diff --git a/libretro-common/include/array/rhmap.h b/libretro-common/include/array/rhmap.h index 10cb550874..f0eaaad8ee 100644 --- a/libretro-common/include/array/rhmap.h +++ b/libretro-common/include/array/rhmap.h @@ -104,7 +104,7 @@ #include /* for memcpy, memset */ #include /* for ptrdiff_t, size_t */ #include /* for uint32_t */ -#include /* for strdup */ +#include /* for strlen */ #define RHMAP_LEN(b) ((b) ? RHMAP__HDR(b)->len : 0) #define RHMAP_MAX(b) ((b) ? RHMAP__HDR(b)->maxlen : 0) @@ -261,7 +261,21 @@ RHMAP__UNUSED static ptrdiff_t rhmap__idx(struct rhmap__hdr* hdr, uint32_t key, } if (!hdr->keys[i]) { - if (add) { hdr->len++; hdr->keys[i] = key; if (str) hdr->key_strs[i] = strdup(str); return (ptrdiff_t)i; } + if (add) + { + int l; + char *t; + + hdr->len++; + hdr->keys[i] = key; + l = strlen(str); + t = malloc(l + 1); + memcpy(t, s, l); + t[l] = '\0'; + if (str) + hdr->key_strs[i] = t; + return (ptrdiff_t)i; + } return (ptrdiff_t)-1; } }