Browse Source

make sure that SDL_malloc(0) or SDL_calloc(0,x) doesn't return NULL.

Ozkan Sezer 7 years ago
parent
commit
bef0fec121
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/stdlib/SDL_malloc.c

+ 6 - 0
src/stdlib/SDL_malloc.c

@@ -33,11 +33,17 @@
 
 
 void *SDL_malloc(size_t size)
 void *SDL_malloc(size_t size)
 {
 {
+    if (!size) {
+        return malloc(1);
+    }
     return malloc(size);
     return malloc(size);
 }
 }
 
 
 void *SDL_calloc(size_t nmemb, size_t size)
 void *SDL_calloc(size_t nmemb, size_t size)
 {
 {
+    if (!size || !nmemb) {
+        return calloc(1,1);
+    }
     return calloc(nmemb, size);
     return calloc(nmemb, size);
 }
 }