This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Fix localedef collation handling of <U0000> (bug 15948)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Thu, 3 Oct 2013 22:51:16 +0000
- Subject: Re: Fix localedef collation handling of <U0000> (bug 15948)
- Authentication-results: sourceware.org; auth=none
- References: <Pine dot LNX dot 4 dot 64 dot 1309122206530 dot 28584 at digraph dot polyomino dot org dot uk> <20130924215529 dot 996342C099 at topped-with-meat dot com>
On Tue, 24 Sep 2013, Roland McGrath wrote:
> > as can be seen by adding "assert (runp->nwcs > 0);" before that code,
>
> So add that assert.
This patch version adds the assertion. As previously noted, the
examples for which the patch matters are locales such as ar_SA.UTF-8
where <U0000> is included in the LC_COLLATE definition.
Tested x86_64 (glibc testsuite and "make localedata/install-locales").
2013-10-03 Richard Sandiford <richard@codesourcery.com>
Joseph Myers <joseph@codesourcery.com
[BZ #15948]
* locale/programs/ld-collate.c (new_element): Handle <U0000> as a
single character.
(add_to_tablewc): Assert sequence of wide characters is nonempty.
diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c
index 31e2d05..1edeeb3 100644
--- a/locale/programs/ld-collate.c
+++ b/locale/programs/ld-collate.c
@@ -350,6 +350,9 @@ new_element (struct locale_collate_t *collate, const char *mbs, size_t mbslen,
{
size_t nwcs = wcslen ((wchar_t *) wcs);
uint32_t zero = 0;
+ /* Handle <U0000> as a single character. */
+ if (nwcs == 0)
+ nwcs = 1;
obstack_grow (&collate->mempool, wcs, nwcs * sizeof (uint32_t));
obstack_grow (&collate->mempool, &zero, sizeof (uint32_t));
newp->wcs = (uint32_t *) obstack_finish (&collate->mempool);
@@ -2076,6 +2079,7 @@ add_to_tablewc (uint32_t ch, struct element_t *runp)
weightidx = output_weightwc (atwc.weightpool, atwc.collate,
runp);
+ assert (runp->nwcs > 0);
added = (1 + 1 + runp->nwcs - 1) * sizeof (int32_t);
if (sizeof (int) == sizeof (int32_t))
obstack_make_room (atwc.extrapool, added);
--
Joseph S. Myers
joseph@codesourcery.com