Skip to content

Commit

Permalink
malloc(0) can return 0 (Fix jqlang#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Jan 3, 2020
1 parent fb105da commit 7041b82
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/jv_alloc.c
Expand Up @@ -120,7 +120,7 @@ static void memory_exhausted() {

void* jv_mem_alloc(size_t sz) {
void* p = malloc(sz);
if (!p) {
if (!p && sz) {
memory_exhausted();
}
return p;
Expand All @@ -132,7 +132,7 @@ void* jv_mem_alloc_unguarded(size_t sz) {

void* jv_mem_calloc(size_t nemb, size_t sz) {
void* p = calloc(nemb, sz);
if (!p) {
if (!p && sz) {
memory_exhausted();
}
return p;
Expand Down Expand Up @@ -160,7 +160,7 @@ void jv_mem_free(void* p) {

void* jv_mem_realloc(void* p, size_t sz) {
p = realloc(p, sz);
if (!p) {
if (!p && sz) {
memory_exhausted();
}
return p;
Expand Down

0 comments on commit 7041b82

Please sign in to comment.