From d80cc14718d88d91e4e23ae19e9bbeb7d685a319 Mon Sep 17 00:00:00 2001 From: halex Date: Sun, 11 May 2014 21:25:07 +0000 Subject: [PATCH] replace realloc(p, N * M) with reallocarray(p, N, M) and remove some pointless cleanup if we're obviously going to die anyway ok guenther@ --- sbin/ncheck_ffs/ncheck_ffs.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/sbin/ncheck_ffs/ncheck_ffs.c b/sbin/ncheck_ffs/ncheck_ffs.c index f398978fce1..48a8d79b49f 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.39 2014/05/11 21:14:03 guenther Exp $ */ +/* $OpenBSD: ncheck_ffs.c,v 1.40 2014/05/11 21:25:07 halex Exp $ */ /*- * Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert @@ -157,13 +157,9 @@ cacheino(ino_t ino, void *dp) { struct icache_s *newicache; - newicache = realloc(icache, (nicache + 1) * sizeof(struct icache_s)); - if (newicache == NULL) { - if (icache) - free(icache); - icache = NULL; + newicache = reallocarray(icache, nicache + 1, sizeof(struct icache_s)); + if (newicache == NULL) errx(1, "malloc"); - } icache = newicache; icache[nicache].ino = ino; if (sblock->fs_magic == FS_UFS1_MAGIC) @@ -321,13 +317,9 @@ addinode(ino_t ino) { ino_t *newilist; - newilist = realloc(ilist, sizeof(ino_t) * (ninodes + 1)); - if (newilist == NULL) { - if (ilist) - free(ilist); - ilist = NULL; + newilist = reallocarray(ilist, ninodes + 1, sizeof(ino_t)); + if (newilist == NULL) errx(4, "not enough memory to allocate tables"); - } ilist = newilist; ilist[ninodes] = ino; ninodes++; -- 2.20.1