From: Mark Date: Tue, 3 Sep 2019 23:38:41 +0000 (+0200) Subject: Warnings to errors imageconvolution X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1f9ab11b384ccc5496f9435d2e4a1e7ad48339c;p=php Warnings to errors imageconvolution --- diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 52db8cea94..d0affc2d16 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3698,23 +3698,23 @@ PHP_FUNCTION(imageconvolution) nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix)); if (nelem != 3) { - php_error_docref(NULL, E_WARNING, "You must have 3x3 array"); - RETURN_FALSE; + zend_throw_error(NULL, "Convolution matrix must be a 3x3 array"); + return; } for (i=0; i<3; i++) { if ((var = zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i))) != NULL && Z_TYPE_P(var) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(var)) != 3 ) { - php_error_docref(NULL, E_WARNING, "You must have 3x3 array"); - RETURN_FALSE; + 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))); + return; } for (j=0; j<3; j++) { if ((var2 = zend_hash_index_find(Z_ARRVAL_P(var), j)) != NULL) { matrix[i][j] = (float) zval_get_double(var2); } else { - php_error_docref(NULL, E_WARNING, "You must have a 3x3 matrix"); - RETURN_FALSE; + zend_throw_error(NULL, "Convolution matrix must be a 3x3 array, matrix[%d][%d] cannot be found (missing integer key)", i, j); + return; } } } diff --git a/ext/gd/tests/imageconvolution_error2.phpt b/ext/gd/tests/imageconvolution_error2.phpt index 217e3e1547..d8d0ca1ab2 100644 --- a/ext/gd/tests/imageconvolution_error2.phpt +++ b/ext/gd/tests/imageconvolution_error2.phpt @@ -9,6 +9,8 @@ if (!extension_loaded("gd")) die("skip GD not present"); ?> --FILE-- imageconvolution($image, $gaussian, 16, 0) +); + ?> ---EXPECTF-- -Warning: imageconvolution(): You must have 3x3 array in %s on line %d -bool(false) +--EXPECT-- +!! [Error] Convolution matrix must be a 3x3 array diff --git a/ext/gd/tests/imageconvolution_error3.phpt b/ext/gd/tests/imageconvolution_error3.phpt index 5f1ddc95be..49aa2be9d0 100644 --- a/ext/gd/tests/imageconvolution_error3.phpt +++ b/ext/gd/tests/imageconvolution_error3.phpt @@ -9,6 +9,8 @@ if (!extension_loaded("gd")) die("skip GD not present"); ?> --FILE-- 1.0) +); + +trycatch_dump( + fn() => imageconvolution($image, $gaussian, 16, 0), + fn() => imageconvolution($image, $gaussian_bad_key, 16, 0) +); + ?> ---EXPECTF-- -Warning: imageconvolution(): You must have 3x3 array in %s on line %d -bool(false) +--EXPECT-- +!! [Error] Convolution matrix must be a 3x3 array, matrix[2] only has 2 elements +!! [Error] Convolution matrix must be a 3x3 array, matrix[2][2] cannot be found (missing integer key)