From: Christoph M. Becker Date: Tue, 10 Sep 2019 10:36:57 +0000 (+0200) Subject: Prefer ValueError over Error in GD X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f4074328c80ee5600390cf1711f781515fce74c;p=php Prefer ValueError over Error in GD Cf. . --- diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 608f350c2f..4f93d62c51 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -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; } @@ -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; } @@ -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; \ } @@ -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; } @@ -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; } @@ -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; } @@ -3698,14 +3698,14 @@ 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; } @@ -3713,7 +3713,7 @@ PHP_FUNCTION(imageconvolution) 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; } } @@ -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; } @@ -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; } @@ -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; } @@ -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 = ▭ @@ -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; } @@ -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; } @@ -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; } diff --git a/ext/gd/tests/bug38212-mb.phpt b/ext/gd/tests/bug38212-mb.phpt index 9275a654db..d69d604e5d 100644 --- a/ext/gd/tests/bug38212-mb.phpt +++ b/ext/gd/tests/bug38212-mb.phpt @@ -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 diff --git a/ext/gd/tests/bug38212.phpt b/ext/gd/tests/bug38212.phpt index 6d5c7e73d7..8645989e09 100644 --- a/ext/gd/tests/bug38212.phpt +++ b/ext/gd/tests/bug38212.phpt @@ -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 diff --git a/ext/gd/tests/bug67248.phpt b/ext/gd/tests/bug67248.phpt index 58d5d55786..c9a9588343 100644 --- a/ext/gd/tests/bug67248.phpt +++ b/ext/gd/tests/bug67248.phpt @@ -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 diff --git a/ext/gd/tests/bug72494.phpt b/ext/gd/tests/bug72494.phpt index 3a4ea08b9c..b01a19179a 100644 --- a/ext/gd/tests/bug72494.phpt +++ b/ext/gd/tests/bug72494.phpt @@ -16,4 +16,4 @@ trycatch_dump( ?> --EXPECT-- -!! [Error] Color argument missing with threshold mode +!! [ValueError] Color argument missing with threshold mode diff --git a/ext/gd/tests/bug72697.phpt b/ext/gd/tests/bug72697.phpt index 5608d5f17b..2c293d14be 100644 --- a/ext/gd/tests/bug72697.phpt +++ b/ext/gd/tests/bug72697.phpt @@ -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 diff --git a/ext/gd/tests/bug72730.phpt b/ext/gd/tests/bug72730.phpt index e3a7971565..09b6657add 100644 --- a/ext/gd/tests/bug72730.phpt +++ b/ext/gd/tests/bug72730.phpt @@ -17,4 +17,4 @@ trycatch_dump( ?> --EXPECT-- -!! [Error] Gamma values must be positive +!! [ValueError] Gamma values must be positive diff --git a/ext/gd/tests/imagecolorallocate_variation5.phpt b/ext/gd/tests/imagecolorallocate_variation5.phpt index 7d4b941069..ae6acb18f6 100644 --- a/ext/gd/tests/imagecolorallocate_variation5.phpt +++ b/ext/gd/tests/imagecolorallocate_variation5.phpt @@ -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) @@ -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) diff --git a/ext/gd/tests/imagecolorallocate_variation6.phpt b/ext/gd/tests/imagecolorallocate_variation6.phpt index 6b2eb8ba2f..9f21739ff1 100644 --- a/ext/gd/tests/imagecolorallocate_variation6.phpt +++ b/ext/gd/tests/imagecolorallocate_variation6.phpt @@ -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=== diff --git a/ext/gd/tests/imageconvolution_error2.phpt b/ext/gd/tests/imageconvolution_error2.phpt index d8d0ca1ab2..d26851c26c 100644 --- a/ext/gd/tests/imageconvolution_error2.phpt +++ b/ext/gd/tests/imageconvolution_error2.phpt @@ -27,4 +27,4 @@ trycatch_dump( ?> --EXPECT-- -!! [Error] Convolution matrix must be a 3x3 array +!! [ValueError] Convolution matrix must be a 3x3 array diff --git a/ext/gd/tests/imageconvolution_error3.phpt b/ext/gd/tests/imageconvolution_error3.phpt index 49aa2be9d0..8974fdbda0 100644 --- a/ext/gd/tests/imageconvolution_error3.phpt +++ b/ext/gd/tests/imageconvolution_error3.phpt @@ -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) diff --git a/ext/gd/tests/imagefilledpolygon_negative.phpt b/ext/gd/tests/imagefilledpolygon_negative.phpt index eae032d51e..165fa1c13b 100644 --- a/ext/gd/tests/imagefilledpolygon_negative.phpt +++ b/ext/gd/tests/imagefilledpolygon_negative.phpt @@ -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 diff --git a/ext/gd/tests/imagepolygon_negative.phpt b/ext/gd/tests/imagepolygon_negative.phpt index 8334589e38..96b2e7591e 100644 --- a/ext/gd/tests/imagepolygon_negative.phpt +++ b/ext/gd/tests/imagepolygon_negative.phpt @@ -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 diff --git a/ext/gd/tests/imagetruecolortopalette_error3.phpt b/ext/gd/tests/imagetruecolortopalette_error3.phpt index 180e947b63..40dc306116 100644 --- a/ext/gd/tests/imagetruecolortopalette_error3.phpt +++ b/ext/gd/tests/imagetruecolortopalette_error3.phpt @@ -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 diff --git a/ext/gd/tests/imagetruecolortopalette_error4.phpt b/ext/gd/tests/imagetruecolortopalette_error4.phpt index ed1345e7ed..055fc657b2 100644 --- a/ext/gd/tests/imagetruecolortopalette_error4.phpt +++ b/ext/gd/tests/imagetruecolortopalette_error4.phpt @@ -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