]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/sysfs: use xstrncpy()
authorKarel Zak <kzak@redhat.com>
Mon, 20 May 2019 10:57:07 +0000 (12:57 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 May 2019 10:57:07 +0000 (12:57 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs.c

index 9e336adcf920cdb91ad26ccac6df4c673cb28f1d..804a0bd872e1b640d1b4bdb4a1f31358520dd91d 100644 (file)
@@ -16,6 +16,7 @@
 #include "fileutils.h"
 #include "all-io.h"
 #include "debug.h"
+#include "strutils.h"
 
 static void sysfs_blkdev_deinit_path(struct path_cxt *pc);
 static int  sysfs_blkdev_enoent_redirect(struct path_cxt *pc, const char *path, int *dirfd);
@@ -489,10 +490,8 @@ static int get_dm_wholedisk(struct path_cxt *pc, char *diskname,
     if (!name)
         return -1;
 
-    if (diskname && len) {
-        strncpy(diskname, name, len);
-        diskname[len - 1] = '\0';
-    }
+    if (diskname && len)
+        xstrncpy(diskname, name, len);
 
     if (diskdevno) {
         *diskdevno = __sysfs_devname_to_devno(ul_path_get_prefix(pc), name, NULL);
@@ -579,10 +578,8 @@ int sysfs_blkdev_get_wholedisk(    struct path_cxt *pc,
             goto err;
 
        sysfs_devname_sys_to_dev(name);
-        if (diskname && len) {
-            strncpy(diskname, name, len);
-            diskname[len - 1] = '\0';
-        }
+        if (diskname && len)
+            xstrncpy(diskname, name, len);
 
         if (diskdevno) {
             *diskdevno = __sysfs_devname_to_devno(ul_path_get_prefix(pc), name, NULL);