Skip to content

Commit

Permalink
Prefer ValueError over Error in GD
Browse files Browse the repository at this point in the history
Cf. <#4682>.
  • Loading branch information
cmb69 committed Sep 10, 2019
1 parent aeaab8e commit 4f40743
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 68 deletions.
54 changes: 27 additions & 27 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ PHP_FUNCTION(imagesetstyle)

num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles));
if (num_styles == 0) {
zend_throw_error(NULL, "Styles array must not be empty");
zend_value_error("Styles array must not be empty");
return;
}

Expand Down Expand Up @@ -885,7 +885,7 @@ PHP_FUNCTION(imagetruecolortopalette)
}

if (ncolors <= 0 || ZEND_LONG_INT_OVFL(ncolors)) {
zend_throw_error(NULL, "Number of colors has to be greater than zero and no more than %d", INT_MAX);
zend_value_error("Number of colors has to be greater than zero and no more than %d", INT_MAX);
return;
}

Expand Down Expand Up @@ -1109,7 +1109,7 @@ PHP_FUNCTION(imagelayereffect)

#define CHECK_RGBA_RANGE(component, name) \
if (component < 0 || component > gd##name##Max) { \
zend_throw_error(NULL, #name " component is out of range, must be between 0 and %d (inclusive)", gd##name##Max); \
zend_value_error(#name " component is out of range, must be between 0 and %d (inclusive)", gd##name##Max); \
return; \
}

Expand Down Expand Up @@ -1712,12 +1712,12 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
}

if (width < 1) {
zend_throw_error(NULL, "Width must be at least 1");
zend_value_error("Width must be at least 1");
return;
}

if (height < 1) {
zend_throw_error(NULL, "Height must be at least 1");
zend_value_error("Height must be at least 1");
return;
}

Expand Down Expand Up @@ -2445,7 +2445,7 @@ PHP_FUNCTION(imagegammacorrect)
}

if ( input <= 0.0 || output <= 0.0 ) {
zend_throw_error(NULL, "Gamma values must be positive");
zend_value_error("Gamma values must be positive");
return;
}

Expand Down Expand Up @@ -2786,17 +2786,17 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)

nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
if (nelem < 6) {
zend_throw_error(NULL, "You must have at least 3 points in your array");
zend_value_error("You must have at least 3 points in your array");
return;
}

if (npoints <= 0) {
zend_throw_error(NULL, "You must give a positive number of points");
zend_value_error("You must give a positive number of points");
return;
}

if (nelem < npoints * 2) {
zend_throw_error(NULL, "Trying to use %d points in array with only %d points", npoints, nelem/2);
zend_value_error("Trying to use %d points in array with only %d points", npoints, nelem/2);
return;
}

Expand Down Expand Up @@ -3698,22 +3698,22 @@ PHP_FUNCTION(imageconvolution)

nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
if (nelem != 3) {
zend_throw_error(NULL, "Convolution matrix must be a 3x3 array");
zend_value_error("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 ) {
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)));
zend_value_error("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 {
zend_throw_error(NULL, "Convolution matrix must be a 3x3 array, matrix[%d][%d] cannot be found (missing integer key)", i, j);
zend_value_error("Convolution matrix must be a 3x3 array, matrix[%d][%d] cannot be found (missing integer key)", i, j);
return;
}
}
Expand Down Expand Up @@ -3814,28 +3814,28 @@ PHP_FUNCTION(imagecrop)
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) {
rect.x = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Cropping rectangle is missing x position");
zend_value_error("Cropping rectangle is missing x position");
return;
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
rect.y = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Cropping rectangle is missing y position");
zend_value_error("Cropping rectangle is missing y position");
return;
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
rect.width = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Cropping rectangle is missing width");
zend_value_error("Cropping rectangle is missing width");
return;
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
rect.height = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Cropping rectangle is missing height");
zend_value_error("Cropping rectangle is missing height");
return;
}

Expand Down Expand Up @@ -3879,14 +3879,14 @@ PHP_FUNCTION(imagecropauto)

case GD_CROP_THRESHOLD:
if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) {
zend_throw_error(NULL, "Color argument missing with threshold mode");
zend_value_error("Color argument missing with threshold mode");
return;
}
im_crop = gdImageCropThreshold(im, color, (float) threshold);
break;

default:
zend_throw_error(NULL, "Unknown crop mode");
zend_value_error("Unknown crop mode");
return;
}

Expand Down Expand Up @@ -3980,7 +3980,7 @@ PHP_FUNCTION(imageaffine)
}

if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
zend_throw_error(NULL, "Affine array must have six elements");
zend_value_error("Affine array must have six elements");
return;
}

Expand All @@ -4007,28 +4007,28 @@ PHP_FUNCTION(imageaffine)
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") - 1)) != NULL) {
rect.x = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Clip array is missing x position");
zend_value_error("Clip array is missing x position");
return;
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
rect.y = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Clip array is missing y position");
zend_value_error("Clip array is missing y position");
return;
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
rect.width = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Clip array is missing width");
zend_value_error("Clip array is missing width");
return;
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
rect.height = zval_get_long(tmp);
} else {
zend_throw_error(NULL, "Clip array is missing height");
zend_value_error("Clip array is missing height");
return;
}
pRect = &rect;
Expand Down Expand Up @@ -4078,14 +4078,14 @@ PHP_FUNCTION(imageaffinematrixget)
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "x", sizeof("x") - 1)) != NULL) {
x = zval_get_double(tmp);
} else {
zend_throw_error(NULL, "Options array is missing x position");
zend_value_error("Options array is missing x position");
return;
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "y", sizeof("y") - 1)) != NULL) {
y = zval_get_double(tmp);
} else {
zend_throw_error(NULL, "Options array is missing y position");
zend_value_error("Options array is missing y position");
return;
}

