From 91072cd480244fbb531a6c000f7eff1fdf8b7cdf Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 20 May 2019 12:46:39 +0200 Subject: losetup: use xstrncpy() Signed-off-by: Karel Zak --- lib/loopdev.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/loopdev.c b/lib/loopdev.c index 4610e9192..ede1b5cdc 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -116,10 +116,9 @@ int loopcxt_set_device(struct loopdev_cxt *lc, const char *device) } snprintf(lc->device, sizeof(lc->device), "%s%s", dir, device); - } else { - strncpy(lc->device, device, sizeof(lc->device)); - lc->device[sizeof(lc->device) - 1] = '\0'; - } + } else + xstrncpy(lc->device, device, sizeof(lc->device)); + DBG(CXT, ul_debugobj(lc, "%s name assigned", device)); } @@ -1158,8 +1157,7 @@ int loopcxt_set_backing_file(struct loopdev_cxt *lc, const char *filename) if (!lc->filename) return -errno; - strncpy((char *)lc->info.lo_file_name, lc->filename, LO_NAME_SIZE); - lc->info.lo_file_name[LO_NAME_SIZE- 1] = '\0'; + xstrncpy((char *)lc->info.lo_file_name, lc->filename, LO_NAME_SIZE); DBG(CXT, ul_debugobj(lc, "set backing file=%s", lc->info.lo_file_name)); return 0; -- cgit v1.2.3-55-g7522