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 --- cpusched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cpusched.c') diff --git a/cpusched.c b/cpusched.c index 2b4260b..26c0771 100644 --- a/cpusched.c +++ b/cpusched.c @@ -140,7 +140,8 @@ static int cleanup_cpusched_batch(void *ptr) void init_cpusched(unsigned int cpus) { rwlock_init(&map_lock); - cpu_work_map = xzmalloc((cpu_len = cpus) * sizeof(*cpu_work_map)); + cpu_len = cpus; + cpu_work_map = xcalloc(cpu_len, sizeof(*cpu_work_map)); init_hash(&mapper); } -- cgit v1.2.3-54-g00ecf