ckiss

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 707346247bfa21f5637e44e4425d4c2f85cfd837
parent 52c1bcd4a4e41d4387a983a68ed57c0ae50efcbe
Author: aabacchus <ben@bvnf.space>
Date:   Sun, 23 Apr 2023 22:19:28 +0100

split: don't modify original string

Diffstat:
Msrc/array.c | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/array.c b/src/array.c @@ -17,6 +17,7 @@ arr_len(array_t arr) { return n; } +// TODO create if arr == NULL array_t arr_append(array_t *arr, char *s, int n, bool dup) { if (n < 0) { @@ -62,8 +63,11 @@ split(char *s, char *sep) { if (s == NULL) return NULL; + /* avoid modifying original string */ + char *ss = strdup(s); + array_t res = NULL; - char *p = strtok(s, sep); + char *p = strtok(ss, sep); int n = 0; while (p) { @@ -71,5 +75,7 @@ split(char *s, char *sep) { p = strtok(NULL, sep); } + free(ss); + return res; }