summaryrefslogtreecommitdiffstats
path: root/zix/strindex.c
diff options
context:
space:
mode:
Diffstat (limited to 'zix/strindex.c')
-rw-r--r--zix/strindex.c8
1 files changed, 6 insertions, 2 deletions
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));
}