Skip to content

Commit 1059e3d

Browse files
committed
Promote warnings to errors in str_repeat()
1 parent bba7f38 commit 1059e3d

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

ext/mbstring/tests/bug73646.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ if (!function_exists('mb_ereg')) die('skip mbregex support not available');
77
?>
88
--FILE--
99
<?php
10-
11-
$v1=str_repeat("#", -1);
12-
var_dump(mb_ereg_search_init($v1));
10+
var_dump(mb_ereg_search_init(NULL));
1311
?>
14-
--EXPECTF--
15-
Warning: str_repeat(): Second argument has to be greater than or equal to 0 in %sbug73646.php on line %d
12+
--EXPECT--
1613
bool(true)

ext/opcache/tests/bug70207.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ function bar() {
1414
}
1515
function foo() {
1616
try { return bar(); }
17-
finally { @str_repeat("foo", -10); }
17+
finally {
18+
@fopen("non-existent", 'r');
19+
}
1820
}
1921

2022
var_dump(foo());

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5363,7 +5363,7 @@ PHP_FUNCTION(str_repeat)
53635363
ZEND_PARSE_PARAMETERS_END();
53645364

53655365
if (mult < 0) {
5366-
php_error_docref(NULL, E_WARNING, "Second argument has to be greater than or equal to 0");
5366+
zend_throw_error(NULL, "Second argument has to be greater than or equal to 0");
53675367
return;
53685368
}
53695369

-432 Bytes
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Test str_repeat() function: usage variations - complex strings containing other than 7-bit chars
3+
--INI--
4+
precision=14
5+
--FILE--
6+
<?php
7+
$str = chr(0).chr(128).chr(129).chr(234).chr(235).chr(254).chr(255);
8+
9+
$withCodePoint = str_repeat($str, chr(51)); // ASCII value of '3' given
10+
$explicit = str_repeat($str, 3);
11+
12+
var_dump($withCodePoint === $explicit);
13+
var_dump( bin2hex( $withCodePoint ) );
14+
var_dump( bin2hex( $explicit ) );
15+
16+
?>
17+
DONE
18+
--EXPECT--
19+
bool(true)
20+
string(42) "008081eaebfeff008081eaebfeff008081eaebfeff"
21+
string(42) "008081eaebfeff008081eaebfeff008081eaebfeff"
22+
DONE

0 commit comments

Comments
 (0)