Skip to content

Commit 34865f5

Browse files
marandallcmb69
authored andcommitted
Warnings become errors for imagepolygon et al
1 parent 87dbb32 commit 34865f5

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

ext/gd/gd.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,16 +2786,18 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
27862786

27872787
nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
27882788
if (nelem < 6) {
2789-
php_error_docref(NULL, E_WARNING, "You must have at least 3 points in your array");
2790-
RETURN_FALSE;
2789+
zend_throw_error(NULL, "You must have at least 3 points in your array");
2790+
return;
27912791
}
2792+
27922793
if (npoints <= 0) {
2793-
php_error_docref(NULL, E_WARNING, "You must give a positive number of points");
2794-
RETURN_FALSE;
2794+
zend_throw_error(NULL, "You must give a positive number of points");
2795+
return;
27952796
}
2797+
27962798
if (nelem < npoints * 2) {
2797-
php_error_docref(NULL, E_WARNING, "Trying to use %d points in array with only %d points", npoints, nelem/2);
2798-
RETURN_FALSE;
2799+
zend_throw_error(NULL, "Trying to use %d points in array with only %d points", npoints, nelem/2);
2800+
return;
27992801
}
28002802

28012803
points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);

ext/gd/tests/imagefilledpolygon_negative.phpt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ imagefilledpolygon() with a negative num of points
66
?>
77
--FILE--
88
<?php
9+
require __DIR__ . '/func.inc';
10+
911
$im = imagecreate(100, 100);
1012
$black = imagecolorallocate($im, 0, 0, 0);
11-
if (imagefilledpolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)) echo "should be false";
13+
14+
trycatch_dump(
15+
fn() => imagefilledpolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)
16+
);
17+
1218
imagedestroy($im);
1319
?>
14-
--EXPECTF--
15-
Warning: imagefilledpolygon(): You must give a positive number of points in %s on line %d
20+
--EXPECT--
21+
!! [Error] You must give a positive number of points

ext/gd/tests/imagepolygon_negative.phpt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ imagepolygon() with a negative num of points
66
?>
77
--FILE--
88
<?php
9+
require __DIR__ . '/func.inc';
10+
911
$im = imagecreate(100, 100);
1012
$black = imagecolorallocate($im, 0, 0, 0);
11-
if (imagepolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)) echo "should be false";
13+
14+
trycatch_dump(
15+
fn() => imagepolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)
16+
);
17+
1218
imagedestroy($im);
1319
?>
14-
--EXPECTF--
15-
Warning: imagepolygon(): You must give a positive number of points in %s on line %d
20+
--EXPECT--
21+
!! [Error] You must give a positive number of points

0 commit comments

Comments
 (0)