diff --git a/MagickWand/mogrify.c b/MagickWand/mogrify.c index 1b1cf52af7..d2244bb6eb 100644 --- a/MagickWand/mogrify.c +++ b/MagickWand/mogrify.c @@ -1217,7 +1217,11 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc, } for (p=start_color; (*p != '-') && (*p != '\0'); p++) if (*p == '(') - for (p++; (*p != ')') && (*p != '\0'); p++); + { + for (p++; (*p != ')') && (*p != '\0'); p++); + if (*p == '\0') + break; + } if (*p == '-') (void) CopyMagickString(stop_color,p+1,MagickPathExtent); *p='\0'; diff --git a/MagickWand/operation.c b/MagickWand/operation.c index 74f2f98ba5..fbee9d8693 100644 --- a/MagickWand/operation.c +++ b/MagickWand/operation.c @@ -2088,7 +2088,11 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand, } for (p=start_color; (*p != '-') && (*p != '\0'); p++) if (*p == '(') - for (p++; (*p != ')') && (*p != '\0'); p++); + { + for (p++; (*p != ')') && (*p != '\0'); p++); + if (*p == '\0') + break; + } if (*p == '-') (void) CopyMagickString(stop_color,p+1,MagickPathExtent); *p='\0'; diff --git a/coders/gradient.c b/coders/gradient.c index 70a3ca04c4..28a35afcc1 100644 --- a/coders/gradient.c +++ b/coders/gradient.c @@ -203,7 +203,11 @@ static Image *ReadGRADIENTImage(const ImageInfo *image_info, MagickPathExtent); for (p=start_color; (*p != '-') && (*p != '\0'); p++) if (*p == '(') - for (p++; (*p != ')') && (*p != '\0'); p++); + { + for (p++; (*p != ')') && (*p != '\0'); p++); + if (*p == '\0') + break; + } if (*p == '-') (void) CopyMagickString(stop_color,p+1,MagickPathExtent); *p='\0';