summaryrefslogtreecommitdiff
path: root/strcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'strcache.c')
-rw-r--r--strcache.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/strcache.c b/strcache.c
index 33dcaf1..5b72399 100644
--- a/strcache.c
+++ b/strcache.c
@@ -155,11 +155,17 @@ strcache_add (const char *str)
const char *
strcache_add_len (const char *str, int len)
{
- char *key = alloca (len + 1);
- memcpy (key, str, len);
- key[len] = '\0';
+ /* If we're not given a nul-terminated string we have to create one, because
+ the hashing functions expect it. */
+ if (str[len] != '\0')
+ {
+ char *key = alloca (len + 1);
+ memcpy (key, str, len);
+ key[len] = '\0';
+ str = key;
+ }
- return add_hash (key, len);
+ return add_hash (str, len);
}
int