Skip to content

Commit 4f40743

Browse files
committed
Prefer ValueError over Error in GD
Cf. <#4682>.
1 parent aeaab8e commit 4f40743

15 files changed

+68
-68
lines changed

ext/gd/gd.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ PHP_FUNCTION(imagesetstyle)
798798

799799
num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles));
800800
if (num_styles == 0) {
801-
zend_throw_error(NULL, "Styles array must not be empty");
801+
zend_value_error("Styles array must not be empty");
802802
return;
803803
}
804804

@@ -885,7 +885,7 @@ PHP_FUNCTION(imagetruecolortopalette)
885885
}
886886

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

@@ -1109,7 +1109,7 @@ PHP_FUNCTION(imagelayereffect)
11091109

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

@@ -1712,12 +1712,12 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
17121712
}
17131713

17141714
if (width < 1) {
1715-
zend_throw_error(NULL, "Width must be at least 1");
1715+
zend_value_error("Width must be at least 1");
17161716
return;
17171717
}
17181718

17191719
if (height < 1) {
1720-
zend_throw_error(NULL, "Height must be at least 1");
1720+
zend_value_error("Height must be at least 1");
17211721
return;
17221722
}
17231723

@@ -2445,7 +2445,7 @@ PHP_FUNCTION(imagegammacorrect)
24452445
}
24462446

24472447
if ( input <= 0.0 || output <= 0.0 ) {
2448-
zend_throw_error(NULL, "Gamma values must be positive");
2448+
zend_value_error("Gamma values must be positive");
24492449
return;
24502450
}
24512451

@@ -2786,17 +2786,17 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
27862786

27872787
nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
27882788
if (nelem < 6) {
2789-
zend_throw_error(NULL, "You must have at least 3 points in your array");
2789+
zend_value_error("You must have at least 3 points in your array");
27902790
return;
27912791
}
27922792

27932793
if (npoints <= 0) {
2794-
zend_throw_error(NULL, "You must give a positive number of points");
2794+
zend_value_error("You must give a positive number of points");
27952795
return;
27962796
}
27972797

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

@@ -3698,22 +3698,22 @@ PHP_FUNCTION(imageconvolution)
36983698

36993699
nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
37003700
if (nelem != 3) {
3701-
zend_throw_error(NULL, "Convolution matrix must be a 3x3 array");
3701+
zend_value_error("Convolution matrix must be a 3x3 array");
37023702
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-
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)));
3708+
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)));
37093709
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-
zend_throw_error(NULL, "Convolution matrix must be a 3x3 array, matrix[%d][%d] cannot be found (missing integer key)", i, j);
3716+
zend_value_error("Convolution matrix must be a 3x3 array, matrix[%d][%d] cannot be found (missing integer key)", i, j);
37173717
return;
37183718
}
37193719
}
@@ -3814,28 +3814,28 @@ PHP_FUNCTION(imagecrop)
38143814
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) {
38153815
rect.x = zval_get_long(tmp);
38163816
} else {
3817-
zend_throw_error(NULL, "Cropping rectangle is missing x position");
3817+
zend_value_error("Cropping rectangle is missing x position");
38183818
return;
38193819
}
38203820

38213821
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
38223822
rect.y = zval_get_long(tmp);
38233823
} else {
3824-
zend_throw_error(NULL, "Cropping rectangle is missing y position");
3824+
zend_value_error("Cropping rectangle is missing y position");
38253825
return;
38263826
}
38273827

38283828
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
38293829
rect.width = zval_get_long(tmp);
38303830
} else {
3831-
zend_throw_error(NULL, "Cropping rectangle is missing width");
3831+
zend_value_error("Cropping rectangle is missing width");
38323832
return;
38333833
}
38343834

38353835
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
38363836
rect.height = zval_get_long(tmp);
38373837
} else {
3838-
zend_throw_error(NULL, "Cropping rectangle is missing height");
3838+
zend_value_error("Cropping rectangle is missing height");
38393839
return;
38403840
}
38413841

@@ -3879,14 +3879,14 @@ PHP_FUNCTION(imagecropauto)
38793879

38803880
case GD_CROP_THRESHOLD:
38813881
if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) {
3882-
zend_throw_error(NULL, "Color argument missing with threshold mode");
3882+
zend_value_error("Color argument missing with threshold mode");
38833883
return;
38843884
}
38853885
im_crop = gdImageCropThreshold(im, color, (float) threshold);
38863886
break;
38873887

38883888
default:
3889-
zend_throw_error(NULL, "Unknown crop mode");
3889+
zend_value_error("Unknown crop mode");
38903890
return;
38913891
}
38923892

@@ -3980,7 +3980,7 @@ PHP_FUNCTION(imageaffine)
39803980
}
39813981

39823982
if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
3983-
zend_throw_error(NULL, "Affine array must have six elements");
3983+
zend_value_error("Affine array must have six elements");
39843984
return;
39853985
}
39863986

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

40144014
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
40154015
rect.y = zval_get_long(tmp);
40164016
} else {
4017-
zend_throw_error(NULL, "Clip array is missing y position");
4017+
zend_value_error("Clip array is missing y position");
40184018
return;
40194019
}
40204020

40214021
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
40224022
rect.width = zval_get_long(tmp);
40234023
} else {
4024-
zend_throw_error(NULL, "Clip array is missing width");
4024+
zend_value_error("Clip array is missing width");
40254025
return;
40264026
}
40274027

