Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3701,7 +3701,7 @@ PHP_FUNCTION(imageconvolution)
zval *var = NULL, *var2 = NULL;
gdImagePtr im_src = NULL;
double div, offset;
int nelem, i, j, res;
int i, j, res;
float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};

ZEND_PARSE_PARAMETERS_START(4, 4)
Expand All @@ -3713,8 +3713,7 @@ PHP_FUNCTION(imageconvolution)

im_src = php_gd_libgdimageptr_from_zval_p(SIM);

nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
if (nelem != 3) {
if (zend_hash_num_elements(Z_ARRVAL_P(hash_matrix)) != 3) {
zend_argument_value_error(2, "must be a 3x3 array");
RETURN_THROWS();
}
Expand Down Expand Up @@ -4034,7 +4033,6 @@ PHP_FUNCTION(imageaffine)
zval *z_affine;
zval *tmp;
double affine[6];
int i, nelems;
zval *zval_affine_elem = NULL;

ZEND_PARSE_PARAMETERS_START(2, 3)
Expand All @@ -4046,13 +4044,13 @@ PHP_FUNCTION(imageaffine)


src = php_gd_libgdimageptr_from_zval_p(IM);

if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
uint32_t nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine));
if (nelems != 6) {
zend_argument_value_error(2, "must have 6 elements");
RETURN_THROWS();
}

for (i = 0; i < nelems; i++) {
for (uint32_t i = 0; i < nelems; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good so far, I think you can do the same stripping down you did above, i.e. we want 6 elements from the matrix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason I use uint32_t here is that we are comparing it to nelems which is a uint32_t

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant more something like

for (uint32_t i = 0; i < 6; i ++) ..

to save the variable like you did above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I did this, (in a follow-up commit from the one you reviewed?)

if ((zval_affine_elem = zend_hash_index_find_deref(Z_ARRVAL_P(z_affine), i)) != NULL) {
switch (Z_TYPE_P(zval_affine_elem)) {
case IS_LONG:
Expand Down