summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/standard/string.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 6b8b633c9b..31a6d7d295 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -4463,11 +4463,10 @@ PHP_FUNCTION(substr_count)
if (Z_STRLEN_PP(needle) == 1) {
cmp = Z_STRVAL_PP(needle)[0];
-
- while (p < endp) {
- if (*(p++) == cmp) {
- count++;
- }
+
+ while ((p = memchr(p, cmp, endp - p))) {
+ count++;
+ p++;
}
} else {
while ((p = php_memnstr(p, Z_STRVAL_PP(needle), Z_STRLEN_PP(needle), endp))) {