Skip to content

Commit 734932e

Browse files
committed
Convert warnings to ValueError
1 parent 761e8c7 commit 734932e

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

ext/json/json.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ static PHP_FUNCTION(json_decode)
313313
}
314314

315315
if (depth <= 0) {
316-
php_error_docref(NULL, E_WARNING, "Depth must be greater than zero");
317-
RETURN_NULL();
316+
zend_value_error("Depth must be greater than zero");
317+
return;
318318
}
319319

320320
if (depth > INT_MAX) {
321-
php_error_docref(NULL, E_WARNING, "Depth must be lower than %d", INT_MAX);
322-
RETURN_NULL();
321+
zend_value_error("Depth must be lower than %d", INT_MAX);
322+
return;
323323
}
324324

325325
/* For BC reasons, the bool $assoc overrides the long $options bit for PHP_JSON_OBJECT_AS_ARRAY */

ext/json/tests/bug72787.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ Bug #72787 (json_decode reads out of bounds)
66
--FILE--
77
<?php
88

9-
var_dump(json_decode('[]', false, 0x100000000));
9+
try {
10+
var_dump(json_decode('[]', false, 0x100000000));
11+
} catch (\ValueError $e) {
12+
echo $e->getMessage() . \PHP_EOL;
13+
}
1014

1115
?>
1216
--EXPECTF--
13-
Warning: json_decode(): Depth must be lower than %d in %s on line %d
14-
NULL
17+
Depth must be lower than %d

ext/json/tests/json_decode_error.phpt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ Test json_decode() function : error conditions
77
echo "*** Testing json_decode() : error conditions ***\n";
88

99
echo "\n-- Testing json_decode() function with depth below 0 --\n";
10-
var_dump(json_decode('"abc"', true, -1));
10+
11+
try {
12+
var_dump(json_decode('"abc"', true, -1));
13+
} catch (\ValueError $e) {
14+
echo $e->getMessage() . \PHP_EOL;
15+
}
1116

1217
?>
13-
--EXPECTF--
18+
--EXPECT--
1419
*** Testing json_decode() : error conditions ***
1520

1621
-- Testing json_decode() function with depth below 0 --
17-
18-
Warning: json_decode(): Depth must be greater than zero in %s on line %d
19-
NULL
22+
Depth must be greater than zero

0 commit comments

Comments
 (0)