MagickSetImageFilename is a no-op when passed a null, but returns MagickTrue?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
coloring
Posts: 82
Joined: 2015-08-27T10:17:36-07:00
Authentication code: 1151

MagickSetImageFilename is a no-op when passed a null, but returns MagickTrue?

Post by coloring »

Perhaps I'm reading this code wrong (I'm new to C), but from what I see, if the filename is NULL, it returns MagickTrue, as if it set the filename successfully, but it actually didn't do anything. It looks like a unintentional no-op to me.

Or maybe I'm missing something, and people should simply be smart enough not to pass a NULL in the first place

Code: Select all

WandExport MagickBooleanType MagickSetImageFilename(MagickWand *wand,
  const char *filename)
{
  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == MagickWandSignature);
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  if (wand->images == (Image *) NULL)
    ThrowWandException(WandError,"ContainsNoImages",wand->name);
  if (filename != (const char *) NULL)
    (void) CopyMagickString(wand->images->filename,filename,MagickPathExtent);
  return(MagickTrue);
}
Last edited by coloring on 2019-08-31T22:37:18-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickSetImageFilename is a no-op when passed a null, but returns MagickTrue?

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
Post Reply