Re: [PATCH v2] for_each_string_list_item: avoid undefined behavior for empty list
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Sep 20, 2017, 17:31 UTC
- Message-ID
- <20170920173134.GZ27425@aiede.mtv.corp.google.com>
- In-Reply-To
- <87vakd2v22.fsf@linux-m68k.org>
Andreas Schwab wrote:
> On Sep 19 2017, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 14 quoted lines
>> 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.
Thanks, Jonathan