]> git.ipfire.org Git - thirdparty/git.git/commitdiff
string-list: document iterator behavior on NULL input
authorDerrick Stolee <derrickstolee@github.com>
Tue, 27 Sep 2022 13:57:01 +0000 (13:57 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Sep 2022 16:32:26 +0000 (09:32 -0700)
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 <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
string-list.h

index d5a744e1438600080b9970e3f7cdedbe7f2a3708..c7b0d5d0008efb906ba034c632adb69b53c4f545 100644 (file)
@@ -141,7 +141,12 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c
 int for_each_string_list(struct string_list *list,
                         string_list_each_func_t func, void *cb_data);
 
-/** Iterate over each item, as a macro. */
+/**
+ * Iterate over each item, as a macro.
+ *
+ * Be sure that 'list' is non-NULL. The macro cannot perform NULL
+ * checks due to -Werror=address errors.
+ */
 #define for_each_string_list_item(item,list)            \
        for (item = (list)->items;                      \
             item && item < (list)->items + (list)->nr; \