summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2019-05-20 12:57:07 +0200
committerKarel Zak2019-05-20 12:57:07 +0200
commit94d9fd9f6ad45b736c8325de30f511af9f46c2a7 (patch)
tree984d283238ad521e52637b62e02dad96ba82aee5 /lib
parentlosetup: use xstrncpy() (diff)
downloadkernel-qcow2-util-linux-94d9fd9f6ad45b736c8325de30f511af9f46c2a7.tar.gz
kernel-qcow2-util-linux-94d9fd9f6ad45b736c8325de30f511af9f46c2a7.tar.xz
kernel-qcow2-util-linux-94d9fd9f6ad45b736c8325de30f511af9f46c2a7.zip
lib/sysfs: use xstrncpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/sysfs.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 9e336adcf..804a0bd87 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -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);