diff options
author | Florian Weimer <fweimer@redhat.com> | 2019-09-05 22:16:58 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2019-09-05 22:16:58 +0200 |
commit | de18a7061c9bdff73d66502c55d6a3ea671fc6d9 (patch) | |
tree | d3d4d3a27d9ac4aea5fc088a884cc2ec5f256ce7 /locale/localeinfo.h | |
parent | ab41100bab128fa98258aafbb0ab1622884cec4c (diff) | |
download | glibc-de18a7061c9bdff73d66502c55d6a3ea671fc6d9.zip glibc-de18a7061c9bdff73d66502c55d6a3ea671fc6d9.tar.gz glibc-de18a7061c9bdff73d66502c55d6a3ea671fc6d9.tar.bz2 |
locale: Avoid zero-length array in _nl_category_names [BZ #24962]
The union wrapper is unnecessary because C allows to read any object
as a sequence of chars.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'locale/localeinfo.h')
-rw-r--r-- | locale/localeinfo.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/locale/localeinfo.h b/locale/localeinfo.h index 7c1cc3e..0e2a0d7 100644 --- a/locale/localeinfo.h +++ b/locale/localeinfo.h @@ -183,23 +183,29 @@ enum #define _ISCTYPE(c, desc) \ (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1) -/* Category name handling variables. */ +/* Category name handling variables. Concatenate all the strings in a + single object to minimize relocations. Individual strings can be + accessed using _nl_category_names. */ #define CATNAMEMF(line) CATNAMEMF1 (line) #define CATNAMEMF1(line) str##line -extern const union catnamestr_t +extern const struct catnamestr_t { - struct - { #define DEFINE_CATEGORY(category, category_name, items, a) \ - char CATNAMEMF (__LINE__)[sizeof (category_name)]; + char CATNAMEMF (__LINE__)[sizeof (category_name)]; #include "categories.def" #undef DEFINE_CATEGORY - }; - char str[0]; } _nl_category_names attribute_hidden; extern const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden; extern const uint8_t _nl_category_name_sizes[__LC_LAST] attribute_hidden; +/* Return the name of the category INDEX, which must be nonnegative + and less than _LC_LAST. */ +static inline const char * +_nl_category_names_get (int index) +{ + return (const char *) &_nl_category_names + _nl_category_name_idxs[index]; +} + /* Name of the standard locales. */ extern const char _nl_C_name[] attribute_hidden; extern const char _nl_POSIX_name[] attribute_hidden; |