Closed Lwisce closed 3 months ago
If we add -Wwrite-strings into CFLAGS in configure file. And then run
-Wwrite-strings
CFLAGS
./configure -w --const make test
We will get compiler warning :
infback.c: In function ‘inflateBack’: infback.c:307:29: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual] 307 | strm->msg = (char )"invalid block type"; | ^ infback.c:318:29: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual] 318 | strm->msg = (char )"invalid stored block lengths"; | ^ infback.c:356:29: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual] 356 | strm->msg = (char *)"too many length or distance symbols"; | ^
The reason for this warning is code attempts to cast a const char pointer pointing to a constant string literal to a char pointer.
Also, in the code, msg is actually declared asz_const char*, so it is logical to add z_const in the type conversion.
msg
z_const char*
z_const
Applied. Thanks.
If we add
-Wwrite-strings
intoCFLAGS
in configure file. And then runWe will get compiler warning :
The reason for this warning is code attempts to cast a const char pointer pointing to a constant string literal to a char pointer.
Also, in the code,
msg
is actually declared asz_const char*
, so it is logical to addz_const
in the type conversion.