diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2010-11-09 22:45:13 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2010-11-09 22:45:13 +0100 |
commit | a8e23f24db6e6da750bbed194ad6e21a0683ce18 (patch) | |
tree | 85482803836224f8cc49a8e069d06edb00e6fe70 /util.c | |
parent | 9cdd115480513cd47f9039da3751f457aef50ef6 (diff) | |
parent | 5912bba9876d5a85f89ea96253037968becda489 (diff) | |
download | ccache-a8e23f24db6e6da750bbed194ad6e21a0683ce18.tar.gz |
Merge branch 'maint'
* maint:
Make x_malloc and x_calloc always return NULL for zero byte allocations
Fix calloc success check
Fix malloc success check
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -596,6 +596,13 @@ void * x_malloc(size_t size) { void *ret; + if (size == 0) { + /* + * malloc() may return NULL if size is zero, so always do this to make sure + * that the code handles it regardless of platform. + */ + return NULL; + } ret = malloc(size); if (!ret) { fatal("x_malloc: Could not allocate %lu bytes", (unsigned long)size); @@ -608,8 +615,15 @@ void * x_calloc(size_t nmemb, size_t size) { void *ret; + if (nmemb * size == 0) { + /* + * calloc() may return NULL if nmemb or size is 0, so always do this to + * make sure that the code handles it regardless of platform. + */ + return NULL; + } ret = calloc(nmemb, size); - if (!ret) { + if (!retr) { fatal("x_calloc: Could not allocate %lu bytes", (unsigned long)size); } return ret; |