diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-09-25 15:24:09 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-25 15:24:09 +0900 |
commit | 48f1e49be19ab64f9dfdffa32073dd1dbbf04727 (patch) | |
tree | 372b8c8488c793832263811506cfe628ab1d1d11 | |
parent | Merge branch 'tb/test-lint-echo-e' (diff) | |
parent | for_each_string_list_item: avoid undefined behavior for empty list (diff) | |
download | tgif-48f1e49be19ab64f9dfdffa32073dd1dbbf04727.tar.xz |
Merge branch 'mh/for-each-string-list-item-empty-fix'
Code cmp.std.c nitpick.
* mh/for-each-string-list-item-empty-fix:
for_each_string_list_item: avoid undefined behavior for empty list
-rw-r--r-- | string-list.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/string-list.h b/string-list.h index 29bfb7ae45..79ae567cbc 100644 --- a/string-list.h +++ b/string-list.h @@ -32,8 +32,10 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c typedef int (*string_list_each_func_t)(struct string_list_item *, void *); int for_each_string_list(struct string_list *list, string_list_each_func_t, void *cb_data); -#define for_each_string_list_item(item,list) \ - for (item = (list)->items; item < (list)->items + (list)->nr; ++item) +#define for_each_string_list_item(item,list) \ + for (item = (list)->items; \ + item && item < (list)->items + (list)->nr; \ + ++item) /* * Apply want to each item in list, retaining only the ones for which |