Expand Down Expand Up @@ -4120,7 +4120,7 @@ PHP_FUNCTION(imageaffinematrixget)
}

default:
zend_throw_error(NULL, "Invalid type for element " ZEND_LONG_FMT, type);
zend_value_error("Invalid type for element " ZEND_LONG_FMT, type);
return;
}

Expand Down Expand Up @@ -4152,7 +4152,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
}

if (((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m1))) != 6) || (nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m2))) != 6) {
zend_throw_error(NULL, "Affine arrays must have six elements");
zend_value_error("Affine arrays must have six elements");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/gd/tests/bug38212-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ trycatch_dump(
unlink($file);
?>
--EXPECT--
!! [Error] Width must be at least 1
!! [Error] Height must be at least 1
!! [ValueError] Width must be at least 1
!! [ValueError] Height must be at least 1
4 changes: 2 additions & 2 deletions ext/gd/tests/bug38212.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ trycatch_dump(
unlink($file);
?>
--EXPECT--
!! [Error] Width must be at least 1
!! [Error] Height must be at least 1
!! [ValueError] Width must be at least 1
!! [ValueError] Height must be at least 1
4 changes: 2 additions & 2 deletions ext/gd/tests/bug67248.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ for($i=0;$i<7;$i++) {
!! [TypeError] Number is expected as option when using rotate or shear
!! [TypeError] Number is expected as option when using rotate or shear
!! [TypeError] Number is expected as option when using rotate or shear
!! [Error] Invalid type for element 5
!! [Error] Invalid type for element 6
!! [ValueError] Invalid type for element 5
!! [ValueError] Invalid type for element 6
2 changes: 1 addition & 1 deletion ext/gd/tests/bug72494.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ trycatch_dump(

?>
--EXPECT--
!! [Error] Color argument missing with threshold mode
!! [ValueError] Color argument missing with threshold mode
2 changes: 1 addition & 1 deletion ext/gd/tests/bug72697.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ trycatch_dump(
?>
DONE
--EXPECT--
!! [Error] Number of colors has to be greater than zero and no more than 2147483647
!! [ValueError] Number of colors has to be greater than zero and no more than 2147483647
DONE
2 changes: 1 addition & 1 deletion ext/gd/tests/bug72730.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ trycatch_dump(

?>
--EXPECT--
!! [Error] Gamma values must be positive
!! [ValueError] Gamma values must be positive
12 changes: 6 additions & 6 deletions ext/gd/tests/imagecolorallocate_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ int(657930)
int(657930)

--Octal -012--
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)

--Octal 0377--
int(16714250)
Expand All @@ -84,9 +84,9 @@ int(657930)
int(657930)

--Hexa-decimal -0xA--
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)

--Hexa-decimal 0xFF--
int(16714250)
Expand Down
36 changes: 18 additions & 18 deletions ext/gd/tests/imagecolorallocate_variation6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ foreach($values as $key => $value) {
*** Testing imagecolorallocate() : usage variations ***

--Decimal 256--
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)

--Octal 0400--
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)

--Hexa-decimal 0x100--
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
===DONE===
2 changes: 1 addition & 1 deletion ext/gd/tests/imageconvolution_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ trycatch_dump(

?>
--EXPECT--
!! [Error] Convolution matrix must be a 3x3 array
!! [ValueError] Convolution matrix must be a 3x3 array
4 changes: 2 additions & 2 deletions ext/gd/tests/imageconvolution_error3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ trycatch_dump(

?>
--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)
!! [ValueError] Convolution matrix must be a 3x3 array, matrix[2] only has 2 elements
!! [ValueError] Convolution matrix must be a 3x3 array, matrix[2][2] cannot be found (missing integer key)
2 changes: 1 addition & 1 deletion ext/gd/tests/imagefilledpolygon_negative.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ trycatch_dump(
imagedestroy($im);
?>
--EXPECT--
!! [Error] You must give a positive number of points
!! [ValueError] You must give a positive number of points
2 changes: 1 addition & 1 deletion ext/gd/tests/imagepolygon_negative.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ trycatch_dump(
imagedestroy($im);
?>
--EXPECT--
!! [Error] You must give a positive number of points
!! [ValueError] You must give a positive number of points
2 changes: 1 addition & 1 deletion ext/gd/tests/imagetruecolortopalette_error3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ trycatch_dump(

?>
--EXPECT--
!! [Error] Number of colors has to be greater than zero and no more than 2147483647
!! [ValueError] Number of colors has to be greater than zero and no more than 2147483647
4 changes: 2 additions & 2 deletions ext/gd/tests/imagetruecolortopalette_error4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ trycatch_dump(

?>
--EXPECT--
!! [Error] Number of colors has to be greater than zero and no more than 2147483647
!! [Error] Number of colors has to be greater than zero and no more than 2147483647
!! [ValueError] Number of colors has to be greater than zero and no more than 2147483647
!! [ValueError] Number of colors has to be greater than zero and no more than 2147483647

0 comments on commit 4f40743

Please sign in to comment.