Skip to content

Commit f35ac99

Browse files
committed
Fix UNKNOWN default values in ext/xml-rpc, ext/mbstring, and ext/gd
1 parent d377467 commit f35ac99

File tree

12 files changed

+222
-203
lines changed

12 files changed

+222
-203
lines changed

ext/gd/gd.c

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ typedef struct _gd_ext_image_object {
155155

156156
static zend_object_handlers php_gd_image_object_handlers;
157157

158-
static const zend_function_entry gd_image_object_methods[] = {
159-
PHP_FE_END
160-
};
161-
162158
static zend_function *php_gd_image_object_get_constructor(zend_object *object)
163159
{
164160
zend_throw_error(NULL, "You cannot initialize a GdImage object except through helper functions");
@@ -221,7 +217,7 @@ void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image)
221217
static void php_gd_object_minit_helper()
222218
{
223219
zend_class_entry ce;
224-
INIT_CLASS_ENTRY(ce, "GdImage", gd_image_object_methods);
220+
INIT_CLASS_ENTRY(ce, "GdImage", class_GdImage_methods);
225221
gd_image_ce = zend_register_internal_class(&ce);
226222
gd_image_ce->ce_flags |= ZEND_ACC_FINAL;
227223
gd_image_ce->create_object = php_gd_image_object_create;
@@ -2542,16 +2538,17 @@ PHP_FUNCTION(imagecolortransparent)
25422538
{
25432539
zval *IM;
25442540
zend_long COL = 0;
2541+
zend_bool COL_IS_NULL = 1;
25452542
gdImagePtr im;
25462543
int argc = ZEND_NUM_ARGS();
25472544

2548-
if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &COL) == FAILURE) {
2545+
if (zend_parse_parameters(argc, "O|l!", &IM, gd_image_ce, &COL, &COL_IS_NULL) == FAILURE) {
25492546
RETURN_THROWS();
25502547
}
25512548

25522549
im = php_gd_libgdimageptr_from_zval_p(IM);
25532550

2554-
if (argc > 1) {
2551+
if (!COL_IS_NULL) {
25552552
gdImageColorTransparent(im, COL);
25562553
}
25572554

@@ -2566,15 +2563,16 @@ PHP_FUNCTION(imageinterlace)
25662563
zval *IM;
25672564
int argc = ZEND_NUM_ARGS();
25682565
zend_long INT = 0;
2566+
zend_bool INT_IS_NULL = 1;
25692567
gdImagePtr im;
25702568

2571-
if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &INT) == FAILURE) {
2569+
if (zend_parse_parameters(argc, "O|l!", &IM, gd_image_ce, &INT, &INT_IS_NULL) == FAILURE) {
25722570
RETURN_THROWS();
25732571
}
25742572

25752573
im = php_gd_libgdimageptr_from_zval_p(IM);
25762574

2577-
if (argc > 1) {
2575+
if (!INT_IS_NULL) {
25782576
gdImageInterlace(im, INT);
25792577
}
25802578

@@ -2591,15 +2589,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
25912589
{
25922590
zval *IM, *POINTS;
25932591
zend_long NPOINTS, COL;
2592+
zend_bool COL_IS_NULL = 1;
25942593
zval *var = NULL;
25952594
gdImagePtr im;
25962595
gdPointPtr points;
25972596
int npoints, col, nelem, i;
25982597

2599-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oal|l", &IM, gd_image_ce, &POINTS, &NPOINTS, &COL) == FAILURE) {
2598+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oal|l!", &IM, gd_image_ce, &POINTS, &NPOINTS, &COL, &COL_IS_NULL) == FAILURE) {
26002599
RETURN_THROWS();
26012600
}
2602-
if (ZEND_NUM_ARGS() == 3) {
2601+
if (COL_IS_NULL) {
26032602
COL = NPOINTS;
26042603
NPOINTS = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
26052604
if (NPOINTS % 2 != 0) {
@@ -3752,7 +3751,7 @@ PHP_FUNCTION(imageaffine)
37523751
int i, nelems;
37533752
zval *zval_affine_elem = NULL;
37543753

3755-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|a", &IM, gd_image_ce, &z_affine, &z_rect) == FAILURE) {
3754+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|a!", &IM, gd_image_ce, &z_affine, &z_rect) == FAILURE) {
37563755
RETURN_THROWS();
37573756
}
37583757

@@ -3876,7 +3875,7 @@ PHP_FUNCTION(imageaffinematrixget)
38763875
double angle;
38773876

38783877
if (!options) {
3879-
zend_argument_type_error(2, "must be of type int|double when using rotate or shear");
3878+
zend_argument_type_error(2, "must be of type int|float when using rotate or shear");
38803879
RETURN_THROWS();
38813880
}
38823881

@@ -4027,26 +4026,26 @@ PHP_FUNCTION(imageresolution)
40274026
{
40284027
zval *IM;
40294028
gdImagePtr im;
4030-
zend_long res_x = GD_RESOLUTION, res_y = GD_RESOLUTION;
4029+
zend_long res_x, res_y;
4030+
zend_bool res_x_is_null = 1, res_y_is_null = 1;
40314031

4032-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ll", &IM, gd_image_ce, &res_x, &res_y) == FAILURE) {
4032+
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) {
40334033
RETURN_THROWS();
40344034
}
40354035

40364036
im = php_gd_libgdimageptr_from_zval_p(IM);
40374037

4038-
switch (ZEND_NUM_ARGS()) {
4039-
case 3:
4040-
gdImageSetResolution(im, res_x, res_y);
4041-
RETURN_TRUE;
4042-
case 2:
4043-
gdImageSetResolution(im, res_x, res_x);
4044-
RETURN_TRUE;
4045-
default:
4046-
array_init(return_value);
4047-
add_next_index_long(return_value, gdImageResolutionX(im));
4048-
add_next_index_long(return_value, gdImageResolutionY(im));
4038+
if (!res_x_is_null && !res_y_is_null) {
4039+
gdImageSetResolution(im, res_x, res_y);
4040+
RETURN_TRUE;
4041+
} else if (!res_x_is_null && res_y_is_null) {
4042+
gdImageSetResolution(im, res_x, res_x);
4043+
RETURN_TRUE;
40494044
}
4045+
4046+
array_init(return_value);
4047+
add_next_index_long(return_value, gdImageResolutionX(im));
4048+
add_next_index_long(return_value, gdImageResolutionY(im));
40504049
}
40514050
/* }}} */
40524051

@@ -4124,9 +4123,8 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41244123
char *file = NULL;
41254124
size_t file_len = 0;
41264125
zend_long quality, basefilter;
4127-
zend_bool compressed = 1;
4126+
zend_bool compressed = 1, quality_is_null = 1, basefilter_is_null = 1;
41284127
gdImagePtr im;
4129-
int argc = ZEND_NUM_ARGS();
41304128
int q = -1, i;
41314129
int f = -1;
41324130
gdIOCtx *ctx = NULL;
@@ -4139,12 +4137,14 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41394137
*/
41404138
switch (image_type) {
41414139
case PHP_GDIMG_TYPE_XBM:
4142-
if (zend_parse_parameters(argc, "Op!|ll", &imgind, gd_image_ce, &file, &file_len, &quality, &basefilter) == FAILURE) {
4140+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op!|l!l!",
4141+
&imgind, gd_image_ce, &file, &file_len, &quality, &quality_is_null, &basefilter, &basefilter_is_null
4142+
) == FAILURE) {
41434143
RETURN_THROWS();
41444144
}
41454145
break;
41464146
case PHP_GDIMG_TYPE_BMP:
4147-
if (zend_parse_parameters(argc, "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) {
4147+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) {
41484148
RETURN_THROWS();
41494149
}
41504150
break;
@@ -4155,21 +4155,26 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41554155
* PHP_GDIMG_TYPE_WBM
41564156
* PHP_GDIMG_TYPE_WEBP
41574157
* */
4158-
if (zend_parse_parameters(argc, "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &basefilter) == FAILURE) {
4158+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!l!l!",
4159+
&imgind, gd_image_ce, &to_zval, &quality, &quality_is_null, &basefilter, &basefilter_is_null
4160+
) == FAILURE) {
41594161
RETURN_THROWS();
41604162
}
41614163
}
41624164

41634165
im = php_gd_libgdimageptr_from_zval_p(imgind);
41644166

4165-
if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3) {
4166-
q = quality; /* or colorindex for foreground of BW images (defaults to black) */
4167-
if (argc == 4) {
4167+
if (image_type != PHP_GDIMG_TYPE_BMP) {
4168+
if (!quality_is_null) {
4169+
q = quality; /* or colorindex for foreground of BW images (defaults to black) */
4170+
}
4171+
4172+
if (!basefilter_is_null) {
41684173
f = basefilter;
41694174
}
41704175
}
41714176

4172-
if (argc > 1 && to_zval != NULL) {
4177+
if (to_zval != NULL) {
41734178
if (Z_TYPE_P(to_zval) == IS_RESOURCE) {
41744179
php_stream_from_zval_no_verify(stream, to_zval);
41754180
if (stream == NULL) {
@@ -4190,7 +4195,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41904195
php_error_docref(NULL, E_WARNING, "Invalid 2nd parameter, it must a filename or a stream");
41914196
RETURN_FALSE;
41924197
}
4193-
} else if (argc > 1 && file != NULL) {
4198+
} else if (file != NULL) {
41944199
stream = php_stream_open_wrapper(file, "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
41954200
if (stream == NULL) {
41964201
RETURN_FALSE;
@@ -4229,7 +4234,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
42294234
break;
42304235
case PHP_GDIMG_TYPE_XBM:
42314236
case PHP_GDIMG_TYPE_WBM:
4232-
if (argc < 3) {
4237+
if (quality_is_null) {
42334238
for(i=0; i < gdImageColorsTotal(im); i++) {
42344239
if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
42354240
}

ext/gd/gd.stub.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
/** @generate-function-entries */
44

5+
final class GdImage
6+
{
7+
}
8+
59
function gd_info(): array {}
610

711
function imageloadfont(string $filename): int|false {}
@@ -96,30 +100,30 @@ function imagecreatefrombmp(string $filename): GdImage|false {}
96100
function imagecreatefromtga(string $filename): GdImage|false {}
97101
#endif
98102

99-
function imagexbm(GdImage $im, ?string $filename, int $foreground = UNKNOWN): bool {}
103+
function imagexbm(GdImage $im, ?string $filename, ?int $foreground = null, ?int $filters = null): bool {}
100104

101105
function imagegif(GdImage $im, $to = null): bool {}
102106

103107
#ifdef HAVE_GD_PNG
104-
function imagepng(GdImage $im, $to = null, int $quality = UNKNOWN, int $filters = UNKNOWN): bool {}
108+
function imagepng(GdImage $im, $to = null, ?int $quality = null, ?int $filters = null): bool {}
105109
#endif
106110

107111
#ifdef HAVE_GD_WEBP
108-
function imagewebp(GdImage $im, $to = null, int $quality = UNKNOWN): bool {}
112+
function imagewebp(GdImage $im, $to = null, ?int $quality = null, ?int $filters = null): bool {}
109113
#endif
110114

111115
#ifdef HAVE_GD_JPG
112-
function imagejpeg(GdImage $im, $to = null, int $quality = UNKNOWN): bool {}
116+
function imagejpeg(GdImage $im, $to = null, ?int $quality = null, ?int $filters = null): bool {}
113117
#endif
114118

115-
function imagewbmp(GdImage $im, $to = null, int $foreground = UNKNOWN): bool {}
119+
function imagewbmp(GdImage $im, $to = null, ?int $foreground = null, ?int $filters = null): bool {}
116120

117121
function imagegd(GdImage $im, $to = UNKNOWN): bool {}
118122

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

121125
#ifdef HAVE_GD_BMP
122-
function imagebmp(GdImage $im, $to = null, int $compressed = 1): bool {}
126+
function imagebmp(GdImage $im, $to = null, bool $compressed = true): bool {}
123127
#endif
124128

125129
function imagedestroy(GdImage $im): bool {}
@@ -166,15 +170,15 @@ function imagefill(GdImage $im, int $x, int $y, int $col): bool {}
166170

167171
function imagecolorstotal(GdImage $im): int {}
168172

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

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

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

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

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

179183
function imagefontwidth(int $font): int {}
180184

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

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

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

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

237+
/** @param array|int|float $options */
233238
function imageaffinematrixget(int $type, $options = UNKNOWN): array|false {}
234239

235240
function imageaffinematrixconcat(array $m1, array $m2): array|false {}
@@ -238,4 +243,4 @@ function imagegetinterpolation(GdImage $im): int {}
238243

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

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

0 commit comments

Comments
 (0)