Skip to content

Commit

Permalink
Throw exception instead of returning NULL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mikhail Galanin authored and Danack committed Jul 1, 2024
1 parent 2c9e599 commit a270a0c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion imagick_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/329_imagick_getImageBlob_empty.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit a270a0c

Please sign in to comment.