Skip to content

Commit 6a05e42

Browse files
marandallcmb69
authored andcommitted
Warnings to Errors imagetruecolortopalette
1 parent fde52e8 commit 6a05e42

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

ext/gd/gd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,10 @@ PHP_FUNCTION(imagetruecolortopalette)
885885
}
886886

887887
if (ncolors <= 0 || ZEND_LONG_INT_OVFL(ncolors)) {
888-
php_error_docref(NULL, E_WARNING, "Number of colors has to be greater than zero and no more than %d", INT_MAX);
889-
RETURN_FALSE;
888+
zend_throw_error(NULL, "Number of colors has to be greater than zero and no more than %d", INT_MAX);
889+
return;
890890
}
891+
891892
if (gdImageTrueColorToPalette(im, dither, (int)ncolors)) {
892893
RETURN_TRUE;
893894
} else {

ext/gd/tests/bug72697.phpt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ if (PHP_INT_MAX !== 9223372036854775807) die("skip for 64-bit long systems only"
88
--FILE--
99
<?php
1010

11+
require __DIR__ . '/func.inc';
12+
1113
$img=imagecreatetruecolor(10, 10);
12-
imagetruecolortopalette($img, false, PHP_INT_MAX / 8);
14+
15+
trycatch_dump(
16+
fn() => imagetruecolortopalette($img, false, PHP_INT_MAX / 8)
17+
);
18+
1319
?>
1420
DONE
15-
--EXPECTF--
16-
Warning: imagetruecolortopalette(): Number of colors has to be greater than zero and no more than 2147483647 in %sbug72697.php on line %d
21+
--EXPECT--
22+
!! [Error] Number of colors has to be greater than zero and no more than 2147483647
1723
DONE

ext/gd/tests/imagetruecolortopalette_error3.phpt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ Rafael Dohms <rdohms [at] gmail [dot] com>
99
?>
1010
--FILE--
1111
<?php
12+
require __DIR__ . '/func.inc';
13+
1214
$image = imagecreatetruecolor(50, 50);
13-
imagetruecolortopalette($image, true, null);
15+
16+
trycatch_dump(
17+
fn() => imagetruecolortopalette($image, true, null)
18+
);
19+
1420
?>
15-
--EXPECTF--
16-
Warning: imagetruecolortopalette(): Number of colors has to be greater than zero and no more than %d in %s on line %d
21+
--EXPECT--
22+
!! [Error] Number of colors has to be greater than zero and no more than 2147483647

ext/gd/tests/imagetruecolortopalette_error4.phpt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ Rafael Dohms <rdohms [at] gmail [dot] com>
99
?>
1010
--FILE--
1111
<?php
12+
require __DIR__ . '/func.inc';
13+
1214
$image = imagecreatetruecolor(50, 50);
1315

14-
imagetruecolortopalette($image, true, 0);
15-
imagetruecolortopalette($image, true, -1);
16+
trycatch_dump(
17+
fn() => imagetruecolortopalette($image, true, 0),
18+
fn() => imagetruecolortopalette($image, true, -1)
19+
);
1620

1721
?>
18-
--EXPECTF--
19-
Warning: imagetruecolortopalette(): Number of colors has to be greater than zero and no more than %d in %s line %d
20-
21-
Warning: imagetruecolortopalette(): Number of colors has to be greater than zero and no more than %d in %s line %d
22+
--EXPECT--
23+
!! [Error] Number of colors has to be greater than zero and no more than 2147483647
24+
!! [Error] Number of colors has to be greater than zero and no more than 2147483647

0 commit comments

Comments
 (0)