summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Schubert <bschubert@ddn.com>2022-05-06 15:42:56 +0200
committerNikolaus Rath <Nikolaus@rath.org>2022-05-06 21:21:06 +0100
commit8d934122df6b1664927641ba19105fefb7b2a1f8 (patch)
treeba26635561b0371214ebade61b3d73251127a357
parenta56147d3cb269d64635408ab5588ad66eba43943 (diff)
downloadfuse-8d934122df6b1664927641ba19105fefb7b2a1f8.tar.gz
Fix a test strncpy compilation warning with recent gcc
meson configure -D buildtype=debugoptimized meson configure -D b_sanitize=address,undefined Results in '-fsanitize=address,undefined ... -O2 -g' that made compilation to give errors with recent gcc versions. bernd@t1700bs build-ubuntu>ninja -v [1/2] ccache gcc -Itest/test_syscalls.p -Itest -I../test -Iinclude -I../include -Ilib -I../lib -I. -I.. -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -O2 -g -D_REENTRANT -DHAVE_CONFIG_H -Wno-sign-compare -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -fno-strict-aliasing -Wno-unused-result -DHAVE_SYMVER_ATTRIBUTE -MD -MQ test/test_syscalls.p/test_syscalls.c.o -MF test/test_syscalls.p/test_syscalls.c.o.d -o test/test_syscalls.p/test_syscalls.c.o -c ../test/test_syscalls.c FAILED: test/test_syscalls.p/test_syscalls.c.o ccache gcc -Itest/test_syscalls.p -Itest -I../test -Iinclude -I../include -Ilib -I../lib -I. -I.. -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -O2 -g -D_REENTRANT -DHAVE_CONFIG_H -Wno-sign-compare -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -fno-strict-aliasing -Wno-unused-result -DHAVE_SYMVER_ATTRIBUTE -MD -MQ test/test_syscalls.p/test_syscalls.c.o -MF test/test_syscalls.p/test_syscalls.c.o.d -o test/test_syscalls.p/test_syscalls.c.o -c ../test/test_syscalls.c In file included from /usr/include/string.h:519, from ../test/test_syscalls.c:7: In function ‘strncpy’, inlined from ‘test_socket’ at ../test/test_syscalls.c:1885:2, inlined from ‘main’ at ../test/test_syscalls.c:2030:9: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: error: ‘__builtin_strncpy’ output may be truncated copying 107 bytes from a string of length 1023 [-Werror=stringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ I disagree a bit on the gcc sanity here, as the code was behaving correctly and even already checked the string length. But sice the string length is already verified, that length can be used for the final strncpy.
-rw-r--r--test/test_syscalls.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/test/test_syscalls.c b/test/test_syscalls.c
index 65292ed..c835661 100644
--- a/test/test_syscalls.c
+++ b/test/test_syscalls.c
@@ -1868,9 +1868,10 @@ static int test_socket(void)
int fd;
int res;
int err = 0;
+ const size_t test_sock_len = strlen(testsock) + 1;
start_test("socket");
- if (strlen(testsock) + 1 > sizeof(su.sun_path)) {
+ if (test_sock_len > sizeof(su.sun_path)) {
fprintf(stderr, "Need to shorten mount point by %zu chars\n",
strlen(testsock) + 1 - sizeof(su.sun_path));
return -1;
@@ -1882,7 +1883,8 @@ static int test_socket(void)
return -1;
}
su.sun_family = AF_UNIX;
- strncpy(su.sun_path, testsock, sizeof(su.sun_path) - 1);
+
+ strncpy(su.sun_path, testsock, test_sock_len);
su.sun_path[sizeof(su.sun_path) - 1] = '\0';
res = bind(fd, (struct sockaddr*)&su, sizeof(su));
if (res == -1) {