X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=util.c;h=3740429f369803c66b9d1d112b882c2dc74c0518;hp=712a9eaa40db597b81e33935a202c0685e9ecf72;hb=46752af74b8553b4a0a6d8928a823289308c6f8a;hpb=0b0b6423bae15eae22685f9efc41d6efe70e8ae4 diff --git a/util.c b/util.c index 712a9ea..3740429 100644 --- 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; }