diff options
| author | Junio C Hamano <gitster@pobox.com> | 2023-05-02 10:13:35 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-05-02 10:13:35 -0700 |
| commit | d699e27bd487598bc3c5bbf649d866c5274ef8cd (patch) | |
| tree | 8e9f201a52546742933c5e92648788e5ca5c8795 /string-list.c | |
| parent | Merge branch 'jk/blame-fake-commit-label' (diff) | |
| parent | banned.h: mark `strtok()` and `strtok_r()` as banned (diff) | |
| download | git-d699e27bd487598bc3c5bbf649d866c5274ef8cd.tar.gz git-d699e27bd487598bc3c5bbf649d866c5274ef8cd.zip | |
Merge branch 'tb/ban-strtok'
Mark strtok() and strtok_r() to be banned.
* tb/ban-strtok:
banned.h: mark `strtok()` and `strtok_r()` as banned
t/helper/test-json-writer.c: avoid using `strtok()`
t/helper/test-oidmap.c: avoid using `strtok()`
t/helper/test-hashmap.c: avoid using `strtok()`
string-list: introduce `string_list_setlen()`
string-list: multi-delimiter `string_list_split_in_place()`
Diffstat (limited to 'string-list.c')
| -rw-r--r-- | string-list.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/string-list.c b/string-list.c index db473f273e..0f8ac117fd 100644 --- a/string-list.c +++ b/string-list.c @@ -203,6 +203,15 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c list->nr = list->alloc = 0; } +void string_list_setlen(struct string_list *list, size_t nr) +{ + if (list->strdup_strings) + BUG("cannot setlen a string_list which owns its entries"); + if (nr > list->nr) + BUG("cannot grow a string_list with setlen"); + list->nr = nr; +} + struct string_list_item *string_list_append_nodup(struct string_list *list, char *string) { @@ -301,7 +310,7 @@ int string_list_split(struct string_list *list, const char *string, } int string_list_split_in_place(struct string_list *list, char *string, - int delim, int maxsplit) + const char *delim, int maxsplit) { int count = 0; char *p = string, *end; @@ -315,7 +324,7 @@ int string_list_split_in_place(struct string_list *list, char *string, string_list_append(list, p); return count; } - end = strchr(p, delim); + end = strpbrk(p, delim); if (end) { *end = '\0'; string_list_append(list, p); |
