Mercurial > gnulib
changeset 33212:9d2463918a70
unistr/u8-strchr: Fix several bugs.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 31 Jul 2010 21:28:55 +0200 |
parents | b73669b7dfcb |
children | a8c8ef029f8b |
files | ChangeLog lib/unistr/u8-strchr.c |
diffstat | 2 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sat Jul 31 21:26:01 2010 +0200 +++ b/ChangeLog Sat Jul 31 21:28:55 2010 +0200 @@ -1,5 +1,9 @@ 2010-07-31 Bruno Haible <bruno@clisp.org> + unistr/u8-strchr: Fix several bugs. + * lib/unistr/u8-strchr.c (u8_strchr): Don't search beyond the end of + the string. When not found, return NULL, not a pointer near the end. + More tests for unistr/u8-strchr. * tests/unistr/test-strchr.h (test_strchr): Renamed from main. Check that the function does not read past the first occurrence of the byte
--- a/lib/unistr/u8-strchr.c Sat Jul 31 21:26:01 2010 +0200 +++ b/lib/unistr/u8-strchr.c Sat Jul 31 21:28:55 2010 +0200 @@ -62,7 +62,7 @@ switch (u8_uctomb_aux (c, uc, 6)) { case 2: - if (*s == 0) + if (*s == 0 || s[1] == 0) break; { uint8_t c0 = c[0]; @@ -96,11 +96,11 @@ if (s[1] == 0) break; } - return (uint8_t *) s; } + break; case 3: - if (*s == 0 || s[1] == 0) + if (*s == 0 || s[1] == 0 || s[2] == 0) break; { uint8_t c0 = c[0]; @@ -147,7 +147,7 @@ } case 4: - if (*s == 0 || s[1] == 0 || s[2] == 0) + if (*s == 0 || s[1] == 0 || s[2] == 0 || s[3] == 0) break; { uint8_t c0 = c[0];