Mercurial > hg > octave-nkf > gnulib-hg
changeset 13721:5cea8d40bf2c
Fix endless loop in mbmemcasecoll.
* lib/mbmemcasecoll.c (apply_towlower): When mbrtowc returns 0, copy 1
byte.
* tests/test-mbmemcasecmp.h (test_ascii): Test embedded NULs.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 22 Sep 2010 13:34:54 +0200 |
parents | 593b9e6a58a7 |
children | 9f109e8f2ad2 |
files | ChangeLog lib/mbmemcasecoll.c tests/test-mbmemcasecmp.h |
diffstat | 3 files changed, 20 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-09-22 Pádraig Brady <P@draigbrady.com> + Bruno Haible <bruno@clisp.org> + + Fix endless loop in mbmemcasecoll. + * lib/mbmemcasecoll.c (apply_towlower): When mbrtowc returns 0, copy 1 + byte. + * tests/test-mbmemcasecmp.h (test_ascii): Test embedded NULs. + 2010-09-22 Bruno Haible <bruno@clisp.org> Tests for module 'memcoll'.
--- a/lib/mbmemcasecoll.c +++ b/lib/mbmemcasecoll.c @@ -1,5 +1,5 @@ /* Locale-specific case-ignoring memory comparison. - Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2001, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This program is free software: you can redistribute it and/or modify it @@ -61,8 +61,12 @@ break; if (n1 != (size_t)(-1)) { - wint_t wc2 = towlower (wc1); + wint_t wc2; + if (n1 == 0) /* NUL character? */ + n1 = 1; + + wc2 = towlower (wc1); if (wc2 != wc1) { size_t n2;
--- a/tests/test-mbmemcasecmp.h +++ b/tests/test-mbmemcasecmp.h @@ -62,6 +62,12 @@ ASSERT (my_casecmp ("para", 4, "paragraph", 9) < 0); ASSERT (my_casecmp ("paragraph", 9, "para", 4) > 0); + + /* Embedded NULs. */ + ASSERT (my_casecmp ("1\0", 2, "2\0", 2) < 0); + ASSERT (my_casecmp ("2\0", 2, "1\0", 2) > 0); + ASSERT (my_casecmp ("x\0""1", 3, "x\0""2", 3) < 0); + ASSERT (my_casecmp ("x\0""2", 3, "x\0""1", 3) > 0); } static void