summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/tools/ipfstat.c
diff options
context:
space:
mode:
authorcy <cy@FreeBSD.org>2017-05-30 03:22:18 +0000
committercy <cy@FreeBSD.org>2017-05-30 03:22:18 +0000
commit48dc5d2fdd681f68b9b33795aedd13b45ecb3499 (patch)
tree48eb964d063b7f6e6727407f394574f5697b1624 /contrib/ipfilter/tools/ipfstat.c
parent3c3043d37d9e754f134bc85975042ebb8078710d (diff)
downloadFreeBSD-src-48dc5d2fdd681f68b9b33795aedd13b45ecb3499.zip
FreeBSD-src-48dc5d2fdd681f68b9b33795aedd13b45ecb3499.tar.gz
MFC r315368:
calloc() and realloc() modernization. This commit replaces calloc calls, which called calloc() as if it were malloc() by allocating a multiple of objects as a sizeof multiplied by the number of objects. The patch rectifies this by calling calloc() as it was meant to be called. This commit also replaces realloc() with reallocarray() in a similar fashion as above. Instead of calculating the memory to reallocated (changed) by multiplying sizeof by the number of objects, the sizeof and number are passed as separate arguments to reallocarray(), letting reallocarray() do the multiplication instead. Like the calloc() adjustment above, this is approach is cleaner and more elegant than than the previous code. This has been tested on my production firewall and a laptop (also running ipfilter). Submitted by: pfg
Diffstat (limited to 'contrib/ipfilter/tools/ipfstat.c')
-rw-r--r--contrib/ipfilter/tools/ipfstat.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/contrib/ipfilter/tools/ipfstat.c b/contrib/ipfilter/tools/ipfstat.c
index 3261cef..3f00601 100644
--- a/contrib/ipfilter/tools/ipfstat.c
+++ b/contrib/ipfilter/tools/ipfstat.c
@@ -1422,8 +1422,8 @@ static void topipstates(saddr, daddr, sport, dport, protocol, ver,
tsentry++;
if (!maxtsentries || tsentry == maxtsentries) {
maxtsentries += STGROWSIZE;
- tstable = realloc(tstable,
- maxtsentries * sizeof(statetop_t));
+ tstable = reallocarray(tstable, maxtsentries,
+ sizeof(statetop_t));
if (tstable == NULL) {
perror("realloc");
exit(-1);
OpenPOWER on IntegriCloud