From 06a3dd536d496eb00d0abeb9d52f4129afbfbe56 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 4 Sep 2019 01:53:16 +0200 Subject: [PATCH] Warnings to errors in imagecrop(auto) --- ext/gd/gd.c | 25 +++++++++++++------------ ext/gd/tests/bug72494.phpt | 14 +++++++++----- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index d0affc2d16..de704d08a4 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3814,29 +3814,29 @@ PHP_FUNCTION(imagecrop) if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) { rect.x = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing x position"); - RETURN_FALSE; + zend_throw_error(NULL, "Cropping rectangle is missing x position"); + return; } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) { rect.y = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing y position"); - RETURN_FALSE; + zend_throw_error(NULL, "Cropping rectangle is missing y position"); + return; } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) { rect.width = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing width"); - RETURN_FALSE; + zend_throw_error(NULL, "Cropping rectangle is missing width"); + return; } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) { rect.height = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing height"); - RETURN_FALSE; + zend_throw_error(NULL, "Cropping rectangle is missing height"); + return; } im_crop = gdImageCrop(im, &rect); @@ -3879,16 +3879,17 @@ PHP_FUNCTION(imagecropauto) case GD_CROP_THRESHOLD: if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) { - php_error_docref(NULL, E_WARNING, "Color argument missing with threshold mode"); - RETURN_FALSE; + zend_throw_error(NULL, "Color argument missing with threshold mode"); + return; } im_crop = gdImageCropThreshold(im, color, (float) threshold); break; default: - php_error_docref(NULL, E_WARNING, "Unknown crop mode"); - RETURN_FALSE; + zend_throw_error(NULL, "Unknown crop mode"); + return; } + if (im_crop == NULL) { RETURN_FALSE; } else { diff --git a/ext/gd/tests/bug72494.phpt b/ext/gd/tests/bug72494.phpt index 4cca9aec8e..3a4ea08b9c 100644 --- a/ext/gd/tests/bug72494.phpt +++ b/ext/gd/tests/bug72494.phpt @@ -6,10 +6,14 @@ if (!extension_loaded('gd')) die('skip gd extension not available'); ?> --FILE-- imagecropauto($im, IMG_CROP_THRESHOLD, 0, 1337) +); + ?> -===DONE=== ---EXPECTF-- -Warning: imagecropauto(): Color argument missing with threshold mode in %s on line %d -===DONE=== +--EXPECT-- +!! [Error] Color argument missing with threshold mode -- 2.50.1