]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
parser_const_string now uses hashtables; hashtables may want to dup an empty string...
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index 712a9eaa40db597b81e33935a202c0685e9ecf72..3740429f369803c66b9d1d112b882c2dc74c0518 100644 (file)
--- a/util.c
+++ b/util.c
@@ -226,6 +226,25 @@ char *_util_Estrdup(const char *s, const char *file, size_t line) {
     return ptr;
 }
 
+char *_util_Estrdup_empty(const char *s, const char *file, size_t line) {
+    size_t  len = 0;
+    char   *ptr = NULL;
+
+    /* in case of -DNOTRACK */
+    (void)file;
+    (void)line;
+
+    if (!s)
+        return NULL;
+
+    len = strlen(s);
+    if ((ptr = (char*)mem_af(len+1, line, file))) {
+        memcpy(ptr, s, len);
+        ptr[len] = '\0';
+    }
+    return ptr;
+}
+
 void util_debug(const char *area, const char *ms, ...) {
     va_list  va;
     if (!OPTS_OPTION_BOOL(OPTION_DEBUG))
@@ -478,7 +497,7 @@ hash_node_t *_util_htnewpair(const char *key, void *value) {
     if (!(node = (hash_node_t*)mem_a(sizeof(hash_node_t))))
         return NULL;
 
-    if (!(node->key = util_strdup(key))) {
+    if (!(node->key = util_strdupe(key))) {
         mem_d(node);
         return NULL;
     }