]> granicus.if.org Git - php/commitdiff
Prefer ValueError over Error in GD
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 10 Sep 2019 10:36:57 +0000 (12:36 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 10 Sep 2019 10:37:42 +0000 (12:37 +0200)
Cf. <https://github.com/php/php-src/pull/4682>.

15 files changed:
ext/gd/gd.c
ext/gd/tests/bug38212-mb.phpt
ext/gd/tests/bug38212.phpt
ext/gd/tests/bug67248.phpt
ext/gd/tests/bug72494.phpt
ext/gd/tests/bug72697.phpt
ext/gd/tests/bug72730.phpt
ext/gd/tests/imagecolorallocate_variation5.phpt
ext/gd/tests/imagecolorallocate_variation6.phpt
ext/gd/tests/imageconvolution_error2.phpt
ext/gd/tests/imageconvolution_error3.phpt
ext/gd/tests/imagefilledpolygon_negative.phpt
ext/gd/tests/imagepolygon_negative.phpt
ext/gd/tests/imagetruecolortopalette_error3.phpt
ext/gd/tests/imagetruecolortopalette_error4.phpt

index 608f350c2f57607c58f41709c1bb4c3eca96ef65..4f93d62c5190dabe55c94cc1c7edad5eb2a917f2 100644 (file)
@@ -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 = &rect;
@@ -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;
        }
 
index 9275a654dbbe9e6c4162206d3d0e43294c2c70c1..d69d604e5d7863b1bf7fe9fa5b5553e2101c4e0b 100644 (file)
@@ -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
index 6d5c7e73d7243317a3356680e9c4ebbc26c8d7fd..8645989e09ee3d5f67d489d9ca89406d0ad29e09 100644 (file)
@@ -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
index 58d5d55786c225ded27818c2c2e6468f7083ff10..c9a9588343ee153420a50239b46b730dc5ed4224 100644 (file)
@@ -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
index 3a4ea08b9c1c55d3ac6a72f12630ff9aa18a7bf7..b01a19179a65fde709d64c91f8de50f954e7ee8c 100644 (file)
@@ -16,4 +16,4 @@ trycatch_dump(
 
 ?>
 --EXPECT--
-!! [Error] Color argument missing with threshold mode
+!! [ValueError] Color argument missing with threshold mode
index 5608d5f17b932570f7e91513dd7e42009893318b..2c293d14be2640bafc02374f1399a935f73a1c31 100644 (file)
@@ -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
index e3a7971565ba6bb32a7ac50011099fa5d67d452a..09b6657adda697ad4ce3150489b41fd8b1affcb4 100644 (file)
@@ -17,4 +17,4 @@ trycatch_dump(
 
 ?>
 --EXPECT--
-!! [Error] Gamma values must be positive
+!! [ValueError] Gamma values must be positive
index 7d4b94106986145d7476fc75068baf961bfb3c9f..ae6acb18f67cb78ea8df299d756fc55692cb6629 100644 (file)
@@ -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)
index 6b2eb8ba2ff6f07c1cdb53fe6b4447234d9c7852..9f21739ff1aeb8a39bd147d260be069ae8577e66 100644 (file)
@@ -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===
index d8d0ca1ab2524184acd974cf20525628cb6f86a4..d26851c26cf1969f5e9ff8948fec5cc367daceca 100644 (file)
@@ -27,4 +27,4 @@ trycatch_dump(
 
 ?>
 --EXPECT--
-!! [Error] Convolution matrix must be a 3x3 array
+!! [ValueError] Convolution matrix must be a 3x3 array
index 49aa2be9d08fb264e6c352116b0bb109d088546d..8974fdbda0f298656a3c4b3bc6efe83b3c88ab9f 100644 (file)
@@ -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)
index eae032d51e5fe69b58b03d0e529feaa7a8a5425a..165fa1c13bb300864877525624fdaf482e538b59 100644 (file)
@@ -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
index 8334589e38e1d0d3006563412b1b8dbec16d8cde..96b2e7591ee2a4f8504c9d8269d7a3e191e54027 100644 (file)
@@ -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
index 180e947b638717b143772c48af29308ace4fe8ec..40dc30611662f5e2db2d5535b4e9081d5621846f 100644 (file)
@@ -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
index ed1345e7ed16371fcbf3132ccc62f4ba150191f4..055fc657b2ba1ff99dc49788e559cf2e00d6e371 100644 (file)
@@ -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