From 0e8cfaafca05d947404f5a370048aebe24eec423 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 7 Jan 2016 09:55:08 +0100 Subject: [PATCH] Fix implementation of opj_calloc The parameter "size" is typically the size of some data type and should never be 0. It is much more important to check the "num" parameter if defined behaviour is required. Remove also a comment which is not helpful. Signed-off-by: Stefan Weil --- src/lib/openjp2/opj_malloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/opj_malloc.c b/src/lib/openjp2/opj_malloc.c index e04db912b..4f8b1d6f7 100644 --- a/src/lib/openjp2/opj_malloc.c +++ b/src/lib/openjp2/opj_malloc.c @@ -196,10 +196,10 @@ void * opj_malloc(size_t size) } void * opj_calloc(size_t num, size_t size) { - if (size == 0U) { /* prevent implementation defined behavior of realloc */ + if (num == 0 || size == 0) { + /* prevent implementation defined behavior of realloc */ return NULL; } - /* according to C89 standard, num == 0 shall return a valid pointer */ return calloc(num, size); }