]> granicus.if.org Git - php/commitdiff
Convert warnings to ValueError
authorGeorge Peter Banyard <girgias@php.net>
Sun, 8 Dec 2019 20:03:14 +0000 (21:03 +0100)
committerGeorge Peter Banyard <girgias@php.net>
Sun, 8 Dec 2019 20:03:14 +0000 (21:03 +0100)
ext/json/json.c
ext/json/tests/bug72787.phpt
ext/json/tests/json_decode_error.phpt

index 5db3621b322f8111c3c2a568fd05a11272f4939d..5c97e9678d449b0199216821c3ff6ae8692f9368 100644 (file)
@@ -313,13 +313,13 @@ static PHP_FUNCTION(json_decode)
        }
 
        if (depth <= 0) {
-               php_error_docref(NULL, E_WARNING, "Depth must be greater than zero");
-               RETURN_NULL();
+               zend_value_error("Depth must be greater than zero");
+               return;
        }
 
        if (depth > INT_MAX) {
-               php_error_docref(NULL, E_WARNING, "Depth must be lower than %d", INT_MAX);
-               RETURN_NULL();
+               zend_value_error("Depth must be lower than %d", INT_MAX);
+               return;
        }
 
        /* For BC reasons, the bool $assoc overrides the long $options bit for PHP_JSON_OBJECT_AS_ARRAY */
index 2b0a49121a9710b78d81ab72f39b4f8bfa47483e..d2d1f8017716d472c905b7906c7e56adcbaad919 100644 (file)
@@ -6,9 +6,12 @@ Bug #72787 (json_decode reads out of bounds)
 --FILE--
 <?php
 
-var_dump(json_decode('[]', false, 0x100000000));
+try {
+    var_dump(json_decode('[]', false, 0x100000000));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 ?>
 --EXPECTF--
-Warning: json_decode(): Depth must be lower than %d in %s on line %d
-NULL
+Depth must be lower than %d
index 4584b7fa5c43d0cf36f926e184434a53b55a7f00..b286df8e744694e44276b2ee02eb192f4d835653 100644 (file)
@@ -7,13 +7,16 @@ Test json_decode() function : error conditions
 echo "*** Testing json_decode() : error conditions ***\n";
 
 echo "\n-- Testing json_decode() function with depth below 0 --\n";
-var_dump(json_decode('"abc"', true, -1));
+
+try {
+    var_dump(json_decode('"abc"', true, -1));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 ?>
---EXPECTF--
+--EXPECT--
 *** Testing json_decode() : error conditions ***
 
 -- Testing json_decode() function with depth below 0 --
-
-Warning: json_decode(): Depth must be greater than zero in %s on line %d
-NULL
+Depth must be greater than zero