From eac564e0fc9052a39981ea47b271f7f3d2821944 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Sequoia Date: Thu, 2 Jan 2014 00:43:14 -0800 Subject: Fix possible malloc allocation error found by clang static analysis list.c:238:23: warning: Call to 'malloc' has an allocation size of 0 bytes ListPtr *sorted = malloc(l * sizeof(ListPtr)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jeremy Huddleston Sequoia --- list.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/list.c b/list.c index 1614d95..320ce20 100644 --- a/list.c +++ b/list.c @@ -235,7 +235,12 @@ sortList(ListPtr old) int i; int l = listLength(old); ListPtr n; - ListPtr *sorted = malloc(l * sizeof(ListPtr)); + ListPtr *sorted; + + if (l <= 0) + return old; + + sorted = malloc(l * sizeof(ListPtr)); if (sorted == NULL) return old; -- cgit v1.2.3