Skip to content

Commit d151f0c

Browse files
derrickstoleegitster
authored andcommitted
string-list: document iterator behavior on NULL input
The for_each_string_list_item() macro takes a string_list and automatically constructs a for loop to iterate over its contents. This macro will segfault if the list is non-NULL. We cannot change the macro to be careful around NULL values because there are many callers that use the address of a local variable, which will never be NULL and will cause compile errors with -Werror=address. For now, leave a documentation comment to try to avoid mistakes in the future where a caller does not check for a NULL list. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 50a044f commit d151f0c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

string-list.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c
141141
int for_each_string_list(struct string_list *list,
142142
string_list_each_func_t func, void *cb_data);
143143

144-
/** Iterate over each item, as a macro. */
144+
/**
145+
* Iterate over each item, as a macro.
146+
*
147+
* Be sure that 'list' is non-NULL. The macro cannot perform NULL
148+
* checks due to -Werror=address errors.
149+
*/
145150
#define for_each_string_list_item(item,list) \
146151
for (item = (list)->items; \
147152
item && item < (list)->items + (list)->nr; \

0 commit comments

Comments
 (0)