diff options
author | David Robillard <d@drobilla.net> | 2019-10-18 14:47:19 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-10-18 14:47:19 +0200 |
commit | 75c667984197ac724f5c941835bb1bf5e2140f2d (patch) | |
tree | 5a8bd4608a52de39538e6ba579364ea4d684b4eb /zix/strindex.c | |
parent | 55f0835fff8bf8be6a58813b6c9faec97ec5597c (diff) | |
download | zix-75c667984197ac724f5c941835bb1bf5e2140f2d.tar.gz zix-75c667984197ac724f5c941835bb1bf5e2140f2d.tar.bz2 zix-75c667984197ac724f5c941835bb1bf5e2140f2d.zip |
Avoid use of strdup
Diffstat (limited to 'zix/strindex.c')
-rw-r--r-- | zix/strindex.c | 8 |
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)); } |