summaryrefslogtreecommitdiff
path: root/sbin/fdisk/misc.c
diff options
context:
space:
mode:
authorTim van der Molen <tim@cvs.openbsd.org>2015-11-12 17:54:51 +0000
committerTim van der Molen <tim@cvs.openbsd.org>2015-11-12 17:54:51 +0000
commit3fdad9db1764f803b4d243c86b8d24ca5b75be25 (patch)
tree93b256f2fd29e5b60a4a465346b466e21df4d4f5 /sbin/fdisk/misc.c
parent27282d39d4595d6009250e12c842e9eefc37453a (diff)
Simplify string_from_line(). No functional change.
OK krw@
Diffstat (limited to 'sbin/fdisk/misc.c')
-rw-r--r--sbin/fdisk/misc.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index b58d6eab345..8831929ad08 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.56 2015/11/12 15:07:41 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.57 2015/11/12 17:54:50 tim Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -71,15 +71,12 @@ string_from_line(char *buf, size_t buflen)
return (1);
if (line[sz - 1] == '\n')
- line[--sz] = '\0';
-
- if (sz < buflen) {
- memcpy(buf, line, sz);
- buf[sz] = '\0';
- } else {
- memcpy(buf, line, buflen - 1);
- buf[buflen - 1] = '\0';
- }
+ sz--;
+ if (sz >= buflen)
+ sz = buflen - 1;
+
+ memcpy(buf, line, sz);
+ buf[sz] = '\0';
return (0);
}