Skip to content

Commit 4e6fbb0

Browse files
committed
Promote warnings to exceptions in ext/gd
Closes GH-6023
1 parent 22982ee commit 4e6fbb0

33 files changed

+95
-69
lines changed

ext/gd/gd.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -861,20 +861,20 @@ PHP_FUNCTION(imagecolormatch)
861861
result = gdImageColorMatch(im1, im2);
862862
switch (result) {
863863
case -1:
864-
php_error_docref(NULL, E_WARNING, "Image1 must be TrueColor" );
865-
RETURN_FALSE;
864+
zend_argument_value_error(1, "must be TrueColor");
865+
RETURN_THROWS();
866866
break;
867867
case -2:
868-
php_error_docref(NULL, E_WARNING, "Image2 must be Palette" );
869-
RETURN_FALSE;
868+
zend_argument_value_error(2, "must be Palette");
869+
RETURN_THROWS();
870870
break;
871871
case -3:
872-
php_error_docref(NULL, E_WARNING, "Image1 and Image2 must be the same size" );
873-
RETURN_FALSE;
872+
zend_argument_value_error(2, "must be the same size as argument #1 ($im1)");
873+
RETURN_THROWS();
874874
break;
875875
case -4:
876-
php_error_docref(NULL, E_WARNING, "Image2 must have at least one color" );
877-
RETURN_FALSE;
876+
zend_argument_value_error(2, "must have at least one color");
877+
RETURN_THROWS();
878878
break;
879879
}
880880

@@ -1459,7 +1459,7 @@ gdImagePtr _php_image_create_from_string(zend_string *data, char *tn, gdImagePtr
14591459

14601460
im = (*ioctx_func_p)(io_ctx);
14611461
if (!im) {
1462-
php_error_docref(NULL, E_WARNING, "Passed data is not in '%s' format", tn);
1462+
php_error_docref(NULL, E_WARNING, "Passed data is not in \"%s\" format", tn);
14631463
io_ctx->gd_free(io_ctx);
14641464
return NULL;
14651465
}
@@ -1483,8 +1483,8 @@ PHP_FUNCTION(imagecreatefromstring)
14831483
}
14841484

14851485
if (ZSTR_LEN(data) < sizeof(sig)) {
1486-
php_error_docref(NULL, E_WARNING, "Empty string or invalid image");
1487-
RETURN_FALSE;
1486+
zend_argument_value_error(1, "cannot be empty");
1487+
RETURN_THROWS();
14881488
}
14891489

14901490
memcpy(sig, ZSTR_VAL(data), sizeof(sig));
@@ -1666,7 +1666,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
16661666
return;
16671667
}
16681668

1669-
php_error_docref(NULL, E_WARNING, "'%s' is not a valid %s file", file, tn);
1669+
php_error_docref(NULL, E_WARNING, "\"%s\" is not a valid %s file", file, tn);
16701670
out_err:
16711671
php_stream_close(stream);
16721672
RETURN_FALSE;
@@ -1806,7 +1806,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
18061806

18071807
fp = VCWD_FOPEN(fn, "wb");
18081808
if (!fp) {
1809-
php_error_docref(NULL, E_WARNING, "Unable to open '%s' for writing", fn);
1809+
php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", fn);
18101810
RETURN_FALSE;
18111811
}
18121812

@@ -2297,8 +2297,8 @@ PHP_FUNCTION(imagecolorsforindex)
22972297
add_assoc_long(return_value,"blue", gdImageBlue(im,col));
22982298
add_assoc_long(return_value,"alpha", gdImageAlpha(im,col));
22992299
} else {
2300-
php_error_docref(NULL, E_WARNING, "Color index %d out of range", col);
2301-
RETURN_FALSE;
2300+
zend_argument_value_error(2, "is out of range");
2301+
RETURN_THROWS();
23022302
}
23032303
}
23042304
/* }}} */

ext/gd/tests/001-mb.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ echo "Done\n";
2020
Warning: imagecreatefrompng(%s001私はガラスを食べられます.test): Failed to open stream: No such file or directory in %s on line %d
2121
bool(false)
2222

