nih-at/libzip

compat.h:170:46: error: ‘__builtin_strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]

XVilka opened this issue · 1 comments

XVilka commented

Compiler Error

gcc-12 -Isubprojects/libzip-1.10.0/liblibzip.a.p -Isubprojects/libzip-1.10.0 -I../subprojects/libzip-1.10.0 -I../subprojects/libzip-1.10.0/lib -Isubprojects/zlib-1.2.13 -I../subprojects/zlib-1.2.13 -I../subprojects/xz-5.4.3/src/liblzma/api -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -O2 -g --std=gnu99 -Werror=sizeof-pointer-memaccess -fvisibility=hidden -DASAN=1 -DRZ_ASSERT_STDOUT=1 -Wno-cpp -ftrivial-auto-var-init=pattern -funsigned-char -fPIC -DLZMA_API_STATIC -MD -MQ subprojects/libzip-1.10.0/liblibzip.a.p/lib_zip_dir_add.c.o -MF subprojects/libzip-1.10.0/liblibzip.a.p/lib_zip_dir_add.c.o.d -o subprojects/libzip-1.10.0/liblibzip.a.p/lib_zip_dir_add.c.o -c ../subprojects/libzip-1.10.0/lib/zip_dir_add.c
In file included from ../subprojects/libzip-1.10.0/lib/zipint.h:39,
                 from ../subprojects/libzip-1.10.0/lib/zip_dir_add.c:38:
../subprojects/libzip-1.10.0/lib/zip_dir_add.c: In function ‘zip_dir_add’:
../subprojects/libzip-1.10.0/lib/compat.h:170:46: error: ‘__builtin_strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
  170 | #define strncpy_s(dest, destsz, src, count) (strncpy((dest), (src), (count)), 0)
      |                                              ^~~~~~~
../subprojects/libzip-1.10.0/lib/zip_dir_add.c:68:15: note: in expansion of macro ‘strncpy_s’
   68 |         (void)strncpy_s(s, len + 2, name, len);
      |               ^~~~~~~~~
../subprojects/libzip-1.10.0/lib/zip_dir_add.c:61:11: note: length computed here
   61 |     len = strlen(name);
      |           ^~~~~~~~~~~~

libzip Version
1.10.0

Operating System and Compiler
Linux x86_64, GCC 12

Additional context

A subproject of rizin

We have checked the code - it is fine. The warning might be correct in other places, but here it is not.
We suggest not turning on warnings with -Werror if you don't own the code base.