diff options
author | Karel Zak | 2019-05-20 12:46:39 +0200 |
---|---|---|
committer | Karel Zak | 2019-05-20 12:46:39 +0200 |
commit | 91072cd480244fbb531a6c000f7eff1fdf8b7cdf (patch) | |
tree | 1bff64125d00b315342a5debef26afd55e04ac8a /lib | |
parent | sfdisk: use xstrcpy() (diff) | |
download | kernel-qcow2-util-linux-91072cd480244fbb531a6c000f7eff1fdf8b7cdf.tar.gz kernel-qcow2-util-linux-91072cd480244fbb531a6c000f7eff1fdf8b7cdf.tar.xz kernel-qcow2-util-linux-91072cd480244fbb531a6c000f7eff1fdf8b7cdf.zip |
losetup: use xstrncpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/loopdev.c | 10 |
1 files changed, 4 insertions, 6 deletions
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; |