]> granicus.if.org Git - imagemagick/blobdiff - tests/validate.c
Eliminate c++ compiler warnings
[imagemagick] / tests / validate.c
index d00be411d2c8441f11d10c519f0826bed0b27181..abd74b5a62ac0fcd346184dbda45373131302dd3 100644 (file)
 %                        ImageMagick Validation Suite                         %
 %                                                                             %
 %                             Software Design                                 %
-%                               John Cristy                                   %
+%                                  Cristy                                     %
 %                               March 2001                                    %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
@@ -48,6 +48,7 @@
 #include <locale.h>
 #include "MagickWand/MagickWand.h"
 #include "MagickCore/colorspace-private.h"
+#include "MagickCore/gem.h"
 #include "MagickCore/resource_.h"
 #include "MagickCore/string-private.h"
 #include "validate.h"
@@ -128,13 +129,6 @@ static void ConvertHSIToRGB(const double hue,const double saturation,
   *blue*=QuantumRange;
 }
 
-static inline double MagickMin(const double x,const double y)
-{
-  if (x < y)
-    return(x);
-  return(y);
-}
-
 static void ConvertRGBToHSI(const double red,const double green,
   const double blue,double *hue,double *saturation,double *intensity)
 {
@@ -158,122 +152,6 @@ static void ConvertRGBToHSI(const double red,const double green,
     *hue+=1.0;
 }
 
-MagickExport void ConvertHSLToRGB(const double hue,const double saturation,
-  const double lightness,double *red,double *green,double *blue)
-{
-  double
-    c,
-    h,
-    min,
-    x;
-
-  h=hue*360.0;
-  if (lightness <= 0.5)
-    c=2.0*lightness*saturation;
-  else
-    c=(2.0-2.0*lightness)*saturation;
-  min=lightness-0.5*c;
-  h-=360.0*floor(h/360.0);
-  h/=60.0;
-  x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
-  switch ((int) floor(h))
-  {
-    case 0:
-    {
-      *red=QuantumRange*(min+c);
-      *green=QuantumRange*(min+x);
-      *blue=QuantumRange*min;
-      break;
-    }
-    case 1:
-    {
-      *red=QuantumRange*(min+x);
-      *green=QuantumRange*(min+c);
-      *blue=QuantumRange*min;
-      break;
-    }
-    case 2:
-    {
-      *red=QuantumRange*min;
-      *green=QuantumRange*(min+c);
-      *blue=QuantumRange*(min+x);
-      break;
-    }
-    case 3:
-    {
-      *red=QuantumRange*min;
-      *green=QuantumRange*(min+x);
-      *blue=QuantumRange*(min+c);
-      break;
-    }
-    case 4:
-    {
-      *red=QuantumRange*(min+x);
-      *green=QuantumRange*min;
-      *blue=QuantumRange*(min+c);
-      break;
-    }
-    case 5:
-    {
-      *red=QuantumRange*(min+c);
-      *green=QuantumRange*min;
-      *blue=QuantumRange*(min+x);
-      break;
-    }
-    default:
-    {
-      *red=0.0;
-      *green=0.0;
-      *blue=0.0;
-    }
-  }
-}
-
-static inline double MagickMax(const double x,const double y)
-{
-  if (x > y)
-    return(x);
-  return(y);
-}
-
-MagickExport void ConvertRGBToHSL(const double red,const double green,
-  const double blue,double *hue,double *saturation,double *lightness)
-{
-  double
-    c,
-    max,
-    min;
-
-  max=MagickMax(QuantumScale*red,MagickMax(QuantumScale*green,
-    QuantumScale*blue));
-  min=MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
-    QuantumScale*blue));
-  c=max-min;
-  *lightness=(max+min)/2.0;
-  if (c <= 0.0)
-    {
-      *hue=0.0;
-      *saturation=0.0;
-      return;
-    }
-  if (max == (QuantumScale*red))
-    {
-      *hue=(QuantumScale*green-QuantumScale*blue)/c;
-      if ((QuantumScale*green) < (QuantumScale*blue))
-        *hue+=6.0;
-    }
-  else
-    if (max == (QuantumScale*green))
-      *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
-    else
-      *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
-  *hue*=60.0/360.0;
-  if (*lightness <= 0.5)
-    *saturation=c/(2.0*(*lightness));
-  else
-    *saturation=c/(2.0-2.0*(*lightness));
-}
-
 static void ConvertHSVToRGB(const double hue,const double saturation,
   const double value,double *red,double *green,double *blue)
 {
@@ -602,20 +480,6 @@ static void ConvertRGBToLMS(const double red,const double green,
   ConvertXYZToLMS(X,Y,Z,L,M,S);
 }
 
-static inline double PerceptibleReciprocal(const double x)
-{
-  double
-    sign;
-
-  /*
-    Return 1/x where x is perceptible (not unlimited or infinitesimal).
-  */
-  sign=x < 0.0 ? -1.0 : 1.0;
-  if ((sign*x) >= MagickEpsilon)
-    return(1.0/x);
-  return(sign/MagickEpsilon);
-}
-
 static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
   double *L,double *u,double *v)
 {
@@ -1281,7 +1145,7 @@ static size_t ValidateCompareCommand(ImageInfo *image_info,
 {
   char
     **arguments,
-    command[MaxTextExtent];
+    command[MagickPathExtent];
 
   int
     number_arguments;
@@ -1303,13 +1167,15 @@ static size_t ValidateCompareCommand(ImageInfo *image_info,
     CatchException(exception);
     (void) FormatLocaleFile(stdout,"  test %.20g: %s",(double) (test++),
       compare_options[i]);
-    (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
+    (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
       compare_options[i],reference_filename,reference_filename,output_filename);
     arguments=StringToArgv(command,&number_arguments);
     if (arguments == (char **) NULL)
       {
         (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
           GetMagickModule());
+        (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),"%s",
+          exception->reason);
         (*fail)++;
         continue;
       }
@@ -1318,10 +1184,12 @@ static size_t ValidateCompareCommand(ImageInfo *image_info,
     for (j=0; j < (ssize_t) number_arguments; j++)
       arguments[j]=DestroyString(arguments[j]);
     arguments=(char **) RelinquishMagickMemory(arguments);
-    if (status != MagickFalse)
+    if (status == MagickFalse)
       {
         (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
           GetMagickModule());
+        (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),"%s",
+          exception->reason);
         (*fail)++;
         continue;
       }
@@ -1372,7 +1240,7 @@ static size_t ValidateCompositeCommand(ImageInfo *image_info,
 {
   char
     **arguments,
-    command[MaxTextExtent];
+    command[MagickPathExtent];
 
   int
     number_arguments;
@@ -1394,7 +1262,7 @@ static size_t ValidateCompositeCommand(ImageInfo *image_info,
     CatchException(exception);
     (void) FormatLocaleFile(stdout,"  test %.20g: %s",(double) (test++),
       composite_options[i]);
-    (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
+    (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
       reference_filename,composite_options[i],reference_filename,
       output_filename);
     arguments=StringToArgv(command,&number_arguments);
@@ -1410,7 +1278,7 @@ static size_t ValidateCompositeCommand(ImageInfo *image_info,
     for (j=0; j < (ssize_t) number_arguments; j++)
       arguments[j]=DestroyString(arguments[j]);
     arguments=(char **) RelinquishMagickMemory(arguments);
-    if (status != MagickFalse)
+    if (status == MagickFalse)
       {
         (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
           GetMagickModule());
@@ -1464,7 +1332,7 @@ static size_t ValidateConvertCommand(ImageInfo *image_info,
 {
   char
     **arguments,
-    command[MaxTextExtent];
+    command[MagickPathExtent];
 
   int
     number_arguments;
@@ -1486,7 +1354,7 @@ static size_t ValidateConvertCommand(ImageInfo *image_info,
     CatchException(exception);
     (void) FormatLocaleFile(stdout,"  test %.20g: %s",(double) test++,
       convert_options[i]);
-    (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
+    (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
       reference_filename,convert_options[i],reference_filename,output_filename);
     arguments=StringToArgv(command,&number_arguments);
     if (arguments == (char **) NULL)
@@ -1501,7 +1369,7 @@ static size_t ValidateConvertCommand(ImageInfo *image_info,
     for (j=0; j < (ssize_t) number_arguments; j++)
       arguments[j]=DestroyString(arguments[j]);
     arguments=(char **) RelinquishMagickMemory(arguments);
-    if (status != MagickFalse)
+    if (status == MagickFalse)
       {
         (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
           GetMagickModule());
@@ -1555,7 +1423,7 @@ static size_t ValidateIdentifyCommand(ImageInfo *image_info,
 {
   char
     **arguments,
-    command[MaxTextExtent];
+    command[MagickPathExtent];
 
   int
     number_arguments;
@@ -1578,7 +1446,7 @@ static size_t ValidateIdentifyCommand(ImageInfo *image_info,
     CatchException(exception);
     (void) FormatLocaleFile(stdout,"  test %.20g: %s",(double) test++,
       identify_options[i]);
-    (void) FormatLocaleString(command,MaxTextExtent,"%s %s",
+    (void) FormatLocaleString(command,MagickPathExtent,"%s %s",
       identify_options[i],reference_filename);
     arguments=StringToArgv(command,&number_arguments);
     if (arguments == (char **) NULL)
@@ -1593,7 +1461,7 @@ static size_t ValidateIdentifyCommand(ImageInfo *image_info,
     for (j=0; j < (ssize_t) number_arguments; j++)
       arguments[j]=DestroyString(arguments[j]);
     arguments=(char **) RelinquishMagickMemory(arguments);
-    if (status != MagickFalse)
+    if (status == MagickFalse)
       {
         (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
           GetMagickModule());
@@ -1654,10 +1522,10 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
 {
   char
 #ifdef MagickCountTempFiles
-    path[MaxTextExtent],
-    SystemCommand[MaxTextExtent],
+    path[MagickPathExtent],
+    SystemCommand[MagickPathExtent],
 #endif
-    size[MaxTextExtent];
+    size[MagickPathExtent];
 
   const MagickInfo
     *magick_info;
@@ -1715,38 +1583,46 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
         CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
         (double) reference_types[j].depth);
       (void) CopyMagickString(image_info->filename,reference_filename,
-        MaxTextExtent);
+        MagickPathExtent);
       reference_image=ReadImage(image_info,exception);
-      if (reference_image == (Image *) NULL)
+      if ((reference_image == (Image *) NULL) ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           continue;
         }
       /*
         Write reference image.
       */
-      (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
+      (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",
         (double) reference_image->columns,(double) reference_image->rows);
       (void) CloneString(&image_info->size,size);
       image_info->depth=reference_types[j].depth;
-      (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
-        reference_formats[i].magick,output_filename);
+      (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
+        "%s:%s",reference_formats[i].magick,output_filename);
       status=SetImageType(reference_image,reference_types[j].type,exception);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
         }
       status=SetImageDepth(reference_image,reference_types[j].depth,exception);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
@@ -1754,23 +1630,30 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
       reference_image->compression=reference_formats[i].compression;
       status=WriteImage(image_info,reference_image,exception);
       reference_image=DestroyImage(reference_image);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           continue;
         }
       /*
         Ping reference image.
       */
-      (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
+      (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
         reference_formats[i].magick,output_filename);
       ping_image=PingImage(image_info,exception);
-      if (ping_image == (Image *) NULL)
+      if (ping_image == (Image *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           continue;
         }
@@ -1779,28 +1662,36 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
         Read reference image.
       */
       reference_image=ReadImage(image_info,exception);
-      if (reference_image == (Image *) NULL)
+      if ((reference_image == (Image *) NULL) ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           continue;
         }
       /*
         Write reference image.
       */
-      (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
-        reference_formats[i].magick,output_filename);
+      (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
+        "%s:%s",reference_formats[i].magick,output_filename);
       (void) CopyMagickString(image_info->magick,reference_formats[i].magick,
-        MaxTextExtent);
+        MagickPathExtent);
       reference_image->depth=reference_types[j].depth;
       reference_image->compression=reference_formats[i].compression;
       length=8192;
       blob=ImageToBlob(image_info,reference_image,&length,exception);
-      if (blob == (unsigned char *) NULL)
+      if ((blob == (unsigned char *) NULL) ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
@@ -1809,10 +1700,14 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
         Ping reference blob.
       */
       ping_image=PingBlob(image_info,blob,length,exception);
-      if (ping_image == (Image *) NULL)
+      if (ping_image == (Image *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           blob=(unsigned char *) RelinquishMagickMemory(blob);
           continue;
@@ -1821,14 +1716,18 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
       /*
         Read reconstruct image.
       */
-      (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
+      (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
         reference_formats[i].magick,output_filename);
       reconstruct_image=BlobToImage(image_info,blob,length,exception);
       blob=(unsigned char *) RelinquishMagickMemory(blob);
-      if (reconstruct_image == (Image *) NULL)
+      if (reconstruct_image == (Image *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
@@ -1843,10 +1742,14 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
         RootMeanSquaredErrorMetric,&distortion,exception);
       reconstruct_image=DestroyImage(reconstruct_image);
       reference_image=DestroyImage(reference_image);
-      if (difference_image == (Image *) NULL)
+      if (difference_image == (Image *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           continue;
         }
@@ -1863,7 +1766,7 @@ static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
       (void) fflush(stdout);
       SystemCommand[0]='\0';
       (void) strncat(SystemCommand,"echo `ls ",9);
-      (void) strncat(SystemCommand,path,MaxTextExtent-31);
+      (void) strncat(SystemCommand,path,MagickPathExtent-31);
       (void) strncat(SystemCommand,"* | wc -w` tmp files.",20);
       (void) system(SystemCommand);
       (void) fflush(stdout);
@@ -1916,7 +1819,7 @@ static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
   ExceptionInfo *exception)
 {
   char
-    size[MaxTextExtent];
+    size[MagickPathExtent];
 
   const MagickInfo
     *magick_info;
@@ -1961,38 +1864,46 @@ static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
         CommandOptionToMnemonic(MagickTypeOptions,reference_types[j].type),
         (double) reference_types[j].depth);
       (void) CopyMagickString(image_info->filename,reference_filename,
-        MaxTextExtent);
+        MagickPathExtent);
       reference_image=ReadImage(image_info,exception);
-      if (reference_image == (Image *) NULL)
+      if ((reference_image == (Image *) NULL) ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           continue;
         }
       /*
         Write reference image.
       */
-      (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",
+      (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",
         (double) reference_image->columns,(double) reference_image->rows);
       (void) CloneString(&image_info->size,size);
       image_info->depth=reference_types[j].depth;
-      (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
-        reference_formats[i].magick,output_filename);
+      (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
+        "%s:%s",reference_formats[i].magick,output_filename);
       status=SetImageType(reference_image,reference_types[j].type,exception);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
         }
       status=SetImageDepth(reference_image,reference_types[j].depth,exception);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
@@ -2000,38 +1911,44 @@ static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
       reference_image->compression=reference_formats[i].compression;
       status=WriteImage(image_info,reference_image,exception);
       reference_image=DestroyImage(reference_image);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          if (exception->reason != (char *) NULL)
+            (void) FormatLocaleFile(stdout,"    reason:%s\n",exception->reason);
+          CatchException(exception);
           (*fail)++;
           continue;
         }
       /*
         Read reference image.
       */
-      (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
+      (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
         reference_formats[i].magick,output_filename);
       reference_image=ReadImage(image_info,exception);
-      if (reference_image == (Image *) NULL)
+      if ((reference_image == (Image *) NULL) ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           continue;
         }
       /*
         Write reference image.
       */
-      (void) FormatLocaleString(reference_image->filename,MaxTextExtent,"%s:%s",
-        reference_formats[i].magick,output_filename);
+      (void) FormatLocaleString(reference_image->filename,MagickPathExtent,
+        "%s:%s",reference_formats[i].magick,output_filename);
       reference_image->depth=reference_types[j].depth;
       reference_image->compression=reference_formats[i].compression;
       status=WriteImage(image_info,reference_image,exception);
-      if (status == MagickFalse)
+      if (status == MagickFalse ||exception->severity >= ErrorException)
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
@@ -2039,13 +1956,15 @@ static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
       /*
         Read reconstruct image.
       */
-      (void) FormatLocaleString(image_info->filename,MaxTextExtent,"%s:%s",
+      (void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s:%s",
         reference_formats[i].magick,output_filename);
       reconstruct_image=ReadImage(image_info,exception);
-      if (reconstruct_image == (Image *) NULL)
+      if (reconstruct_image == (Image *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
@@ -2060,10 +1979,12 @@ static size_t ValidateImageFormatsOnDisk(ImageInfo *image_info,
         RootMeanSquaredErrorMetric,&distortion,exception);
       reconstruct_image=DestroyImage(reconstruct_image);
       reference_image=DestroyImage(reference_image);
-      if (difference_image == (Image *) NULL)
+      if (difference_image == (Image *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           continue;
         }
@@ -2161,12 +2082,14 @@ static size_t ValidateImportExportPixels(ImageInfo *image_info,
         reference_map[i],CommandOptionToMnemonic(MagickStorageOptions,
         reference_storage[j].type));
       (void) CopyMagickString(image_info->filename,reference_filename,
-        MaxTextExtent);
+        MagickPathExtent);
       reference_image=ReadImage(image_info,exception);
-      if (reference_image == (Image *) NULL)
+      if ((reference_image == (Image *) NULL) ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           continue;
         }
@@ -2175,22 +2098,25 @@ static size_t ValidateImportExportPixels(ImageInfo *image_info,
       length=strlen(reference_map[i])*reference_image->columns*
         reference_image->rows*reference_storage[j].quantum;
       pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
-      if (pixels == (unsigned char *) NULL)
+      if (pixels == (unsigned char *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
         }
-      (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
+      (void) memset(pixels,0,length*sizeof(*pixels));
       status=ExportImagePixels(reference_image,0,0,reference_image->columns,
         reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
         exception);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           pixels=(unsigned char *) RelinquishMagickMemory(pixels);
           reference_image=DestroyImage(reference_image);
@@ -2200,10 +2126,11 @@ static size_t ValidateImportExportPixels(ImageInfo *image_info,
       status=ImportImagePixels(reference_image,0,0,reference_image->columns,
         reference_image->rows,reference_map[i],reference_storage[j].type,
         pixels,exception);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
            pixels=(unsigned char *) RelinquishMagickMemory(pixels);
           reference_image=DestroyImage(reference_image);
@@ -2222,10 +2149,11 @@ static size_t ValidateImportExportPixels(ImageInfo *image_info,
         reconstruct_image->rows,reference_map[i],reference_storage[j].type,
         pixels,exception);
       pixels=(unsigned char *) RelinquishMagickMemory(pixels);
-      if (status == MagickFalse)
+      if (status == MagickFalse || (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           reference_image=DestroyImage(reference_image);
           continue;
@@ -2237,10 +2165,12 @@ static size_t ValidateImportExportPixels(ImageInfo *image_info,
         RootMeanSquaredErrorMetric,&distortion,exception);
       reconstruct_image=DestroyImage(reconstruct_image);
       reference_image=DestroyImage(reference_image);
-      if (difference_image == (Image *) NULL)
+      if (difference_image == (Image *) NULL ||
+          (exception->severity >= ErrorException))
         {
           (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
+          CatchException(exception);
           (*fail)++;
           continue;
         }
@@ -2300,7 +2230,7 @@ static size_t ValidateMontageCommand(ImageInfo *image_info,
 {
   char
     **arguments,
-    command[MaxTextExtent];
+    command[MagickPathExtent];
 
   int
     number_arguments;
@@ -2322,7 +2252,7 @@ static size_t ValidateMontageCommand(ImageInfo *image_info,
     CatchException(exception);
     (void) FormatLocaleFile(stdout,"  test %.20g: %s",(double) (test++),
       montage_options[i]);
-    (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s %s",
+    (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s %s",
       reference_filename,montage_options[i],reference_filename,
       output_filename);
     arguments=StringToArgv(command,&number_arguments);
@@ -2338,7 +2268,7 @@ static size_t ValidateMontageCommand(ImageInfo *image_info,
     for (j=0; j < (ssize_t) number_arguments; j++)
       arguments[j]=DestroyString(arguments[j]);
     arguments=(char **) RelinquishMagickMemory(arguments);
-    if (status != MagickFalse)
+    if (status == MagickFalse)
       {
         (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
@@ -2392,7 +2322,7 @@ static size_t ValidateStreamCommand(ImageInfo *image_info,
 {
   char
     **arguments,
-    command[MaxTextExtent];
+    command[MagickPathExtent];
 
   int
     number_arguments;
@@ -2414,7 +2344,7 @@ static size_t ValidateStreamCommand(ImageInfo *image_info,
     CatchException(exception);
     (void) FormatLocaleFile(stdout,"  test %.20g: %s",(double) (test++),
       stream_options[i]);
-    (void) FormatLocaleString(command,MaxTextExtent,"%s %s %s",
+    (void) FormatLocaleString(command,MagickPathExtent,"%s %s %s",
       stream_options[i],reference_filename,output_filename);
     arguments=StringToArgv(command,&number_arguments);
     if (arguments == (char **) NULL)
@@ -2429,7 +2359,7 @@ static size_t ValidateStreamCommand(ImageInfo *image_info,
     for (j=0; j < (ssize_t) number_arguments; j++)
       arguments[j]=DestroyString(arguments[j]);
     arguments=(char **) RelinquishMagickMemory(arguments);
-    if (status != MagickFalse)
+    if (status == MagickFalse)
       {
         (void) FormatLocaleFile(stdout,"... fail @ %s/%s/%lu.\n",
             GetMagickModule());
@@ -2510,8 +2440,8 @@ int main(int argc,char **argv)
 }
 
   char
-    output_filename[MaxTextExtent],
-    reference_filename[MaxTextExtent],
+    output_filename[MagickPathExtent],
+    reference_filename[MagickPathExtent],
     *option;
 
   double
@@ -2562,13 +2492,14 @@ int main(int argc,char **argv)
   (void) regard_warnings;
   exception=AcquireExceptionInfo();
   image_info=AcquireImageInfo();
-  (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent);
+  (void) CopyMagickString(image_info->filename,ReferenceFilename,
+    MagickPathExtent);
   for (i=1; i < (ssize_t) argc; i++)
   {
     option=argv[i];
     if (IsCommandOption(option) == MagickFalse)
       {
-        (void) CopyMagickString(image_info->filename,option,MaxTextExtent);
+        (void) CopyMagickString(image_info->filename,option,MagickPathExtent);
         continue;
       }
     switch (*(option+1))
@@ -2629,7 +2560,7 @@ int main(int argc,char **argv)
             if (*option == '+')
               break;
             i++;
-            if (i == (ssize_t) argc)
+            if (i >= (ssize_t) argc)
               ThrowValidateException(OptionError,"MissingArgument",option);
             validate=ParseCommandOption(MagickValidateOptions,MagickFalse,
               argv[i]);
@@ -2668,11 +2599,11 @@ int main(int argc,char **argv)
     {
       if (LocaleCompare(image_info->filename,ReferenceFilename) == 0)
         (void) CopyMagickString(reference_image->magick,ReferenceImageFormat,
-          MaxTextExtent);
+          MagickPathExtent);
       (void) AcquireUniqueFilename(reference_filename);
       (void) AcquireUniqueFilename(output_filename);
       (void) CopyMagickString(reference_image->filename,reference_filename,
-        MaxTextExtent);
+        MagickPathExtent);
       status=WriteImage(image_info,reference_image,exception);
       reference_image=DestroyImage(reference_image);
       if (status == MagickFalse)