From 46b0ace509d9ed013915e9ab8013c7c712e11395 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 24 Jun 2014 19:06:05 +0200 Subject: xmalloc: Add and use xcalloc Add a wrapper for calloc which checks for integer overflows in the calculation of the size to allocate. Use xcalloc to allocate an array of objects instead of calculating the size ourselves, which might cause an integer overflow. Signed-off-by: Tobias Klauser --- ifpps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ifpps.c') diff --git a/ifpps.c b/ifpps.c index 4cdcbf4..77c63a6 100644 --- a/ifpps.c +++ b/ifpps.c @@ -173,7 +173,7 @@ static inline int padding_from_num(int n) } #define STATS_ALLOC1(member) \ - do { stats->member = xzmalloc(cpus * sizeof(*(stats->member))); } while (0) + do { stats->member = xcalloc(cpus, sizeof(*(stats->member))); } while (0) static void stats_alloc(struct ifstat *stats, unsigned int cpus) { @@ -1425,7 +1425,7 @@ int main(int argc, char **argv) stats_alloc(&stats_new, cpus); stats_alloc(&stats_delta, cpus); - cpu_hits = xzmalloc(cpus * sizeof(*cpu_hits)); + cpu_hits = xcalloc(cpus, sizeof(*cpu_hits)); if (promisc) ifflags = device_enter_promiscuous_mode(ifname); -- cgit v1.2.3-54-g00ecf