]> granicus.if.org Git - php/commitdiff
Warnings to errors in imagecrop(auto)
authorMark <mrandall@digitellinc.com>
Tue, 3 Sep 2019 23:53:16 +0000 (01:53 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 4 Sep 2019 13:12:04 +0000 (15:12 +0200)
ext/gd/gd.c
ext/gd/tests/bug72494.phpt

index d0affc2d1611ea5bec20722909efaa72df46206c..de704d08a4fd2a1b39e4a82a782747db6e890b44 100644 (file)
@@ -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 {
index 4cca9aec8e5b001c3ce4f122f3ac7f68bfb1aa27..3a4ea08b9c1c55d3ac6a72f12630ff9aa18a7bf7 100644 (file)
@@ -6,10 +6,14 @@ if (!extension_loaded('gd')) die('skip gd extension not available');
 ?>
 --FILE--
 <?php
+require __DIR__ . '/func.inc';
+
 $im = imagecreate(10,10);
-imagecropauto($im, IMG_CROP_THRESHOLD, 0, 1337);
+
+trycatch_dump(
+    fn() => 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