Skip to content

Commit 838ae01

Browse files
committed
Make imagegd $file parameter nullable
It is explicitly documented to be nullable, and this matches other functions like imagepng. It is also documented to accept a stream, which it currently does not...
1 parent d4aff25 commit 838ae01

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

ext/gd/gd.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,36 +1778,32 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
17781778
char *file = NULL;
17791779
zend_long quality = 0, type = 0;
17801780
gdImagePtr im;
1781-
char *fn = NULL;
17821781
FILE *fp;
17831782
size_t file_len = 0;
17841783
int argc = ZEND_NUM_ARGS();
17851784
int q = -1, t = 1;
17861785

17871786
/* The quality parameter for gd2 stands for chunk size */
17881787

1789-
if (zend_parse_parameters(argc, "O|pll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
1788+
if (zend_parse_parameters(argc, "O|p!ll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
17901789
RETURN_THROWS();
17911790
}
17921791

17931792
im = php_gd_libgdimageptr_from_zval_p(imgind);
17941793

1795-
if (argc > 1) {
1796-
fn = file;
1797-
if (argc >= 3) {
1798-
q = quality;
1799-
if (argc == 4) {
1800-
t = type;
1801-
}
1794+
if (argc >= 3) {
1795+
q = quality;
1796+
if (argc == 4) {
1797+
t = type;
18021798
}
18031799
}
18041800

1805-
if (argc >= 2 && file_len) {
1806-
PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
1801+
if (file_len) {
1802+
PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename");
18071803

1808-
fp = VCWD_FOPEN(fn, "wb");
1804+
fp = VCWD_FOPEN(file, "wb");
18091805
if (!fp) {
1810-
php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", fn);
1806+
php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", file);
18111807
RETURN_FALSE;
18121808
}
18131809

ext/gd/gd.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ function imagejpeg(GdImage $image, $file = null, int $quality = -1): bool {}
124124
/** @param resource|string|null $file */
125125
function imagewbmp(GdImage $image, $file = null, ?int $foreground_color = null): bool {}
126126

127-
function imagegd(GdImage $image, string $file = UNKNOWN): bool {}
127+
function imagegd(GdImage $image, ?string $file = null): bool {}
128128

129-
function imagegd2(GdImage $image, string $file = UNKNOWN, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
129+
function imagegd2(GdImage $image, ?string $file = null, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
130130

131131
#ifdef HAVE_GD_BMP
132132
/** @param resource|string|null $file */

ext/gd/gd_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 59256d0de105f1a2f5d5fc1e20f8090031b42a76 */
2+
* Stub hash: 63898b501cc3ae38585fe0c6f70a9f7865fbee4d */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -238,12 +238,12 @@ ZEND_END_ARG_INFO()
238238

239239
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd, 0, 1, _IS_BOOL, 0)
240240
ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
241-
ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
241+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
242242
ZEND_END_ARG_INFO()
243243

244244
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd2, 0, 1, _IS_BOOL, 0)
245245
ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
246-
ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
246+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
247247
ZEND_ARG_TYPE_INFO(0, chunk_size, IS_LONG, 0)
248248
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
249249
ZEND_END_ARG_INFO()

0 commit comments

Comments
 (0)