Fixed must-copy version of stringmap_insert().
authorRyan C. Gordon <icculus@icculus.org>
Thu, 20 Oct 2011 12:08:12 -0400
changeset 1059 9655c606b39d
parent 1058 dcbe39bffedc
child 1060 4cdf5a3ceb03
Fixed must-copy version of stringmap_insert(). Thanks to Sam Lantinga for pointing out the bug.
mojoshader_common.c
--- a/mojoshader_common.c	Mon Aug 01 15:14:50 2011 -0400
+++ b/mojoshader_common.c	Thu Oct 20 12:08:12 2011 -0400
@@ -250,7 +250,17 @@
     int rc = -1;
     char *k = (char *) smap->m(strlen(key) + 1, smap->d);
     char *v = (char *) (value ? smap->m(strlen(value) + 1, smap->d) : NULL);
-    if ( (!k) || ((!v) && (value)) || ((rc = hash_insert(smap, k, v)) <= 0) )
+    int failed = ( (!k) || ((!v) && (value)) );
+
+    if (!failed)
+    {
+        strcpy(k, key);
+        if (value != NULL)
+            strcpy(v, value);
+        failed = ((rc = hash_insert(smap, k, v)) <= 0);
+    } // if
+
+    if (failed)
     {
         smap->f(k, smap->d);
         smap->f(v, smap->d);