Re: [PATCH] revision: mark blobs needed for resolve-undo as reachable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 14, 2022 at 10:02:32PM -0400, Taylor Blau wrote:

> --- >8 ---
> 
> diff --git a/string-list.h b/string-list.h
> index d5a744e143..425abc55f4 100644
> --- a/string-list.h
> +++ b/string-list.h
> @@ -143,7 +143,7 @@ int for_each_string_list(struct string_list *list,
> 
>  /** Iterate over each item, as a macro. */
>  #define for_each_string_list_item(item,list)            \
> -	for (item = (list)->items;                      \
> +	for (item = (list) ? (list)->items : NULL;      \
>  	     item && item < (list)->items + (list)->nr; \
>  	     ++item)
> 
> --- 8< ---
> 
> > but even with your suggestion, I get this compiler error:
> 
> ...so did I. Though I'm not sure I understand the compiler's warning
> here. Surely the thing being passed as list in the macro expansion
> _won't_ always evaluate to non-NULL, will it?

In the general case, no, but in this specific expansion of the macro, it
is passing the address of a local variable (&cpath), which will never be
NULL. The compiler is overeager here; the check is indeed pointless in
this expansion, but warning on useless macro-expanded code isn't
helpful, since other macro users need it.

Hiding it in a function seems to work, even with -O2 inlining, like:

diff --git a/string-list.h b/string-list.h
index d5a744e143..b28b135e11 100644
--- a/string-list.h
+++ b/string-list.h
@@ -141,9 +141,14 @@ 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);
 
+static inline struct string_list_item *string_list_first_item(const struct string_list *list)
+{
+	return list ? list->items : NULL;
+}
+
 /** Iterate over each item, as a macro. */
 #define for_each_string_list_item(item,list)            \
-	for (item = (list)->items;                      \
+	for (item = string_list_first_item(list);       \
 	     item && item < (list)->items + (list)->nr; \
 	     ++item)
 

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux