Skip to content

Commit d1f9ab1

Browse files
marandallcmb69
authored andcommitted
Warnings to errors imageconvolution
1 parent 34865f5 commit d1f9ab1

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

ext/gd/gd.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,23 +3698,23 @@ PHP_FUNCTION(imageconvolution)
36983698

36993699
nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
37003700
if (nelem != 3) {
3701-
php_error_docref(NULL, E_WARNING, "You must have 3x3 array");
3702-
RETURN_FALSE;
3701+
zend_throw_error(NULL, "Convolution matrix must be a 3x3 array");
3702+
return;
37033703
}
37043704

37053705
for (i=0; i<3; i++) {
37063706
if ((var = zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i))) != NULL && Z_TYPE_P(var) == IS_ARRAY) {
37073707
if (zend_hash_num_elements(Z_ARRVAL_P(var)) != 3 ) {
3708-
php_error_docref(NULL, E_WARNING, "You must have 3x3 array");
3709-
RETURN_FALSE;
3708+
zend_throw_error(NULL, "Convolution matrix must be a 3x3 array, matrix[%d] only has %d elements", i, zend_hash_num_elements(Z_ARRVAL_P(var)));
3709+
return;
37103710
}
37113711

37123712
for (j=0; j<3; j++) {
37133713
if ((var2 = zend_hash_index_find(Z_ARRVAL_P(var), j)) != NULL) {
37143714
matrix[i][j] = (float) zval_get_double(var2);
37153715
} else {
3716-
php_error_docref(NULL, E_WARNING, "You must have a 3x3 matrix");
3717-
RETURN_FALSE;
3716+
zend_throw_error(NULL, "Convolution matrix must be a 3x3 array, matrix[%d][%d] cannot be found (missing integer key)", i, j);
3717+
return;
37183718
}
37193719
}
37203720
}

ext/gd/tests/imageconvolution_error2.phpt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ if (!extension_loaded("gd")) die("skip GD not present");
99
?>
1010
--FILE--
1111
<?php
12+
require __DIR__ . '/func.inc';
13+
1214
$image = imagecreatetruecolor(180, 30);
1315

1416
// Writes the text and apply a gaussian blur on the image
@@ -19,8 +21,10 @@ $gaussian = array(
1921
array(2.0, 4.0, 2.0)
2022
);
2123

22-
var_dump(imageconvolution($image, $gaussian, 16, 0));
24+
trycatch_dump(
25+
fn() => imageconvolution($image, $gaussian, 16, 0)
26+
);
27+
2328
?>
24-
--EXPECTF--
25-
Warning: imageconvolution(): You must have 3x3 array in %s on line %d
26-
bool(false)
29+
--EXPECT--
30+
!! [Error] Convolution matrix must be a 3x3 array

ext/gd/tests/imageconvolution_error3.phpt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ if (!extension_loaded("gd")) die("skip GD not present");
99
?>
1010
--FILE--
1111
<?php
12+
require __DIR__ . '/func.inc';
13+
1214
$image = imagecreatetruecolor(180, 30);
1315

1416
// Writes the text and apply a gaussian blur on the image
@@ -20,8 +22,18 @@ $gaussian = array(
2022
array(1.0, 2.0)
2123
);
2224

23-
var_dump(imageconvolution($image, $gaussian, 16, 0));
25+
$gaussian_bad_key = array(
26+
array(1.0, 2.0, 1.0),
27+
array(2.0, 4.0, 2.0),
28+
array(1.0, 2.0, 'x' => 1.0)
29+
);
30+
31+
trycatch_dump(
32+
fn() => imageconvolution($image, $gaussian, 16, 0),
33+
fn() => imageconvolution($image, $gaussian_bad_key, 16, 0)
34+
);
35+
2436
?>
25-
--EXPECTF--
26-
Warning: imageconvolution(): You must have 3x3 array in %s on line %d
27-
bool(false)
37+
--EXPECT--
38+
!! [Error] Convolution matrix must be a 3x3 array, matrix[2] only has 2 elements
39+
!! [Error] Convolution matrix must be a 3x3 array, matrix[2][2] cannot be found (missing integer key)

0 commit comments

Comments
 (0)