Skip to content

Commit

Permalink
Fixed must-copy version of stringmap_insert().
Browse files Browse the repository at this point in the history
Thanks to Sam Lantinga for pointing out the bug.
  • Loading branch information
icculus committed Oct 20, 2011
1 parent ba9421b commit 5929b22
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mojoshader_common.c
Expand Up @@ -250,7 +250,17 @@ int stringmap_insert(StringMap *smap, const char *key, const char *value)
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);
Expand Down

0 comments on commit 5929b22

Please sign in to comment.