]> granicus.if.org Git - php/commitdiff
Warnings become errors for imagepolygon et al
authorMark <mrandall@digitellinc.com>
Tue, 3 Sep 2019 23:46:41 +0000 (01:46 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 4 Sep 2019 10:35:48 +0000 (12:35 +0200)
ext/gd/gd.c
ext/gd/tests/imagefilledpolygon_negative.phpt
ext/gd/tests/imagepolygon_negative.phpt

index 7dd14ab5d02fc06c3416085329929cf533f178b9..52db8cea941adde551b02137c2845acee5bd3ecc 100644 (file)
@@ -2786,16 +2786,18 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
 
        nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
        if (nelem < 6) {
-               php_error_docref(NULL, E_WARNING, "You must have at least 3 points in your array");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "You must have at least 3 points in your array");
+               return;
        }
+
        if (npoints <= 0) {
-               php_error_docref(NULL, E_WARNING, "You must give a positive number of points");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "You must give a positive number of points");
+               return;
        }
+
        if (nelem < npoints * 2) {
-               php_error_docref(NULL, E_WARNING, "Trying to use %d points in array with only %d points", npoints, nelem/2);
-               RETURN_FALSE;
+               zend_throw_error(NULL, "Trying to use %d points in array with only %d points", npoints, nelem/2);
+               return;
        }
 
        points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);
index a572a195f5d0fa5f64d7bb95c03fa33e8a45f6ce..eae032d51e5fe69b58b03d0e529feaa7a8a5425a 100644 (file)
@@ -6,10 +6,16 @@ imagefilledpolygon() with a negative num of points
 ?>
 --FILE--
 <?php
+require __DIR__ . '/func.inc';
+
 $im = imagecreate(100, 100);
 $black = imagecolorallocate($im, 0, 0, 0);
-if (imagefilledpolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)) echo "should be false";
+
+trycatch_dump(
+    fn() => imagefilledpolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)
+);
+
 imagedestroy($im);
 ?>
---EXPECTF--
-Warning: imagefilledpolygon(): You must give a positive number of points in %s on line %d
+--EXPECT--
+!! [Error] You must give a positive number of points
index d122a3bbaa73dce92d36e0a6aa8af90d2610879a..8334589e38e1d0d3006563412b1b8dbec16d8cde 100644 (file)
@@ -6,10 +6,16 @@ imagepolygon() with a negative num of points
 ?>
 --FILE--
 <?php
+require __DIR__ . '/func.inc';
+
 $im = imagecreate(100, 100);
 $black = imagecolorallocate($im, 0, 0, 0);
-if (imagepolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)) echo "should be false";
+
+trycatch_dump(
+    fn() => imagepolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)
+);
+
 imagedestroy($im);
 ?>
---EXPECTF--
-Warning: imagepolygon(): You must give a positive number of points in %s on line %d
+--EXPECT--
+!! [Error] You must give a positive number of points