lib/sysfs: use xstrncpy()

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-05-20 12:57:07 +02:00
parent 91072cd480
commit 94d9fd9f6a
1 changed files with 5 additions and 8 deletions

View 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);