Re: [PATCH v2] for_each_string_list_item: avoid undefined behavior for empty list
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 21, 2017, 01:12 UTC
- Message-ID
- <xmqqtvzwn9bj.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <87lgl9rqbq.fsf@linux-m68k.org>
Andreas Schwab <schwab@linux-m68k.org> writes:
Show 24 quoted lines
> On Sep 20 2017, Jonathan Nieder <jrnieder@gmail.com> wrote: > >> Andreas Schwab wrote: >>> On Sep 19 2017, Jonathan Nieder <jrnieder@gmail.com> wrote: >> >>>> B. #define for_each_string_list_item(item, list) \ >>>> if (list->items) \ >>>> for (item = ...; ...; ... ) >>>> >>>> This breaks a caller like >>>> if (foo) >>>> for_each_string_list_item(item, list) >>>> ... >>>> else >>>> ... >>>> >>>> making it a non-starter. >>> >>> That can be fixed with a dangling else. >> >> I believe the fix you're referring to is option C, from the same email >> you are replying to. If not, please correct me. > > A variant thereof, yes.
Now you make me curious. How would that variant be different from option C. in Jonathan's message? Perhaps that different version may be a solution to work around the potential issue mentioned in the description of option C.?