summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2014-01-02 00:43:14 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2014-01-02 00:43:14 -0800
commiteac564e0fc9052a39981ea47b271f7f3d2821944 (patch)
treee92306faa016d41afb402edeec0fe18334834e91
parent423ffbe9c5552dfeffa81bb6e2f2b62ab6b17580 (diff)
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 <jeremyhu@apple.com>
-rw-r--r--list.c7
1 files changed, 6 insertions, 1 deletions
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;