Don't allocate zero bytes for MOJOSHADER_symbolTypeInfo::members.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 09 Jun 2011 01:56:10 -0400
changeset 1052 0ac978521113
parent 1051 96a838f4e680
child 1053 513af64373ad
Don't allocate zero bytes for MOJOSHADER_symbolTypeInfo::members.
mojoshader.c
--- a/mojoshader.c	Thu Jun 02 14:49:30 2011 -0400
+++ b/mojoshader.c	Thu Jun 09 01:56:10 2011 -0400
@@ -6940,13 +6940,17 @@
     if ((pos + 16 + (info->member_count * 8)) >= bytes)
         return 0;  // corrupt CTAB.
 
-    const size_t len = sizeof (MOJOSHADER_symbolStructMember) *
-                        info->member_count;
-
-    info->members = (MOJOSHADER_symbolStructMember *) Malloc(ctx, len);
-    if (info->members == NULL)
-        return 1;  // we'll check ctx->out_of_memory later.
-    memset(info->members, '\0', len);
+    if (info->member_count == 0)
+        info->members = NULL;
+    else
+    {
+        const size_t len = sizeof (MOJOSHADER_symbolStructMember) *
+                            info->member_count;
+        info->members = (MOJOSHADER_symbolStructMember *) Malloc(ctx, len);
+        if (info->members == NULL)
+            return 1;  // we'll check ctx->out_of_memory later.
+        memset(info->members, '\0', len);
+    } // else
 
     int i;
     const uint32 *member = (const uint32 *)((const uint8 *) (&typeptr[6]));