mojoshader_opengl.c
changeset 1182 179ffe99c57f
parent 1173 4b2f745c643b
child 1188 25000edc0176
--- a/mojoshader_opengl.c	Fri Oct 13 00:47:22 2017 -0400
+++ b/mojoshader_opengl.c	Fri May 04 17:45:20 2018 -0400
@@ -347,9 +347,10 @@
     set_error("out of memory");
 } // out_of_memory
 
+static char zeromalloc = 0;
 static inline void *Malloc(const size_t len)
 {
-    void *retval = ctx->malloc_fn((int) len, ctx->malloc_data);
+    void *retval = (len == 0) ? &zeromalloc : ctx->malloc_fn((int) len, ctx->malloc_data);
     if (retval == NULL)
         out_of_memory();
     return retval;
@@ -357,7 +358,7 @@
 
 static inline void Free(void *ptr)
 {
-    if (ptr != NULL)
+    if ((ptr != &zeromalloc) && (ptr != NULL))
         ctx->free_fn(ptr, ctx->malloc_data);
 } // Free