summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@gmail.com>2019-08-29 20:28:29 +0100
committerNikolaus Rath <Nikolaus@rath.org>2019-08-29 20:28:29 +0100
commitf39c71dcf99292c188bb6f0a117d7e118f92bfb1 (patch)
treebb41bf027212445f267b3d7a1b0dce9d601b03d8 /test
parentab26ad4dfab74937daf99e0b7e75e4a0e148b0a7 (diff)
downloadfuse-f39c71dcf99292c188bb6f0a117d7e118f92bfb1.tar.gz
Avoid gcc 9.1 strncpy(3) warnings (#447)
Recent GCC releases have warnings related to common strncpy(3) bugs. These warnings can be avoided by explicitly NUL-terminating the buffer or using memcpy(3) when the intention is to copy just the characters without the NUL terminator. This commit fixes the following warnings: [1/27] Compiling C object 'test/9f86d08@@test_syscalls@exe/test_syscalls.c.o'. In function ‘test_socket’, inlined from ‘main’ at ../test/test_syscalls.c:1899:9: ../test/test_syscalls.c:1760:2: warning: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 1023 [-Wstringop-truncation] 1760 | strncpy(su.sun_path, testsock, sizeof(su.sun_path)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [2/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse.c.o'. ../lib/fuse.c: In function ‘add_name’: ../lib/fuse.c:968:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 968 | strncpy(s, name, len); | ^~~~~~~~~~~~~~~~~~~~~ ../lib/fuse.c:944:15: note: length computed here 944 | size_t len = strlen(name); | ^~~~~~~~~~~~ [3/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse_lowlevel.c.o'. ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry’: ../lib/fuse_lowlevel.c:288:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 288 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:276:12: note: length computed here 276 | namelen = strlen(name); | ^~~~~~~~~~~~ ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry_plus’: ../lib/fuse_lowlevel.c:381:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 381 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:366:12: note: length computed here 366 | namelen = strlen(name); | ^~~~~~~~~~~~ Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_syscalls.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/test/test_syscalls.c b/test/test_syscalls.c
index 1d776fd..e1dbab3 100644
--- a/test/test_syscalls.c
+++ b/test/test_syscalls.c
@@ -1757,7 +1757,8 @@ static int test_socket(void)
return -1;
}
su.sun_family = AF_UNIX;
- strncpy(su.sun_path, testsock, sizeof(su.sun_path));
+ strncpy(su.sun_path, testsock, sizeof(su.sun_path) - 1);
+ su.sun_path[sizeof(su.sun_path) - 1] = '\0';
res = bind(fd, (struct sockaddr*)&su, sizeof(su));
if (res == -1) {
PERROR("bind");