pmqs / Compress-Raw-Zlib

Perl5 interface to zlib compression library
3 stars 10 forks source link

gcc 8.3.0 warnings for multistatement-macros​ #2

Closed pmqs closed 5 years ago

pmqs commented 5 years ago

Perl/perl5#17013 notes this warning

Wmultistatement-macros​:

deflate.c​: In function ‘deflateParams’​:
deflate.c​:602​:28​: warning​: macro expands to multiple statements
[-Wmultistatement-macros]
  CLEAR_HASH(s);
  ^
deflate.c​:193​:5​: note​: in definition of macro ‘CLEAR_HASH’
  s->head[s->hash_size-1] = NIL; \
  ^
deflate.c​:601​:13​: note​: some parts of macro expansion are not guarded
by this ‘else’ clause
  else
  ^~~~

This is the macro in question

#define CLEAR_HASH(s) \
    s->head[s->hash_size-1] = NIL; \
    zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));

Upstream zlib has fixed this issue in https://github.com/madler/zlib/commit/38e8ce32afbaa82f67d992b9f3056f281fe69259.

#define CLEAR_HASH(s) \
    do { \
        s->head[s->hash_size-1] = NIL; \
        zmemzero((Bytef *)s->head, \
                 (unsigned)(s->hash_size-1)*sizeof(*s->head)); \
    } while (0)
pmqs commented 5 years ago

Confirmed warning

perl5.26.1 Makefile.PL CCFLAGS=' -Wall -Wimplicit-fallthrough -Wmultistatement-macros -Werror=declaration-after-statement -Wextra -Wc++-compat -Wwrite-strings' && make

...
gcc-8 -c  -I./zlib-src -Wall -Werror=declaration-after-statement -Wextra -Wc++-compat -Wwrite-strings -Wcast-function-type -Wimplicit-fallthrough -Wmultistatement-macros -Wunused-but-set-variable -Wunused-parameter -Wunused-variable -O2   -DVERSION=\"2.090\" -DXS_VERSION=\"2.090\" -fPIC "-I/home/paul/base/install/gcc-8/perl/std/5.26.1/lib/5.26.1/x86_64-linux/CORE"  -DNO_VIZ -DZ_SOLO   -DGZIP_OS_CODE=3 -DUSE_PPPORT_H deflate.c
deflate.c: In function ‘deflateParams’:
deflate.c:602:28: warning: macro expands to multiple statements [-Wmultistatement-macros]
                 CLEAR_HASH(s);
                            ^
deflate.c:193:5: note: in definition of macro ‘CLEAR_HASH’
     s->head[s->hash_size-1] = NIL; \
     ^
deflate.c:601:13: note: some parts of macro expansion are not guarded by this ‘else’ clause
             else
             ^~~~
pmqs commented 5 years ago

Issue fixed in 2.091 Changes da2bd1fc765b80d01ed10a79b6c4a035e5095ed8