diff options
author | 2014-10-09 02:41:22 +0000 | |
---|---|---|
committer | 2014-10-09 02:41:22 +0000 | |
commit | 785ea9dd0821898824c14444c2991811ff3cb81c (patch) | |
tree | 68e6407c203335c82ca91233ee286556d5e6b0f6 | |
parent | obvious reallocarray() conversions (diff) | |
download | wireguard-openbsd-785ea9dd0821898824c14444c2991811ff3cb81c.tar.xz wireguard-openbsd-785ea9dd0821898824c14444c2991811ff3cb81c.zip |
fairly obvious reallocarray() conversion, where the size is recalculated
only on success.
-rw-r--r-- | sbin/ncheck_ffs/ncheck_ffs.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/sbin/ncheck_ffs/ncheck_ffs.c b/sbin/ncheck_ffs/ncheck_ffs.c index ff02d083cdb..bb35aa939f3 100644 --- a/sbin/ncheck_ffs/ncheck_ffs.c +++ b/sbin/ncheck_ffs/ncheck_ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ncheck_ffs.c,v 1.46 2014/07/09 11:21:48 krw Exp $ */ +/* $OpenBSD: ncheck_ffs.c,v 1.47 2014/10/09 02:41:22 deraadt Exp $ */ /*- * Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> @@ -615,7 +615,6 @@ format_entry(const char *path, struct direct *dp) { static size_t size; static char *buf; - size_t nsize; char *src, *dst, *newbuf; int len; @@ -629,12 +628,10 @@ format_entry(const char *path, struct direct *dp) /* Need room for at least one character in buf. */ if (size <= dst - buf) { expand_buf: - nsize = size << 1; - - if ((newbuf = realloc(buf, nsize)) == NULL) + if ((newbuf = reallocarray(buf, size, 2)) == NULL) err(1, "realloc"); buf = newbuf; - size = nsize; + size = size * 2; } if (src[0] =='\\') { switch (src[1]) { |