This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix localedef collation handling of <U0000> (bug 15948)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]