diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-10-09 02:41:23 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-10-09 02:41:23 +0000 |
commit | 49f18132a4f68ac756c5b569969adebe112bd756 (patch) | |
tree | 66c2695ca789a0eae5f3fa72990d4334840254f9 /sbin/ncheck_ffs/ncheck_ffs.c | |
parent | 1b5e01e6feef83f5fd37ee22fd37e5756bccee91 (diff) |
fairly obvious reallocarray() conversion, where the size is recalculated
only on success.
Diffstat (limited to 'sbin/ncheck_ffs/ncheck_ffs.c')
-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]) { |