From 75c667984197ac724f5c941835bb1bf5e2140f2d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 18 Oct 2019 14:47:19 +0200 Subject: Avoid use of strdup --- zix/strindex.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'zix/strindex.c') diff --git a/zix/strindex.c b/zix/strindex.c index a502177..6323944 100644 --- a/zix/strindex.c +++ b/zix/strindex.c @@ -48,15 +48,19 @@ ZIX_API ZixStrindex* zix_strindex_new(const char* s) { + const size_t len = strlen(s); + ZixStrindex* t = (ZixStrindex*)malloc(sizeof(ZixStrindex)); memset(t, '\0', sizeof(struct _ZixStrindex)); - t->s = strdup(s); + + t->s = calloc(1, len + 1); + memcpy(t->s, s, len); + t->root = (ZixStrindexNode*)malloc(sizeof(ZixStrindexNode)); memset(t->root, '\0', sizeof(ZixStrindexNode)); t->root->num_children = 0; t->root->first = t->s; - const size_t len = strlen(t->s); for (size_t i = 0; i < len; ++i) { strindex_insert(t->root, t->s + i, t->s + i, t->s + (len - 1)); } -- cgit v1.2.1