diff options
author | cy <cy@FreeBSD.org> | 2017-05-30 03:22:18 +0000 |
---|---|---|
committer | cy <cy@FreeBSD.org> | 2017-05-30 03:22:18 +0000 |
commit | 48dc5d2fdd681f68b9b33795aedd13b45ecb3499 (patch) | |
tree | 48eb964d063b7f6e6727407f394574f5697b1624 /contrib/ipfilter/tools | |
parent | 3c3043d37d9e754f134bc85975042ebb8078710d (diff) | |
download | FreeBSD-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')
-rw-r--r-- | contrib/ipfilter/tools/ipf_y.y | 2 | ||||
-rw-r--r-- | contrib/ipfilter/tools/ipfcomp.c | 2 | ||||
-rw-r--r-- | contrib/ipfilter/tools/ipfstat.c | 4 |
3 files changed, 4 insertions, 4 deletions
diff --git a/contrib/ipfilter/tools/ipf_y.y b/contrib/ipfilter/tools/ipf_y.y index 2ff9abd..26db2a2 100644 --- a/contrib/ipfilter/tools/ipf_y.y +++ b/contrib/ipfilter/tools/ipf_y.y @@ -2195,7 +2195,7 @@ char *phrase; for (i = 0, s = strtok(phrase, " \r\n\t"); s != NULL; s = strtok(NULL, " \r\n\t"), i++) { - fb = realloc(fb, (i / 4 + 1) * sizeof(*fb)); + fb = reallocarray(fb, i / 4 + 1, sizeof(*fb)); if (fb == NULL) { warnx("memory allocation error at %d in %s in %s", __LINE__, __FUNCTION__, __FILE__); abort(); diff --git a/contrib/ipfilter/tools/ipfcomp.c b/contrib/ipfilter/tools/ipfcomp.c index eba28ce..d41faa4 100644 --- a/contrib/ipfilter/tools/ipfcomp.c +++ b/contrib/ipfilter/tools/ipfcomp.c @@ -965,7 +965,7 @@ void printC(dir) frgroup_t *g; if (m == NULL) - m = (mc_t *)calloc(1, sizeof(*m) * FRC_MAX); + m = (mc_t *)calloc(FRC_MAX, sizeof(*m)); for (g = groups; g != NULL; g = g->fg_next) { if ((dir == 0) && ((g->fg_flags & FR_INQUE) != 0)) 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); |