chokkan / crfsuite

CRFsuite: a fast implementation of Conditional Random Fields (CRFs)
http://www.chokkan.org/software/crfsuite/
Other
641 stars 208 forks source link

lib/cqdb/src/cqdb.c and Wstringop-truncation #105

Closed jwijffels closed 5 years ago

jwijffels commented 6 years ago

Hello,

I'm trying to publish the R package which wraps CRFsuite to CRAN (https://github.com/bnosac/crfsuite). CRAN complains about the cqdb in the lib folder, the check system running gcc-8 on Debian gives the following warning when compiling cqdb.c which is in lib/cqdb/src/cqdb.c Is there a way on how to fix these issues?

gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG -I./cqdb/include -I./crf/src -I./liblbfgs/include -I./include -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include   -fpic  -g -O2 -Wall -pedantic -mtune=native -c cqdb/src/cqdb.c -o cqdb/src/cqdb.o
cqdb/src/cqdb.c: In function ‘cqdb_writer_close’:
cqdb/src/cqdb.c:270:5: warning: ‘strncpy’ output truncated before terminating nul copying 4 bytes from a string of the same length [-Wstringop-truncation]
     strncpy((char*)header.chunkid, CHUNKID, 4);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cqdb/src/cqdb.c: In function ‘cqdb_reader’:
cqdb/src/cqdb.c:469:9: warning: ‘strncpy’ specified bound 4 equals destination size [-Wstringop-truncation]
         strncpy((char*)db->header.chunkid, (const char*)p, 4);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

many thanks for any input.

usptact commented 6 years ago

Try to use a GCC-7 or even GCC-6 to compile the program.

Take also a look at the documentation on the warning you got: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

jwijffels commented 6 years ago

The warning comes from the CRAN build machines (in this case Debian with gcc-8) which I do not control, nor am I allowed to tweak specific compiler settings which ignore these -Wstring-truncation and the CRAN policy also disallows setting pragma's. Is there another way of rewriting strncpy((char*)header.chunkid, CHUNKID, 4); and strncpy((char*)db->header.chunkid, (const char*)p, 4);such that the -Wstringop-truncation warnings will disappear while still keeping the functionality (which basically sees if the header of the file is of type CQDB)?

jwijffels commented 5 years ago

Never mind. Made the following change which worked out fine: https://github.com/bnosac/crfsuite/commit/19412d0f1659ff8f5735cb12aaaa342eede5055e