Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
13 changes: 5 additions & 8 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "php.h"
#include "php_ini.h"
#include "ext/standard/head.h"
#include <math.h>
#include "SAPI.h"
#include "php_gd.h"
Expand Down Expand Up @@ -3702,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 @@ -3714,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 @@ -4035,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 @@ -4047,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
68 changes: 34 additions & 34 deletions ext/gd/gd.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,19 +496,19 @@ function imagetruecolortopalette(GdImage $image, bool $dither, int $num_colors):

function imagepalettetotruecolor(GdImage $image): bool {}

function imagecolormatch(GdImage $image1, GdImage $image2): bool {}
function imagecolormatch(GdImage $image1, GdImage $image2): true {}

function imagesetthickness(GdImage $image, int $thickness): bool {}
function imagesetthickness(GdImage $image, int $thickness): true {}

function imagefilledellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color): bool {}
function imagefilledellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color): true {}

function imagefilledarc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color, int $style): bool {}
function imagefilledarc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color, int $style): true {}

function imagealphablending(GdImage $image, bool $enable): bool {}
function imagealphablending(GdImage $image, bool $enable): true {}

function imagesavealpha(GdImage $image, bool $enable): bool {}
function imagesavealpha(GdImage $image, bool $enable): true {}

function imagelayereffect(GdImage $image, int $effect): bool {}
function imagelayereffect(GdImage $image, int $effect): true {}

function imagecolorallocatealpha(GdImage $image, int $red, int $green, int $blue, int $alpha): int|false {}

Expand All @@ -518,7 +518,7 @@ function imagecolorclosestalpha(GdImage $image, int $red, int $green, int $blue,

function imagecolorexactalpha(GdImage $image, int $red, int $green, int $blue, int $alpha): int {}

function imagecopyresampled(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height): bool {}
function imagecopyresampled(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height): true {}

#ifdef PHP_WIN32

Expand All @@ -533,9 +533,9 @@ function imagegrabscreen(): GdImage|false {}
/** @refcount 1 */
function imagerotate(GdImage $image, float $angle, int $background_color): GdImage|false {}

function imagesettile(GdImage $image, GdImage $tile): bool {}
function imagesettile(GdImage $image, GdImage $tile): true {}

function imagesetbrush(GdImage $image, GdImage $brush): bool {}
function imagesetbrush(GdImage $image, GdImage $brush): true {}

/** @refcount 1 */
function imagecreate(int $width, int $height): GdImage|false {}
Expand Down Expand Up @@ -635,7 +635,7 @@ function imagegd2(GdImage $image, ?string $file = null, int $chunk_size = 128, i
function imagebmp(GdImage $image, $file = null, bool $compressed = true): bool {}
#endif

function imagedestroy(GdImage $image): bool {}
function imagedestroy(GdImage $image): true {}

function imagecolorallocate(GdImage $image, int $red, int $green, int $blue): int|false {}

Expand All @@ -647,7 +647,7 @@ function imagecolorclosest(GdImage $image, int $red, int $green, int $blue): int

function imagecolorclosesthwb(GdImage $image, int $red, int $green, int $blue): int {}

function imagecolordeallocate(GdImage $image, int $color): bool {}
function imagecolordeallocate(GdImage $image, int $color): true {}

function imagecolorresolve(GdImage $image, int $red, int $green, int $blue): int {}

Expand All @@ -661,25 +661,25 @@ function imagecolorset(GdImage $image, int $color, int $red, int $green, int $bl
*/
function imagecolorsforindex(GdImage $image, int $color): array {}

function imagegammacorrect(GdImage $image, float $input_gamma, float $output_gamma): bool {}
function imagegammacorrect(GdImage $image, float $input_gamma, float $output_gamma): true {}

function imagesetpixel(GdImage $image, int $x, int $y, int $color): bool {}
function imagesetpixel(GdImage $image, int $x, int $y, int $color): true {}

function imageline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): bool {}
function imageline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): true {}

function imagedashedline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): bool {}
function imagedashedline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): true {}

function imagerectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): bool {}
function imagerectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): true {}

function imagefilledrectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): bool {}
function imagefilledrectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color): true {}

function imagearc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color): bool {}
function imagearc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color): true {}

function imageellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color): bool {}
function imageellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color): true {}

function imagefilltoborder(GdImage $image, int $x, int $y, int $border_color, int $color): bool {}
function imagefilltoborder(GdImage $image, int $x, int $y, int $border_color, int $color): true {}

function imagefill(GdImage $image, int $x, int $y, int $color): bool {}
function imagefill(GdImage $image, int $x, int $y, int $color): true {}

function imagecolorstotal(GdImage $image): int {}

Expand All @@ -697,27 +697,27 @@ function imagefontwidth(GdFont|int $font): int {}

function imagefontheight(GdFont|int $font): int {}

function imagechar(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color): bool {}
function imagechar(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color): true {}

function imagecharup(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color): bool {}
function imagecharup(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color): true {}

function imagestring(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color): bool {}
function imagestring(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color): true {}

function imagestringup(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color): bool {}
function imagestringup(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color): true {}

function imagecopy(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height): bool {}
function imagecopy(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height): true {}

function imagecopymerge(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct): bool {}
function imagecopymerge(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct): true {}

function imagecopymergegray(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct): bool {}
function imagecopymergegray(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct): true {}

function imagecopyresized(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height): bool {}
function imagecopyresized(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height): true {}

function imagesx(GdImage $image): int {}

function imagesy(GdImage $image): int {}

function imagesetclip(GdImage $image, int $x1, int $y1, int $x2, int $y2): bool {}
function imagesetclip(GdImage $image, int $x1, int $y1, int $x2, int $y2): true {}

/**
* @return array<int, int>
Expand Down Expand Up @@ -756,9 +756,9 @@ function imagefilter(GdImage $image, int $filter, ...$args): bool {}

function imageconvolution(GdImage $image, array $matrix, float $divisor, float $offset): bool {}

function imageflip(GdImage $image, int $mode): bool {}
function imageflip(GdImage $image, int $mode): true {}

function imageantialias(GdImage $image, bool $enable): bool {}
function imageantialias(GdImage $image, bool $enable): true {}

/** @refcount 1 */
function imagecrop(GdImage $image, array $rectangle): GdImage|false {}
Expand Down Expand Up @@ -793,4 +793,4 @@ function imagesetinterpolation(GdImage $image, int $method = IMG_BILINEAR_FIXED)
* @return array<int, int>|true
* @refcount 1
*/
function imageresolution(GdImage $image, ?int $resolution_x = null, ?int $resolution_y = null): array|bool {}
function imageresolution(GdImage $image, ?int $resolution_x = null, ?int $resolution_y = null): array|true {}
Loading