]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Correct the size of _nl_value_type_LC_... arrays.
authorRafal Luzynski <digitalfreak@lingonborough.com>
Tue, 11 Jul 2017 23:32:33 +0000 (01:32 +0200)
committerRafal Luzynski <digitalfreak@lingonborough.com>
Fri, 27 Oct 2017 23:46:14 +0000 (01:46 +0200)
There were several problems with checking the array size in the past,
for example BZ#356, caused by incorrectly assuming that every locale
token represents one element.  In fact, if a token represented
a subarray, for example an array of month names or characters category
and it appeared at the end of the array the compiler assumed that
the array ends just after the first element of the subarray.
A workaround used in the past was to skip some categories while testing,
for example LC_CTYPE.  Now when we are about to add alternative month
names to LC_TIME (BZ#10871) this will fail again.

* locale/loadlocale.c: Correct size of
_nl_value_type_LC_<category> arrays.

Reviewed-by: Zack Weinberg <zackw@panix.com>
ChangeLog
locale/loadlocale.c

index 61bbfa64ccac9b4428a17f3d7e5f8e7a6e8b3cfa..a8c89b738313795915624385c5c27c506e799f9d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-10-27  Rafal Luzynski  <digitalfreak@lingonborough.com>
+
+       * locale/loadlocale.c: Correct size of
+       _nl_value_type_LC_<category> arrays.
+
 2017-10-27  Joseph Myers  <joseph@codesourcery.com>
 
        * math/math.h [__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !_LIBC)]:
index 2bdb39b4b8873ac1a759b20c0d936a7eda3fb4e7..2dba86d7738201d80646b756750412864f618209 100644 (file)
@@ -44,8 +44,12 @@ static const size_t _nl_category_num_items[] =
 
 #define NO_PAREN(arg, rest...) arg, ##rest
 
+/* The size of the array must be specified explicitly because some of
+   the 'items' may be subarrays, which will cause the compiler to deduce
+   an incorrect size from the initializer.  */
 #define DEFINE_CATEGORY(category, category_name, items, a) \
-static const enum value_type _nl_value_type_##category[] = { NO_PAREN items };
+static const enum value_type _nl_value_type_##category     \
+  [_NL_ITEM_INDEX (_NL_NUM_##category)] = { NO_PAREN items };
 #define DEFINE_ELEMENT(element, element_name, optstd, type, rest...) \
   [_NL_ITEM_INDEX (element)] = type,
 #include "categories.def"