23-
Warning: imagecreatefrompng(): '%s001私はガラスを食べられます.test' is not a valid PNG file in %s on line %d
23+
Warning: imagecreatefrompng(): "%s001私はガラスを食べられます.test" is not a valid PNG file in %s on line %d
2424
bool(false)
2525
Done

ext/gd/tests/001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ echo "Done\n";
2020
Warning: imagecreatefrompng(%s001.test): Failed to open stream: No such file or directory in %s on line %d
2121
bool(false)
2222

23-
Warning: imagecreatefrompng(): '%s001.test' is not a valid PNG file in %s on line %d
23+
Warning: imagecreatefrompng(): "%s001.test" is not a valid PNG file in %s on line %d
2424
bool(false)
2525
Done

ext/gd/tests/bug37346-mb.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Bug #37346 (gdimagecreatefromgif, bad colormap)
99
$im = imagecreatefromgif(__DIR__ . '/bug37346私はガラスを食べられます.gif');
1010
?>
1111
--EXPECTF--
12-
Warning: imagecreatefromgif(): '%sbug37346私はガラスを食べられます.gif' is not a valid GIF file in %sbug37346-mb.php on line %d
12+
Warning: imagecreatefromgif(): "%sbug37346私はガラスを食べられます.gif" is not a valid GIF file in %sbug37346-mb.php on line %d

ext/gd/tests/bug37346.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Bug #37346 (gdimagecreatefromgif, bad colormap)
99
$im = imagecreatefromgif(__DIR__ . '/bug37346.gif');
1010
?>
1111
--EXPECTF--
12-
Warning: imagecreatefromgif(): '%sbug37346.gif' is not a valid GIF file in %sbug37346.php on line %d
12+
Warning: imagecreatefromgif(): "%sbug37346.gif" is not a valid GIF file in %sbug37346.php on line %d

ext/gd/tests/bug37360.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ $im = imagecreatefromgif(__DIR__ . '/bug37360.gif');
1010
var_dump($im);
1111
?>
1212
--EXPECTF--
13-
Warning: imagecreatefromgif(): '%s' is not a valid GIF file in %s on line %d
13+
Warning: imagecreatefromgif(): "%s" is not a valid GIF file in %s on line %d
1414
bool(false)

ext/gd/tests/bug38112.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Bug #38112 (GIF Invalid Code size ).
1111
$im = imagecreatefromgif(__DIR__ . '/bug38112.gif');
1212
?>
1313
--EXPECTF--
14-
Warning: imagecreatefromgif(): '%sbug38112.gif' is not a valid GIF file in %sbug38112.php on line %d
14+
Warning: imagecreatefromgif(): "%sbug38112.gif" is not a valid GIF file in %sbug38112.php on line %d

ext/gd/tests/bug39780.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Warning: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncate
1616

1717
Warning: imagecreatefrompng(): gd-png error: setjmp returns error condition in %s on line %d
1818

19-
Warning: imagecreatefrompng(): '%s' is not a valid PNG file in %s on line %d
19+
Warning: imagecreatefrompng(): "%s" is not a valid PNG file in %s on line %d
2020
bool(false)

ext/gd/tests/bug39780_extern.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ var_dump($im);
1414
--EXPECTF--
1515
gd-png: fatal libpng error: Read Error: truncated data
1616
gd-png error: setjmp returns error condition 2
17-
Warning: imagecreatefrompng(): '%sbug39780.png' is not a valid PNG file in /%s on line %d
17+
Warning: imagecreatefrompng(): v%sbug39780.png" is not a valid PNG file in /%s on line %d
1818
bool(false)

ext/gd/tests/bug71912-mb.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . "invalid_neg_size私はガラ
1111
?>
1212
OK
1313
--EXPECTF--
14-
Warning: imagecreatefromgd2(): '%s%einvalid_neg_size私はガラスを食べられます.gd2' is not a valid GD2 file in %s%ebug71912-mb.php on line %d
14+
Warning: imagecreatefromgd2(): "%s%einvalid_neg_size私はガラスを食べられます.gd2" is not a valid GD2 file in %s%ebug71912-mb.php on line %d
1515
OK

0 commit comments

Comments
 (0)