[PATCH] locale: Avoid zero-length array in _nl_category_names [BZ #24962]

Martin Sebor msebor@gmail.com
Thu Sep 5 14:40:00 GMT 2019


On 9/5/19 8:29 AM, Florian Weimer wrote:
> * Martin Sebor:
> 
>> On 9/5/19 7:25 AM, Jeff Law wrote:
>>> On 9/5/19 1:34 AM, Florian Weimer wrote:
>>>> (Martin, can you give this a test using GCC 10?  I don't expect any
>>>> issues because the zero-length array is completely gone.  The patch
>>>> passed testing on x86_64-linux-gnu without regressions, but with GCC 9.)
>>>>
>>>> The union wrapper is unnecessary because C allows to read any object
>>>> as a sequence of chars.
>>>>
>>>> 2019-09-05  Florian Weimer  <fweimer@redhat.com>
>>>>
>>>> 	[BZ #24962]
>>>> 	* locale/localeinfo.h (_nl_category_names): Remove union wrapper.
>>>> 	(_nl_category_names_get): New function.
>>>> 	* intl/dcigettext.c (category_to_name): Call it.
>>>> 	* locale/findlocale.c (_nl_find_locale): Likewise.
>>>> 	* intl/loadlocale.c (_nl_load_locale): Likewise.
>>>> 	* locale/newlocale.c (__newlocale): Likewise.
>>>> 	* locale/setlocale.c (_nl_category_names): Adjust definition.
>>>> 	(_nl_category_name_idxs): Likewise.
>>>> 	(new_composite_name): Call _nl_category_names_get.
>>>> 	(setlocale): Likewise.
>>> Might be easier for me than Martin.  I just threw it into my github
>>> repo, so my tester will pick it up as of now.  Will report back in a few
>>> hours.
>>
>> Thanks Jeff.  I'm sure your coverage will be more comprehensive
>> than mine.  (The warning Florian is fixing only shows up with
>> the patch for PR 91631 I posted yesterday so you need both in
>> your tested to verify them.)
>>
>> It's pretty easy for me to test it on x86_64-linux: with your
>> patch, Florian, and my enhanced GCC 10 I don't see any warnings.
> 
> Thanks.  Do you (or anyone else) have any comments on the patch itself?
> I need some sort of review before I can push it. 8-)

It's close to what I suggested in the bug so LGTM :)

As an aside, an anonymous struct in a union was among the issues
I mentioned in the other thread (see N2038), so it's good to get
rid of even if this code is only compiled with GCC (and maybe
also Clang?)

Martin



More information about the Libc-alpha mailing list