From patchwork Fri Oct 27 23:56:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafal Luzynski X-Patchwork-Id: 23946 Received: (qmail 60876 invoked by alias); 27 Oct 2017 23:56:29 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 60423 invoked by uid 89); 27 Oct 2017 23:56:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, URIBL_RED autolearn=ham version=3.3.2 spammy=month X-HELO: aev204.rev.netart.pl X-Spam-Score: 0 Date: Sat, 28 Oct 2017 01:56:23 +0200 (CEST) From: Rafal Luzynski Reply-To: Rafal Luzynski To: GNU C Library Message-ID: <530601722.145177.1509148583043@poczta.nazwa.pl> Subject: [COMMITTED] Correct the size of _nl_value_type_LC_... arrays. MIME-Version: 1.0 X-Originating-Client: com.openexchange.ox.gui.dhtml 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_ arrays. Reviewed-by: Zack Weinberg --- ChangeLog | 5 +++++ locale/loadlocale.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 61bbfa6..a8c89b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-10-27 Rafal Luzynski + + * locale/loadlocale.c: Correct size of + _nl_value_type_LC_ arrays. + 2017-10-27 Joseph Myers * math/math.h [__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !_LIBC)]: diff --git a/locale/loadlocale.c b/locale/loadlocale.c index 2bdb39b..2dba86d 100644 --- a/locale/loadlocale.c +++ b/locale/loadlocale.c @@ -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"