From: Antony Dovgal Date: Wed, 4 Oct 2006 11:12:21 +0000 (+0000) Subject: fix #39032 (strcspn() stops on null character) X-Git-Tag: RELEASE_1_0_0RC1~1432 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88e893b50aa7056932fd94e76f6813a84fb7bbd6;p=php fix #39032 (strcspn() stops on null character) --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 9ad5f74e1f..9d148c7e89 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2306,11 +2306,12 @@ PHPAPI int php_u_strcspn(UChar *s1, UChar *s2, UChar *s1_end, UChar *s2_end) int codepts; UChar32 ch; - for (i = 0, codepts = 0 ; i < len1 ; codepts++) { + for (i = 0, codepts = 0 ; i < len1 ; ) { U16_NEXT(s1, i, len1, ch); - if (u_memchr32(s2, ch, len2)) { + if (!len2 || u_memchr32(s2, ch, len2)) { break; } + codepts++; } return codepts; } @@ -2329,7 +2330,7 @@ PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end) if (*spanp == c || p == s1_end) { return p - s1; } - } while (spanp++ < s2_end); + } while (spanp++ < (s2_end - 1)); c = *++p; } /* NOTREACHED */ diff --git a/ext/standard/tests/strings/bug39032.phpt b/ext/standard/tests/strings/bug39032.phpt new file mode 100644 index 0000000000..dbd39ec9d8 --- /dev/null +++ b/ext/standard/tests/strings/bug39032.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #39032 (strcspn() stops on null character) +--FILE-- + +--EXPECTF-- +int(1) +int(0) +int(1) +int(1) +Done