mirror of
https://github.com/php/php-src.git
synced 2025-08-18 23:18:56 +02:00
fix #39032 (strcspn() stops on null character)
This commit is contained in:
parent
8d85069827
commit
88e893b50a
2 changed files with 22 additions and 3 deletions
|
@ -2306,11 +2306,12 @@ PHPAPI int php_u_strcspn(UChar *s1, UChar *s2, UChar *s1_end, UChar *s2_end)
|
||||||
int codepts;
|
int codepts;
|
||||||
UChar32 ch;
|
UChar32 ch;
|
||||||
|
|
||||||
for (i = 0, codepts = 0 ; i < len1 ; codepts++) {
|
for (i = 0, codepts = 0 ; i < len1 ; ) {
|
||||||
U16_NEXT(s1, i, len1, ch);
|
U16_NEXT(s1, i, len1, ch);
|
||||||
if (u_memchr32(s2, ch, len2)) {
|
if (!len2 || u_memchr32(s2, ch, len2)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
codepts++;
|
||||||
}
|
}
|
||||||
return 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) {
|
if (*spanp == c || p == s1_end) {
|
||||||
return p - s1;
|
return p - s1;
|
||||||
}
|
}
|
||||||
} while (spanp++ < s2_end);
|
} while (spanp++ < (s2_end - 1));
|
||||||
c = *++p;
|
c = *++p;
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
|
18
ext/standard/tests/strings/bug39032.phpt
Normal file
18
ext/standard/tests/strings/bug39032.phpt
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue