fix #39032 (strcspn() stops on null character)

This commit is contained in:
Antony Dovgal 2006-10-04 11:12:21 +00:00
parent 8d85069827
commit 88e893b50a
2 changed files with 22 additions and 3 deletions

View File

@ -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 */

View File

@ -0,0 +1,18 @@
--TEST--
Bug #39032 (strcspn() stops on null character)
--FILE--
<?php
var_dump(strcspn(chr(0),"x"));
var_dump(strcspn(chr(0),""));
var_dump(strcspn(chr(0),"qweqwe"));
var_dump(strcspn(chr(1),"qweqwe"));
echo "Done\n";
?>
--EXPECTF--
int(1)
int(0)
int(1)
int(1)
Done