From bfa8b84b0ec4a0d1e70495b5d210f56d103fdf31 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 26 Nov 2013 08:23:45 -0800 Subject: [PATCH] [xhash] use strdup if possible --- extlib/xhash/xhash.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/extlib/xhash/xhash.h b/extlib/xhash/xhash.h index 3566e5d9..038d4027 100644 --- a/extlib/xhash/xhash.h +++ b/extlib/xhash/xhash.h @@ -62,8 +62,7 @@ xh_get(struct xhash *x, const char *key) static inline struct xh_entry * xh_put(struct xhash *x, const char *key, int val) { - int idx, len; - char *new_key; + int idx; struct xh_entry *e; if ((e = xh_get(x, key))) { @@ -71,14 +70,10 @@ xh_put(struct xhash *x, const char *key, int val) return e; } - len = strlen(key); - new_key = (char *)malloc(len+1); - strcpy(new_key, key); - idx = xh_hash(key) % x->size; e = (struct xh_entry *)malloc(sizeof(struct xh_entry)); e->next = x->buckets[idx]; - e->key = new_key; + e->key = strdup(key); e->val = val; return x->buckets[idx] = e;