Skip to content

Commit a7785e8

Browse files
authored
Simplify parsing of affine matrix arguments (GH-17094)
This code repetition is prone to errors and makes the code harder to read than necessary. We simplify at the cost of making parsing of ints slightly less performant (what should not really matter in practice).
1 parent 85f69a7 commit a7785e8

File tree

1 file changed

+0
-20
lines changed

1 file changed

+0
-20
lines changed

ext/gd/gd.c

-20
Original file line numberDiff line numberDiff line change
@@ -4017,19 +4017,7 @@ PHP_FUNCTION(imageaffine)
40174017
if ((zval_affine_elem = zend_hash_index_find(Z_ARRVAL_P(z_affine), i)) != NULL) {
40184018
switch (Z_TYPE_P(zval_affine_elem)) {
40194019
case IS_LONG:
4020-
affine[i] = Z_LVAL_P(zval_affine_elem);
4021-
if (affine[i] < INT_MIN || affine[i] > INT_MAX) {
4022-
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
4023-
RETURN_THROWS();
4024-
}
4025-
break;
40264020
case IS_DOUBLE:
4027-
affine[i] = Z_DVAL_P(zval_affine_elem);
4028-
if (affine[i] < INT_MIN || affine[i] > INT_MAX) {
4029-
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
4030-
RETURN_THROWS();
4031-
}
4032-
break;
40334021
case IS_STRING:
40344022
affine[i] = zval_get_double(zval_affine_elem);
40354023
if (affine[i] < INT_MIN || affine[i] > INT_MAX) {
@@ -4195,11 +4183,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
41954183
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(z_m1), i)) != NULL) {
41964184
switch (Z_TYPE_P(tmp)) {
41974185
case IS_LONG:
4198-
m1[i] = Z_LVAL_P(tmp);
4199-
break;
42004186
case IS_DOUBLE:
4201-
m1[i] = Z_DVAL_P(tmp);
4202-
break;
42034187
case IS_STRING:
42044188
m1[i] = zval_get_double(tmp);
42054189
break;
@@ -4212,11 +4196,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
42124196
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(z_m2), i)) != NULL) {
42134197
switch (Z_TYPE_P(tmp)) {
42144198
case IS_LONG:
4215-
m2[i] = Z_LVAL_P(tmp);
4216-
break;
42174199
case IS_DOUBLE:
4218-
m2[i] = Z_DVAL_P(tmp);
4219-
break;
42204200
case IS_STRING:
42214201
m2[i] = zval_get_double(tmp);
42224202
break;

0 commit comments

Comments
 (0)