diff options
author | Jeremy Huddleston Sequoia <jeremyhu@apple.com> | 2014-01-02 00:43:14 -0800 |
---|---|---|
committer | Jeremy Huddleston Sequoia <jeremyhu@apple.com> | 2014-01-02 00:43:14 -0800 |
commit | eac564e0fc9052a39981ea47b271f7f3d2821944 (patch) | |
tree | e92306faa016d41afb402edeec0fe18334834e91 | |
parent | 423ffbe9c5552dfeffa81bb6e2f2b62ab6b17580 (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.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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; |