Skip to content

Commit 45efdac

Browse files
committed
Fix UNKNOWN default values in ext/mbstring and ext/gd
1 parent 19bf66a commit 45efdac

File tree

9 files changed

+226
-230
lines changed

9 files changed

+226
-230
lines changed

ext/gd/gd.c

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,18 +1948,17 @@ PHP_FUNCTION(imagewbmp)
19481948
zval *imgind;
19491949
zend_long foreground_color = -1;
19501950
gdImagePtr im;
1951-
int argc = ZEND_NUM_ARGS();
19521951
int i;
19531952
gdIOCtx *ctx = NULL;
19541953
zval *to_zval = NULL;
19551954

1956-
if (zend_parse_parameters(argc, "O|z!l", &imgind, gd_image_ce, &to_zval, &foreground_color) == FAILURE) {
1955+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!l", &imgind, gd_image_ce, &to_zval, &foreground_color) == FAILURE) {
19571956
RETURN_THROWS();
19581957
}
19591958

19601959
im = php_gd_libgdimageptr_from_zval_p(imgind);
19611960

1962-
if (argc > 1 && to_zval != NULL) {
1961+
if (to_zval != NULL) {
19631962
ctx = create_stream_context_from_zval(to_zval);
19641963
if (!ctx) {
19651964
RETURN_FALSE;
@@ -1968,10 +1967,11 @@ PHP_FUNCTION(imagewbmp)
19681967
ctx = create_output_context();
19691968
}
19701969

1971-
if (argc < 3) {
1970+
if (foreground_color == -1) {
19721971
for (i=0; i < gdImageColorsTotal(im); i++) {
1973-
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i))
1972+
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) {
19741973
break;
1974+
}
19751975
}
19761976

19771977
foreground_color = i;
@@ -2006,17 +2006,16 @@ PHP_FUNCTION(imagebmp)
20062006
zval *imgind;
20072007
zend_bool compressed = 1;
20082008
gdImagePtr im;
2009-
int argc = ZEND_NUM_ARGS();
20102009
gdIOCtx *ctx = NULL;
20112010
zval *to_zval = NULL;
20122011

2013-
if (zend_parse_parameters(argc, "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) {
2012+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) {
20142013
RETURN_THROWS();
20152014
}
20162015

20172016
im = php_gd_libgdimageptr_from_zval_p(imgind);
20182017

2019-
if (argc > 1 && to_zval != NULL) {
2018+
if (to_zval != NULL) {
20202019
ctx = create_stream_context_from_zval(to_zval);
20212020
if (!ctx) {
20222021
RETURN_FALSE;
@@ -2555,16 +2554,16 @@ PHP_FUNCTION(imagecolortransparent)
25552554
{
25562555
zval *IM;
25572556
zend_long COL = 0;
2557+
zend_bool COL_IS_NULL = 1;
25582558
gdImagePtr im;
2559-
int argc = ZEND_NUM_ARGS();
25602559

2561-
if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &COL) == FAILURE) {
2560+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &IM, gd_image_ce, &COL, &COL_IS_NULL) == FAILURE) {
25622561
RETURN_THROWS();
25632562
}
25642563

25652564
im = php_gd_libgdimageptr_from_zval_p(IM);
25662565

2567-
if (argc > 1) {
2566+
if (!COL_IS_NULL) {
25682567
gdImageColorTransparent(im, COL);
25692568
}
25702569

@@ -2576,17 +2575,17 @@ PHP_FUNCTION(imagecolortransparent)
25762575
PHP_FUNCTION(imageinterlace)
25772576
{
25782577
zval *IM;
2579-
int argc = ZEND_NUM_ARGS();
25802578
zend_long INT = 0;
2579+
zend_bool INT_IS_NULL = 1;
25812580
gdImagePtr im;
25822581

2583-
if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &INT) == FAILURE) {
2582+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &IM, gd_image_ce, &INT, &INT_IS_NULL) == FAILURE) {
25842583
RETURN_THROWS();
25852584
}
25862585

25872586
im = php_gd_libgdimageptr_from_zval_p(IM);
25882587

2589-
if (argc > 1) {
2588+
if (!INT_IS_NULL) {
25902589
gdImageInterlace(im, INT);
25912590
}
25922591

@@ -2603,15 +2602,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
26032602
{
26042603
zval *IM, *POINTS;
26052604
zend_long NPOINTS, COL;
2605+
zend_bool COL_IS_NULL = 1;
26062606
zval *var = NULL;
26072607
gdImagePtr im;
26082608
gdPointPtr points;
26092609
int npoints, col, nelem, i;
26102610

2611-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oal|l", &IM, gd_image_ce, &POINTS, &NPOINTS, &COL) == FAILURE) {
2611+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oal|l!", &IM, gd_image_ce, &POINTS, &NPOINTS, &COL, &COL_IS_NULL) == FAILURE) {
26122612
RETURN_THROWS();
26132613
}
2614-
if (ZEND_NUM_ARGS() == 3) {
2614+
if (COL_IS_NULL) {
26152615
COL = NPOINTS;
26162616
NPOINTS = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
26172617
if (NPOINTS % 2 != 0) {
@@ -3733,7 +3733,7 @@ PHP_FUNCTION(imageaffine)
37333733
int i, nelems;
37343734
zval *zval_affine_elem = NULL;
37353735

3736-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|a", &IM, gd_image_ce, &z_affine, &z_rect) == FAILURE) {
3736+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|a!", &IM, gd_image_ce, &z_affine, &z_rect) == FAILURE) {
37373737
RETURN_THROWS();
37383738
}
37393739

@@ -3856,7 +3856,7 @@ PHP_FUNCTION(imageaffinematrixget)
38563856
double angle;
38573857

38583858
if (!options) {
3859-
zend_argument_type_error(2, "must be of type int|double when using rotate or shear");
3859+
zend_argument_type_error(2, "must be of type int|float when using rotate or shear");
38603860
RETURN_THROWS();
38613861
}
38623862

@@ -4003,26 +4003,29 @@ PHP_FUNCTION(imageresolution)
40034003
{
40044004
zval *IM;
40054005
gdImagePtr im;
4006-
zend_long res_x = GD_RESOLUTION, res_y = GD_RESOLUTION;
4006+
zend_long res_x, res_y;
4007+
zend_bool res_x_is_null = 1, res_y_is_null = 1;
40074008

4008-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ll", &IM, gd_image_ce, &res_x, &res_y) == FAILURE) {
4009+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!l!", &IM, gd_image_ce, &res_x, &res_x_is_null, &res_y, &res_y_is_null) == FAILURE) {
40094010
RETURN_THROWS();
40104011
}
40114012

40124013
im = php_gd_libgdimageptr_from_zval_p(IM);
40134014

4014-
switch (ZEND_NUM_ARGS()) {
4015-
case 3:
4016-
gdImageSetResolution(im, res_x, res_y);
4017-
RETURN_TRUE;
4018-
case 2:
4019-
gdImageSetResolution(im, res_x, res_x);
4020-
RETURN_TRUE;
4021-
default:
4022-
array_init(return_value);
4023-
add_next_index_long(return_value, gdImageResolutionX(im));
4024-
add_next_index_long(return_value, gdImageResolutionY(im));
4015+
if (!res_x_is_null && !res_y_is_null) {
4016+
gdImageSetResolution(im, res_x, res_y);
4017+
RETURN_TRUE;
4018+
} else if (!res_x_is_null && res_y_is_null) {
4019+
gdImageSetResolution(im, res_x, res_x);
4020+
RETURN_TRUE;
4021+
} else if (res_x_is_null && !res_y_is_null) {
4022+
gdImageSetResolution(im, res_y, res_y);
4023+
RETURN_TRUE;
40254024
}
4025+
4026+
array_init(return_value);
4027+
add_next_index_long(return_value, gdImageResolutionX(im));
4028+
add_next_index_long(return_value, gdImageResolutionY(im));
40264029
}
40274030
/* }}} */
40284031

@@ -4156,7 +4159,11 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41564159
gdIOCtx *ctx = NULL;
41574160
zval *to_zval = NULL;
41584161

4159-
if (image_type == PHP_GDIMG_TYPE_PNG) {
4162+
if (image_type == PHP_GDIMG_TYPE_GIF) {
4163+
if (zend_parse_parameters(argc, "O|z", &imgind, gd_image_ce, &to_zval) == FAILURE) {
4164+
RETURN_THROWS();
4165+
}
4166+
} else if (image_type == PHP_GDIMG_TYPE_PNG) {
41604167
if (zend_parse_parameters(argc, "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &basefilter) == FAILURE) {
41614168
RETURN_THROWS();
41624169
}
@@ -4168,7 +4175,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41684175

41694176
im = php_gd_libgdimageptr_from_zval_p(imgind);
41704177

4171-
if (argc > 1 && to_zval != NULL) {
4178+
if (to_zval != NULL) {
41724179
ctx = create_stream_context_from_zval(to_zval);
41734180
if (!ctx) {
41744181
RETURN_FALSE;
@@ -4191,7 +4198,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41914198
(*func_p)(im, ctx, (int) quality, (int) basefilter);
41924199
break;
41934200
case PHP_GDIMG_TYPE_WBM:
4194-
if (argc < 3) {
4201+
if (quality == -1) {
41954202
for (i=0; i < gdImageColorsTotal(im); i++) {
41964203
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
41974204
}

ext/gd/gd.stub.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function gd_info(): array {}
1010

1111
function imageloadfont(string $filename): int|false {}
1212

13-
function imagesetstyle($im, array $styles): bool {}
13+
function imagesetstyle(GdImage $im, array $styles): bool {}
1414

1515
function imagecreatetruecolor(int $x_size, int $y_size): GdImage|false {}
1616

@@ -20,7 +20,7 @@ function imagetruecolortopalette(GdImage $im, bool $ditherFlag, int $colorWanted
2020

2121
function imagepalettetotruecolor(GdImage $im): bool {}
2222

23-
function imagecolormatch($im1, $im2): bool {}
23+
function imagecolormatch(GdImage $im1, GdImage $im2): bool {}
2424

2525
function imagesetthickness(GdImage $im, int $thickness): bool {}
2626

@@ -54,9 +54,9 @@ function imagegrabscreen(): GdImage|false {}
5454

5555
function imagerotate(GdImage $im, float $angle, int $bgdcolor, int $ignoretransparent = 0): GdImage|false {}
5656

57-
function imagesettile(GdImage $im, $tile): bool {}
57+
function imagesettile(GdImage $im, GdImage $tile): bool {}
5858

59-
function imagesetbrush(GdImage $im, $brush): bool {}
59+
function imagesetbrush(GdImage $im, GdImage $brush): bool {}
6060

6161
function imagecreate(int $x_size, int $y_size): GdImage|false {}
6262

@@ -100,30 +100,36 @@ function imagecreatefrombmp(string $filename): GdImage|false {}
100100
function imagecreatefromtga(string $filename): GdImage|false {}
101101
#endif
102102

103-
function imagexbm(GdImage $im, ?string $filename, int $foreground = UNKNOWN): bool {}
103+
function imagexbm(GdImage $im, ?string $filename, int $foreground = -1): bool {}
104104

105+
/** @param resource|string|null $to */
105106
function imagegif(GdImage $im, $to = null): bool {}
106107

107108
#ifdef HAVE_GD_PNG
108-
function imagepng(GdImage $im, $to = null, int $quality = UNKNOWN, int $filters = UNKNOWN): bool {}
109+
/** @param resource|string|null $to */
110+
function imagepng(GdImage $im, $to = null, int $quality = -1, int $filters = -1): bool {}
109111
#endif
110112

111113
#ifdef HAVE_GD_WEBP
112-
function imagewebp(GdImage $im, $to = null, int $quality = UNKNOWN): bool {}
114+
/** @param resource|string|null $to */
115+
function imagewebp(GdImage $im, $to = null, int $quality = -1): bool {}
113116
#endif
114117

115118
#ifdef HAVE_GD_JPG
116-
function imagejpeg(GdImage $im, $to = null, int $quality = UNKNOWN): bool {}
119+
/** @param resource|string|null $to */
120+
function imagejpeg(GdImage $im, $to = null, int $quality = -1): bool {}
117121
#endif
118122

119-
function imagewbmp(GdImage $im, $to = null, int $foreground = UNKNOWN): bool {}
123+
/** @param resource|string|null $to */
124+
function imagewbmp(GdImage $im, $to = null, int $foreground = -1): bool {}
120125

121126
function imagegd(GdImage $im, $to = UNKNOWN): bool {}
122127

123128
function imagegd2(GdImage $im, $to = UNKNOWN, int $chunk_size = UNKNOWN, int $type = UNKNOWN): bool {}
124129

125130
#ifdef HAVE_GD_BMP
126-
function imagebmp(GdImage $im, $to = null, int $compressed = 1): bool {}
131+
/** @param resource|string|null $to */
132+
function imagebmp(GdImage $im, $to = null, bool $compressed = true): bool {}
127133
#endif
128134

129135
function imagedestroy(GdImage $im): bool {}
@@ -170,15 +176,15 @@ function imagefill(GdImage $im, int $x, int $y, int $col): bool {}
170176

171177
function imagecolorstotal(GdImage $im): int {}
172178

173-
function imagecolortransparent(GdImage $im, int $col = UNKNOWN): ?int {}
179+
function imagecolortransparent(GdImage $im, ?int $col = null): ?int {}
174180

175-
function imageinterlace(GdImage $im, int $interlace = UNKNOWN): ?int {}
181+
function imageinterlace(GdImage $im, ?int $interlace = null): ?int {}
176182

177-
function imagepolygon(GdImage $im, array $points, int $num_points_or_col, int $col = UNKNOWN): bool {}
183+
function imagepolygon(GdImage $im, array $points, int $num_points_or_col, ?int $col = null): bool {}
178184

179-
function imageopenpolygon(GdImage $im, array $points, int $num_points_or_col, int $col = UNKNOWN): bool {}
185+
function imageopenpolygon(GdImage $im, array $points, int $num_points_or_col, ?int $col = null): bool {}
180186

181-
function imagefilledpolygon(GdImage $im, array $points, int $num_points_or_col, int $col = UNKNOWN): bool {}
187+
function imagefilledpolygon(GdImage $im, array $points, int $num_points_or_col, ?int $col = null): bool {}
182188

183189
function imagefontwidth(int $font): int {}
184190

@@ -230,10 +236,11 @@ function imagecrop(GdImage $im, array $rect): GdImage|false {}
230236

231237
function imagecropauto(GdImage $im, int $mode = IMG_CROP_DEFAULT, float $threshold = 0.5, int $color = -1): GdImage|false {}
232238

233-
function imagescale(GdImage $im, int $new_width, int $new_height = UNKNOWN, int $mode = IMG_BILINEAR_FIXED): GdImage|false {}
239+
function imagescale(GdImage $im, int $new_width, int $new_height = -1, int $mode = IMG_BILINEAR_FIXED): GdImage|false {}
234240

235-
function imageaffine(GdImage $im, array $affine, array $clip = UNKNOWN): GdImage|false {}
241+
function imageaffine(GdImage $im, array $affine, ?array $clip = null): GdImage|false {}
236242

243+
/** @param array|int|float $options */
237244
function imageaffinematrixget(int $type, $options = UNKNOWN): array|false {}
238245

239246
function imageaffinematrixconcat(array $m1, array $m2): array|false {}
@@ -242,4 +249,4 @@ function imagegetinterpolation(GdImage $im): int {}
242249

243250
function imagesetinterpolation(GdImage $im, int $method = IMG_BILINEAR_FIXED): bool {}
244251

245-
function imageresolution(GdImage $im, int $res_x = UNKNOWN, int $res_y = UNKNOWN): array|bool {}
252+
function imageresolution(GdImage $im, ?int $res_x = null, ?int $res_y = null): array|bool {}

0 commit comments

Comments
 (0)