jmacd / xdelta

open-source binary diff, delta/differential compression tools, VCDIFF/RFC 3284 delta compression
http://xdelta.org
1.14k stars 189 forks source link

Fix assertion related compile failure #241

Open wdhongtw opened 6 years ago

wdhongtw commented 6 years ago

static_assert is declared in assert.h and should only be used after C11.

wdhongtw commented 6 years ago

When build this tool with generate_build_files.sh and ./configure and make install, we may see some compile failure like

gcc -DHAVE_CONFIG_H -I.    -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare -Wformat=2 -Wno-format-nonliteral -Wno-unused-parameter -Wno-unused-function -std=c99 -DREGRESSION_TEST=1 -DSECONDARY_DJW=1 -DSECONDARY_FGK=1 -DXD3_MAIN=1  -DXD3_DEBUG=0 -g -O2 -MT xdelta3-xdelta3.o -MD -MP -MF .deps/xdelta3-xdelta3.Tpo -c -o xdelta3-xdelta3.o `test -f 'xdelta3.c' || echo './'`xdelta3.c
In file included from xdelta3.h:30:0,
                 from xdelta3.c:264:
config.h:65:23: error: expected declaration specifiers or ‘...’ before numeric constant
 #define SIZEOF_SIZE_T 8
                       ^
xdelta3.h:171:15: note: in expansion of macro ‘SIZEOF_SIZE_T’
 static_assert(SIZEOF_SIZE_T == sizeof(size_t), "SIZEOF_SIZE_T not correctly set");
               ^
In file included from xdelta3.c:264:0:
xdelta3.h:171:48: error: expected declaration specifiers or ‘...’ before string constant
 static_assert(SIZEOF_SIZE_T == sizeof(size_t), "SIZEOF_SIZE_T not correctly set");
                                                ^

I guess this compile do fail because compiler think that statement is a function declaration.. So compiler says that specifiers should be added.

Fix this bug by including assert.h. Also change C standard from C99 to C11, because static_assert is added since C11.