40284028
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
40294029
rect.height = zval_get_long(tmp);
40304030
} else {
4031-
zend_throw_error(NULL, "Clip array is missing height");
4031+
zend_value_error("Clip array is missing height");
40324032
return;
40334033
}
40344034
pRect = &rect;
@@ -4078,14 +4078,14 @@ PHP_FUNCTION(imageaffinematrixget)
40784078
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "x", sizeof("x") - 1)) != NULL) {
40794079
x = zval_get_double(tmp);
40804080
} else {
4081-
zend_throw_error(NULL, "Options array is missing x position");
4081+
zend_value_error("Options array is missing x position");
40824082
return;
40834083
}
40844084

40854085
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "y", sizeof("y") - 1)) != NULL) {
40864086
y = zval_get_double(tmp);
40874087
} else {
4088-
zend_throw_error(NULL, "Options array is missing y position");
4088+
zend_value_error("Options array is missing y position");
40894089
return;
40904090
}
40914091

@@ -4120,7 +4120,7 @@ PHP_FUNCTION(imageaffinematrixget)
41204120
}
41214121

41224122
default:
4123-
zend_throw_error(NULL, "Invalid type for element " ZEND_LONG_FMT, type);
4123+
zend_value_error("Invalid type for element " ZEND_LONG_FMT, type);
41244124
return;
41254125
}
41264126

@@ -4152,7 +4152,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
41524152
}
41534153

41544154
if (((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m1))) != 6) || (nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m2))) != 6) {
4155-
zend_throw_error(NULL, "Affine arrays must have six elements");
4155+
zend_value_error("Affine arrays must have six elements");
41564156
return;
41574157
}
41584158

ext/gd/tests/bug38212-mb.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ trycatch_dump(
2121
unlink($file);
2222
?>
2323
--EXPECT--
24-
!! [Error] Width must be at least 1
25-
!! [Error] Height must be at least 1
24+
!! [ValueError] Width must be at least 1
25+
!! [ValueError] Height must be at least 1

ext/gd/tests/bug38212.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ trycatch_dump(
2121
unlink($file);
2222
?>
2323
--EXPECT--
24-
!! [Error] Width must be at least 1
25-
!! [Error] Height must be at least 1
24+
!! [ValueError] Width must be at least 1
25+
!! [ValueError] Height must be at least 1

ext/gd/tests/bug67248.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ for($i=0;$i<7;$i++) {
2121
!! [TypeError] Number is expected as option when using rotate or shear
2222
!! [TypeError] Number is expected as option when using rotate or shear
2323
!! [TypeError] Number is expected as option when using rotate or shear
24-
!! [Error] Invalid type for element 5
25-
!! [Error] Invalid type for element 6
24+
!! [ValueError] Invalid type for element 5
25+
!! [ValueError] Invalid type for element 6

ext/gd/tests/bug72494.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ trycatch_dump(
1616

1717
?>
1818
--EXPECT--
19-
!! [Error] Color argument missing with threshold mode
19+
!! [ValueError] Color argument missing with threshold mode

ext/gd/tests/bug72697.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ trycatch_dump(
1919
?>
2020
DONE
2121
--EXPECT--
22-
!! [Error] Number of colors has to be greater than zero and no more than 2147483647
22+
!! [ValueError] Number of colors has to be greater than zero and no more than 2147483647
2323
DONE

ext/gd/tests/bug72730.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ trycatch_dump(
1717

1818
?>
1919
--EXPECT--
20-
!! [Error] Gamma values must be positive
20+
!! [ValueError] Gamma values must be positive

ext/gd/tests/imagecolorallocate_variation5.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ int(657930)
6464
int(657930)
6565

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

7171
--Octal 0377--
7272
int(16714250)
@@ -84,9 +84,9 @@ int(657930)
8484
int(657930)
8585

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

9191
--Hexa-decimal 0xFF--
9292
int(16714250)

ext/gd/tests/imagecolorallocate_variation6.phpt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@ foreach($values as $key => $value) {
5252
*** Testing imagecolorallocate() : usage variations ***
5353

5454
--Decimal 256--
55-
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
56-
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
57-
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
58-
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
59-
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
60-
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
55+
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
56+
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
57+
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
58+
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
59+
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
60+
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
6161

6262
--Octal 0400--
63-
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
64-
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
65-
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
66-
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
67-
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
68-
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
63+
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
64+
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
65+
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
66+
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
67+
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
68+
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
6969

7070
--Hexa-decimal 0x100--
71-
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
72-
!! [Error] Red component is out of range, must be between 0 and 255 (inclusive)
73-
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
74-
!! [Error] Green component is out of range, must be between 0 and 255 (inclusive)
75-
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
76-
!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive)
71+
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
72+
!! [ValueError] Red component is out of range, must be between 0 and 255 (inclusive)
73+
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
74+
!! [ValueError] Green component is out of range, must be between 0 and 255 (inclusive)
75+
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
76+
!! [ValueError] Blue component is out of range, must be between 0 and 255 (inclusive)
7777
===DONE===

ext/gd/tests/imageconvolution_error2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ trycatch_dump(
2727

2828
?>
2929
--EXPECT--
30-
!! [Error] Convolution matrix must be a 3x3 array
30+
!! [ValueError] Convolution matrix must be a 3x3 array

0 commit comments

Comments
 (0)