summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-10 10:22:48 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-10 10:32:39 +0200
commit706fb34851be3116e28d6abd2c879f984c3d8c83 (patch)
treec20a0880cf4a700af61249c73dd9d22f856bc769 /src/shared
parentf34635bcda4e725f72da4ae982b83daf36609b41 (diff)
downloadsystemd-706fb34851be3116e28d6abd2c879f984c3d8c83.tar.gz
shared/dm-util: use strncpy_exact() to silence gcc
With gcc-9.1.1-2.fc31.x86_64 and -Doptimization=2: ../src/shared/dm-util.c: In function ‘dm_deferred_remove’: ../src/shared/dm-util.c:35:9: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] 35 | strncpy(dm.name, name, sizeof(dm.name)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc is plain wrong here, because we checked strlen(name) a few lines above, so there can be no truncation and even the terminator always fits. But let's avoid the warning.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dm-util.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/shared/dm-util.c b/src/shared/dm-util.c
index a17b85b64a..f73bf93520 100644
--- a/src/shared/dm-util.c
+++ b/src/shared/dm-util.c
@@ -5,6 +5,7 @@
#include "dm-util.h"
#include "fd-util.h"
+#include "string-util.h"
int dm_deferred_remove(const char *name) {
@@ -25,14 +26,14 @@ int dm_deferred_remove(const char *name) {
/* Unfortunately, libcryptsetup doesn't provide a proper API for this, hence call the ioctl()
* directly. */
- if (strlen(name) > sizeof(dm.name)-1)
+ if (strlen(name) >= sizeof(dm.name))
return -ENODEV; /* A device with a name longer than this cannot possibly exist */
fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
if (fd < 0)
return -errno;
- strncpy(dm.name, name, sizeof(dm.name));
+ strncpy_exact(dm.name, name, sizeof(dm.name));
if (ioctl(fd, DM_DEV_REMOVE, &dm))
return -errno;