mojoshader_preprocessor.c
changeset 1182 179ffe99c57f
parent 1142 7b554e065321
child 1188 25000edc0176
--- a/mojoshader_preprocessor.c	Fri Oct 13 00:47:22 2017 -0400
+++ b/mojoshader_preprocessor.c	Fri May 04 17:45:20 2018 -0400
@@ -68,9 +68,10 @@
     ctx->out_of_memory = 1;
 } // out_of_memory
 
+static char zeromalloc = 0;
 static inline void *Malloc(Context *ctx, const size_t len)
 {
-    void *retval = ctx->malloc((int) len, ctx->malloc_data);
+    void *retval = (len == 0) ? &zeromalloc : ctx->malloc((int) len, ctx->malloc_data);
     if (retval == NULL)
         out_of_memory(ctx);
     return retval;
@@ -78,7 +79,8 @@
 
 static inline void Free(Context *ctx, void *ptr)
 {
-    ctx->free(ptr, ctx->malloc_data);
+    if ((ptr != &zeromalloc) && (ptr != NULL))
+        ctx->free(ptr, ctx->malloc_data);
 } // Free
 
 static void *MallocBridge(int bytes, void *data)