mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
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>
This commit is contained in:
parent
ab41100bab
commit
de18a7061c
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
||||
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.
|
||||
|
||||
2019-09-05 Gabriel F. T. Gomes <gabrielftg@linux.ibm.com>
|
||||
|
||||
* math/bits/mathcalls.h (totalorder, totalordermag): Replace
|
||||
|
@ -360,8 +360,7 @@ static const char *guess_category_value (int category,
|
||||
|
||||
#ifdef _LIBC
|
||||
# include "../locale/localeinfo.h"
|
||||
# define category_to_name(category) \
|
||||
_nl_category_names.str + _nl_category_name_idxs[category]
|
||||
# define category_to_name(category) _nl_category_names_get (category)
|
||||
#else
|
||||
static const char *category_to_name (int category);
|
||||
#endif
|
||||
|
@ -118,8 +118,7 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
|
||||
variables. */
|
||||
cloc_name = getenv ("LC_ALL");
|
||||
if (!name_present (cloc_name))
|
||||
cloc_name = getenv (_nl_category_names.str
|
||||
+ _nl_category_name_idxs[category]);
|
||||
cloc_name = getenv (_nl_category_names_get (category));
|
||||
if (!name_present (cloc_name))
|
||||
cloc_name = getenv ("LANG");
|
||||
if (!name_present (cloc_name))
|
||||
@ -207,8 +206,7 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
|
||||
locale_path, locale_path_len, mask,
|
||||
language, territory, codeset,
|
||||
normalized_codeset, modifier,
|
||||
_nl_category_names.str
|
||||
+ _nl_category_name_idxs[category], 0);
|
||||
_nl_category_names_get (category), 0);
|
||||
|
||||
if (locale_file == NULL)
|
||||
{
|
||||
@ -218,8 +216,7 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
|
||||
locale_path, locale_path_len, mask,
|
||||
language, territory, codeset,
|
||||
normalized_codeset, modifier,
|
||||
_nl_category_names.str
|
||||
+ _nl_category_name_idxs[category], 1);
|
||||
_nl_category_names_get (category), 1);
|
||||
if (locale_file == NULL)
|
||||
/* This means we are out of core. */
|
||||
return NULL;
|
||||
|
@ -199,8 +199,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
||||
newp = (char *) alloca (filenamelen
|
||||
+ 5 + _nl_category_name_sizes[category] + 1);
|
||||
__mempcpy (__mempcpy (__mempcpy (newp, file->filename, filenamelen),
|
||||
"/SYS_", 5),
|
||||
_nl_category_names.str + _nl_category_name_idxs[category],
|
||||
"/SYS_", 5), _nl_category_names_get (category),
|
||||
_nl_category_name_sizes[category] + 1);
|
||||
|
||||
fd = __open_nocancel (newp, O_RDONLY | O_CLOEXEC);
|
||||
|
@ -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;
|
||||
|
@ -131,8 +131,7 @@ __newlocale (int category_mask, const char *locale, locale_t base)
|
||||
for (cnt = 0; cnt < __LC_LAST; ++cnt)
|
||||
if (cnt != LC_ALL
|
||||
&& (size_t) (cp - np) == _nl_category_name_sizes[cnt]
|
||||
&& memcmp (np, (_nl_category_names.str
|
||||
+ _nl_category_name_idxs[cnt]), cp - np) == 0)
|
||||
&& memcmp (np, (_nl_category_names_get (cnt)), cp - np) == 0)
|
||||
break;
|
||||
|
||||
if (cnt == __LC_LAST)
|
||||
|
@ -65,20 +65,18 @@ static char *const _nl_current_used[] =
|
||||
|
||||
|
||||
/* Define an array of category names (also the environment variable names). */
|
||||
const union catnamestr_t _nl_category_names attribute_hidden =
|
||||
const struct catnamestr_t _nl_category_names attribute_hidden =
|
||||
{
|
||||
{
|
||||
#define DEFINE_CATEGORY(category, category_name, items, a) \
|
||||
category_name,
|
||||
category_name,
|
||||
#include "categories.def"
|
||||
#undef DEFINE_CATEGORY
|
||||
}
|
||||
};
|
||||
|
||||
const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden =
|
||||
{
|
||||
#define DEFINE_CATEGORY(category, category_name, items, a) \
|
||||
[category] = offsetof (union catnamestr_t, CATNAMEMF (__LINE__)),
|
||||
[category] = offsetof (struct catnamestr_t, CATNAMEMF (__LINE__)),
|
||||
#include "categories.def"
|
||||
#undef DEFINE_CATEGORY
|
||||
};
|
||||
@ -180,7 +178,7 @@ new_composite_name (int category, const char *newnames[__LC_LAST])
|
||||
const char *name = (category == LC_ALL ? newnames[i]
|
||||
: category == i ? newnames[0]
|
||||
: _nl_global_locale.__names[i]);
|
||||
p = __stpcpy (p, _nl_category_names.str + _nl_category_name_idxs[i]);
|
||||
p = __stpcpy (p, _nl_category_names_get (i));
|
||||
*p++ = '=';
|
||||
p = __stpcpy (p, name);
|
||||
*p++ = ';';
|
||||
@ -298,8 +296,7 @@ setlocale (int category, const char *locale)
|
||||
for (cnt = 0; cnt < __LC_LAST; ++cnt)
|
||||
if (cnt != LC_ALL
|
||||
&& (size_t) (cp - np) == _nl_category_name_sizes[cnt]
|
||||
&& (memcmp (np, (_nl_category_names.str
|
||||
+ _nl_category_name_idxs[cnt]), cp - np)
|
||||
&& (memcmp (np, (_nl_category_names_get (cnt)), cp - np)
|
||||
== 0))
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user