From: Bruno Haible Date: Sat, 31 Jul 2010 19:28:55 +0000 (+0200) Subject: unistr/u8-strchr: Fix several bugs. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a09e8291d1bd692b26684c2bb7d9379593e8846;p=pspp unistr/u8-strchr: Fix several bugs. --- diff --git a/ChangeLog b/ChangeLog index 264945825f..8c83dff08d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-07-31 Bruno Haible + 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 diff --git a/lib/unistr/u8-strchr.c b/lib/unistr/u8-strchr.c index 03d6138adc..a67b8f322e 100644 --- a/lib/unistr/u8-strchr.c +++ b/lib/unistr/u8-strchr.c @@ -62,7 +62,7 @@ u8_strchr (const uint8_t *s, ucs4_t uc) 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 @@ u8_strchr (const uint8_t *s, ucs4_t uc) 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 @@ u8_strchr (const uint8_t *s, ucs4_t uc) } 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];