From a270a0ca67fe316e33ab11088a9c3dfec1ad6acd Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Sat, 25 Feb 2023 15:26:51 +0000 Subject: [PATCH] Throw exception instead of returning NULL The signature of the function tells us that getImageBlob() always return string or throws Exception. In this case, the returning value is NULL as retval is unset. --- imagick_class.c | 3 ++- tests/329_imagick_getImageBlob_empty.phpt | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/imagick_class.c b/imagick_class.c index b06b899a..33c46d3d 100644 --- a/imagick_class.c +++ b/imagick_class.c @@ -8409,7 +8409,8 @@ PHP_METHOD(Imagick, getImageBlob) image_contents = MagickGetImageBlob(intern->magick_wand, &image_size); if (!image_contents) { - return; + php_imagick_throw_exception(IMAGICK_CLASS, "Failed to get the image contents (empty or invalid image?)" TSRMLS_CC); + RETURN_THROWS(); } IM_ZVAL_STRINGL(return_value, (char *)image_contents, image_size); diff --git a/tests/329_imagick_getImageBlob_empty.phpt b/tests/329_imagick_getImageBlob_empty.phpt index 07c5d318..1f6396e7 100644 --- a/tests/329_imagick_getImageBlob_empty.phpt +++ b/tests/329_imagick_getImageBlob_empty.phpt @@ -10,14 +10,14 @@ $imagick = new Imagick(); try { $imagick->newPseudoImage(200, 200, "xc:red"); $result = $imagick->getImageBlob(); - echo "Imagick failed to throw exception"; + echo "Imagick failed to throw exception" . PHP_EOL; } catch (ImagickException $e) { - echo "ImagickException: " . $e->getMessage(); + echo "ImagickException: " . $e->getMessage() . PHP_EOL; } echo "Fin.\n"; ?> --EXPECTF-- -ImagickException: Some words here. +ImagickException: Failed to get the image contents (empty or invalid image?) Fin. \ No newline at end of file