diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-09-25 09:24:09 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-25 09:24:09 +0300 |
commit | 48f1e49be19ab64f9dfdffa32073dd1dbbf04727 (patch) | |
tree | 372b8c8488c793832263811506cfe628ab1d1d11 | |
parent | 6b05e611bc6c7584d1af7b56e387824f99a76713 (diff) | |
parent | ac7da78ede468315ba22d9ee1265b61a744371ee (diff) |
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 |