]> granicus.if.org Git - imagemagick/blobdiff - coders/xpm.c
...
[imagemagick] / coders / xpm.c
index 3c3e38eaf439d8893f2bbf35b2b93ad418f42fc8..ca88c1751d49708d4b46f387234c1229ceb2d08e 100644 (file)
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  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,          %
@@ -151,30 +151,28 @@ static int CompareXPMColor(const void *target,const void *source)
   return(strcmp(p,q));
 }
 
-static char *CopyXPMColor(char *destination,const char *source,size_t length)
+static ssize_t CopyXPMColor(char *destination,const char *source,size_t length)
 {
-  while (length-- && (*source != '\0'))
-    *destination++=(*source++);
-  *destination='\0';
-  return(destination-length);
+  register const char
+    *p;
+
+  p=source;
+  while (length-- && (*p != '\0'))
+    *destination++=(*p++);
+  if (length != 0)
+    *destination='\0';
+  return((ssize_t) (p-source));
 }
 
 static char *NextXPMLine(char *p)
 {
-  assert(p != (char*)NULL);
+  assert(p != (char *) NULL);
   p=strchr(p,'\n');
   if (p != (char *) NULL)
     p++;
   return(p);
 }
 
-static inline size_t MagickMin(const size_t x,const size_t y)
-{
-  if (x < y)
-    return(x);
-  return(y);
-}
-
 static char *ParseXPMColor(char *color,MagickBooleanType search_start)
 {
 #define NumberTargets  6
@@ -190,7 +188,7 @@ static char *ParseXPMColor(char *color,MagickBooleanType search_start)
     i;
 
   static const char
-    *targets[NumberTargets] = { "c ", "g ", "g4 ", "m ", "b ", "s " };
+    *const targets[NumberTargets] = { "c ", "g ", "g4 ", "m ", "b ", "s " };
 
   if (search_start != MagickFalse)
     {
@@ -218,32 +216,29 @@ static char *ParseXPMColor(char *color,MagickBooleanType search_start)
       }
       return((char *) NULL);
     }
-  else
+  for (p=color+1; *p != '\0'; p++)
+  {
+    if (*p == '\n')
+      break;
+    if (isspace((int) ((unsigned char) (*(p-1)))) == 0)
+      continue;
+    if (isspace((int) ((unsigned char) (*p))) != 0)
+      continue;
+    for (i=0; i < NumberTargets; i++)
     {
-      for (p=color+1; *p != '\0'; p++)
-      {
-        if (*p == '\n')
-          break;
-        if (isspace((int) ((unsigned char) (*(p-1)))) == 0)
-          continue;
-        if (isspace((int) ((unsigned char) (*p))) != 0)
-          continue;
-        for (i=0; i < NumberTargets; i++)
-        {
-          if (*p == *targets[i] && *(p+1) == *(targets[i]+1))
-            return(p);
-        }
-      }
-      return(p);
+      if ((*p == *targets[i]) && (*(p+1) == *(targets[i]+1)))
+        return(p);
     }
+  }
+  return(p);
 }
 
 static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
   char
     *grey,
-    key[MaxTextExtent],
-    target[MaxTextExtent],
+    key[MagickPathExtent],
+    target[MagickPathExtent],
     *xpm_buffer;
 
   Image
@@ -285,12 +280,12 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     Open image file.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   image=AcquireImage(image_info,exception);
   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
   if (status == MagickFalse)
@@ -301,26 +296,28 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   /*
     Read XPM file.
   */
-  length=MaxTextExtent;
+  length=MagickPathExtent;
   xpm_buffer=(char *) AcquireQuantumMemory((size_t) length,sizeof(*xpm_buffer));
+  if (xpm_buffer == (char *) NULL)
+    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+  *xpm_buffer='\0';
   p=xpm_buffer;
-  if (xpm_buffer != (char *) NULL)
-    while (ReadBlobString(image,p) != (char *) NULL)
-    {
-      if ((*p == '#') && ((p == xpm_buffer) || (*(p-1) == '\n')))
-        continue;
-      if ((*p == '}') && (*(p+1) == ';'))
-        break;
-      p+=strlen(p);
-      if ((size_t) (p-xpm_buffer+MaxTextExtent) < length)
-        continue;
-      length<<=1;
-      xpm_buffer=(char *) ResizeQuantumMemory(xpm_buffer,length+MaxTextExtent,
-        sizeof(*xpm_buffer));
-      if (xpm_buffer == (char *) NULL)
-        break;
-      p=xpm_buffer+strlen(xpm_buffer);
-    }
+  while (ReadBlobString(image,p) != (char *) NULL)
+  {
+    if ((*p == '#') && ((p == xpm_buffer) || (*(p-1) == '\n')))
+      continue;
+    if ((*p == '}') && (*(p+1) == ';'))
+      break;
+    p+=strlen(p);
+    if ((size_t) (p-xpm_buffer+MagickPathExtent) < length)
+      continue;
+    length<<=1;
+    xpm_buffer=(char *) ResizeQuantumMemory(xpm_buffer,length+MagickPathExtent,
+      sizeof(*xpm_buffer));
+    if (xpm_buffer == (char *) NULL)
+      break;
+    p=xpm_buffer+strlen(xpm_buffer);
+  }
   if (xpm_buffer == (char *) NULL)
     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
   /*
@@ -339,15 +336,18 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     if (count == 4)
       break;
   }
-  if ((count != 4) || (width > 10) || (image->columns == 0) ||
-      (image->rows == 0) || (image->colors == 0))
-    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+  if ((count != 4) || (width == 0) || (width > 3) ||
+      (image->columns == 0) || (image->rows == 0) ||
+      (image->colors == 0) || (image->colors > MaxColormapSize))
+    {
+      xpm_buffer=DestroyString(xpm_buffer);
+      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+    }
   /*
     Remove unquoted characters.
   */
   active=MagickFalse;
-  q=xpm_buffer;
-  while (*p != '\0')
+  for (q=xpm_buffer; *p != '\0'; )
   {
     if (*p++ == '"')
       {
@@ -365,32 +365,38 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   xpm_colors=NewSplayTree(CompareXPMColor,RelinquishMagickMemory,
     (void *(*)(void *)) NULL);
   if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
-    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    {
+      xpm_colors=DestroySplayTree(xpm_colors);
+      xpm_buffer=DestroyString(xpm_buffer);
+      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    }
   /*
     Read image colormap.
   */
   image->depth=1;
   next=NextXPMLine(xpm_buffer);
-  for (j=0; (j < (ssize_t) image->colors) && (next != (char*) NULL); j++)
+  for (j=0; (j < (ssize_t) image->colors) && (next != (char *) NULL); j++)
   {
     p=next;
     next=NextXPMLine(p);
-    (void) CopyXPMColor(key,p,MagickMin((size_t) width,MaxTextExtent));
+    (void) CopyXPMColor(key,p,MagickMin((size_t) width,MagickPathExtent-1));
     status=AddValueToSplayTree(xpm_colors,ConstantString(key),(void *) j);
     /*
       Parse color.
     */
-    (void) CopyMagickString(target,"gray",MaxTextExtent);
+    (void) CopyMagickString(target,"gray",MagickPathExtent);
     q=ParseXPMColor(p+width,MagickTrue);
     if (q != (char *) NULL)
       {
         while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0'))
           q++;
+        if ((next-q) < 0)
+          break;
         if (next != (char *) NULL)
           (void) CopyXPMColor(target,q,MagickMin((size_t) (next-q),
-            MaxTextExtent));
+            MagickPathExtent-1));
         else
-          (void) CopyMagickString(target,q,MaxTextExtent);
+          (void) CopyMagickString(target,q,MagickPathExtent);
         q=ParseXPMColor(target,MagickFalse);
         if (q != (char *) NULL)
           *q='\0';
@@ -412,13 +418,24 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
       image->depth=image->colormap[j].depth;
   }
   if (j < (ssize_t) image->colors)
-    ThrowReaderException(CorruptImageError,"CorruptImage");
+    {
+      xpm_colors=DestroySplayTree(xpm_colors);
+      xpm_buffer=DestroyString(xpm_buffer);
+      ThrowReaderException(CorruptImageError,"CorruptImage");
+    }
   j=0;
   if (image_info->ping == MagickFalse)
     {
       /*
         Read image pixels.
       */
+      status=SetImageExtent(image,image->columns,image->rows,exception);
+      if (status == MagickFalse)
+        {
+          xpm_colors=DestroySplayTree(xpm_colors);
+          xpm_buffer=DestroyString(xpm_buffer);
+          return(DestroyImageList(image));
+        }
       for (y=0; y < (ssize_t) image->rows; y++)
       {
         p=NextXPMLine(p);
@@ -429,23 +446,32 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
           break;
         for (x=0; x < (ssize_t) image->columns; x++)
         {
-          (void) CopyXPMColor(key,p,(size_t) width);
+          ssize_t count=CopyXPMColor(key,p,MagickMin(width,MagickPathExtent-1));
+          if (count != (ssize_t) width)
+            break;
           j=(ssize_t) GetValueFromSplayTree(xpm_colors,key);
           if (image->storage_class == PseudoClass)
-            SetPixelIndex(image,j,r);
-          SetPixelInfoPixel(image,image->colormap+j,r);
-          p+=width;
+            SetPixelIndex(image,(Quantum) j,r);
+          SetPixelViaPixelInfo(image,image->colormap+j,r);
+          p+=count;
           r+=GetPixelChannels(image);
         }
+        if (x < (ssize_t) image->columns)
+          break;
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
       }
       if (y < (ssize_t) image->rows)
-        ThrowReaderException(CorruptImageError,"NotEnoughPixelData");
+        {
+          xpm_colors=DestroySplayTree(xpm_colors);
+          xpm_buffer=DestroyString(xpm_buffer);
+          ThrowReaderException(CorruptImageError,"NotEnoughPixelData");
+        }
     }
   /*
     Relinquish resources.
   */
+  xpm_buffer=DestroyString(xpm_buffer);
   xpm_colors=DestroySplayTree(xpm_colors);
   (void) CloseBlob(image);
   return(GetFirstImageInList(image));
@@ -479,28 +505,22 @@ ModuleExport size_t RegisterXPMImage(void)
   MagickInfo
     *entry;
 
-  entry=SetMagickInfo("PICON");
+  entry=AcquireMagickInfo("XPM","PICON","Personal Icon");
   entry->decoder=(DecodeImageHandler *) ReadXPMImage;
   entry->encoder=(EncodeImageHandler *) WritePICONImage;
-  entry->adjoin=MagickFalse;
-  entry->description=ConstantString("Personal Icon");
-  entry->module=ConstantString("XPM");
+  entry->flags^=CoderAdjoinFlag;
   (void) RegisterMagickInfo(entry);
-  entry=SetMagickInfo("PM");
+  entry=AcquireMagickInfo("XPM","PM","X Windows system pixmap (color)");
   entry->decoder=(DecodeImageHandler *) ReadXPMImage;
   entry->encoder=(EncodeImageHandler *) WriteXPMImage;
-  entry->adjoin=MagickFalse;
-  entry->stealth=MagickTrue;
-  entry->description=ConstantString("X Windows system pixmap (color)");
-  entry->module=ConstantString("XPM");
+  entry->flags^=CoderAdjoinFlag;
+  entry->flags|=CoderStealthFlag;
   (void) RegisterMagickInfo(entry);
-  entry=SetMagickInfo("XPM");
+  entry=AcquireMagickInfo("XPM","XPM","X Windows system pixmap (color)");
   entry->decoder=(DecodeImageHandler *) ReadXPMImage;
   entry->encoder=(EncodeImageHandler *) WriteXPMImage;
   entry->magick=(IsImageFormatHandler *) IsXPM;
-  entry->adjoin=MagickFalse;
-  entry->description=ConstantString("X Windows system pixmap (color)");
-  entry->module=ConstantString("XPM");
+  entry->flags^=CoderAdjoinFlag;
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }
@@ -601,10 +621,10 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
                          "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";
 
   char
-    buffer[MaxTextExtent],
-    basename[MaxTextExtent],
-    name[MaxTextExtent],
-    symbol[MaxTextExtent];
+    buffer[MagickPathExtent],
+    basename[MagickPathExtent],
+    name[MagickPathExtent],
+    symbol[MagickPathExtent];
 
   Image
     *affinity_image,
@@ -649,13 +669,13 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
     Open output image file.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
@@ -668,14 +688,20 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
   blob_info=CloneImageInfo(image_info);
   (void) AcquireUniqueFilename(blob_info->filename);
   if ((image_info->type != TrueColorType) &&
-      (IsImageGray(image,exception) != MagickFalse))
+      (SetImageGray(image,exception) != MagickFalse))
     affinity_image=BlobToImage(blob_info,Graymap,GraymapExtent,exception);
   else
     affinity_image=BlobToImage(blob_info,Colormap,ColormapExtent,exception);
   (void) RelinquishUniqueFileResource(blob_info->filename);
   blob_info=DestroyImageInfo(blob_info);
   if ((picon == (Image *) NULL) || (affinity_image == (Image *) NULL))
-    return(MagickFalse);
+    {
+      if (affinity_image != (Image *) NULL)
+        affinity_image=DestroyImage(affinity_image);
+      if (picon != (Image *) NULL)
+        picon=DestroyImage(picon);
+      return(MagickFalse);
+    }
   quantize_info=AcquireQuantizeInfo(image_info);
   status=RemapImage(quantize_info,picon,affinity_image,exception);
   quantize_info=DestroyQuantizeInfo(quantize_info);
@@ -684,7 +710,7 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
   if (picon->storage_class == PseudoClass)
     {
       (void) CompressImageColormap(picon,exception);
-      if (picon->alpha_trait == BlendPixelTrait)
+      if (picon->alpha_trait != UndefinedPixelTrait)
         transparent=MagickTrue;
     }
   else
@@ -692,7 +718,7 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
       /*
         Convert DirectClass to PseudoClass picon.
       */
-      if (picon->alpha_trait == BlendPixelTrait)
+      if (picon->alpha_trait != UndefinedPixelTrait)
         {
           /*
             Map all the transparent pixels.
@@ -732,7 +758,7 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
         for (x=0; x < (ssize_t) picon->columns; x++)
         {
           if (GetPixelAlpha(image,q) == (Quantum) TransparentAlpha)
-            SetPixelIndex(picon,picon->colors,q);
+            SetPixelIndex(picon,(Quantum) picon->colors,q);
           q+=GetPixelChannels(picon);
         }
         if (SyncAuthenticPixels(picon,exception) == MagickFalse)
@@ -750,11 +776,11 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
   */
   (void) WriteBlobString(image,"/* XPM */\n");
   GetPathComponent(picon->filename,BasePath,basename);
-  (void) FormatLocaleString(buffer,MaxTextExtent,
+  (void) FormatLocaleString(buffer,MagickPathExtent,
     "static char *%s[] = {\n",basename);
   (void) WriteBlobString(image,buffer);
   (void) WriteBlobString(image,"/* columns rows colors chars-per-pixel */\n");
-  (void) FormatLocaleString(buffer,MaxTextExtent,
+  (void) FormatLocaleString(buffer,MagickPathExtent,
     "\"%.20g %.20g %.20g %.20g\",\n",(double) picon->columns,(double)
     picon->rows,(double) colors,(double) characters_per_pixel);
   (void) WriteBlobString(image,buffer);
@@ -772,7 +798,7 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
     if (transparent != MagickFalse)
       {
         if (i == (ssize_t) (colors-1))
-          (void) CopyMagickString(name,"grey75",MaxTextExtent);
+          (void) CopyMagickString(name,"grey75",MagickPathExtent);
       }
     /*
       Write XPM color.
@@ -785,7 +811,7 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
       symbol[j]=Cixel[k];
     }
     symbol[j]='\0';
-    (void) FormatLocaleString(buffer,MaxTextExtent,"\"%s c %s\",\n",
+    (void) FormatLocaleString(buffer,MagickPathExtent,"\"%s c %s\",\n",
        symbol,name);
     (void) WriteBlobString(image,buffer);
   }
@@ -809,11 +835,11 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
         symbol[j]=Cixel[k];
       }
       symbol[j]='\0';
-      (void) CopyMagickString(buffer,symbol,MaxTextExtent);
+      (void) CopyMagickString(buffer,symbol,MagickPathExtent);
       (void) WriteBlobString(image,buffer);
-      p+=GetPixelChannels(image);
+      p+=GetPixelChannels(picon);
     }
-    (void) FormatLocaleString(buffer,MaxTextExtent,"\"%s\n",
+    (void) FormatLocaleString(buffer,MagickPathExtent,"\"%s\n",
       y == (ssize_t) (picon->rows-1) ? "" : ",");
     (void) WriteBlobString(image,buffer);
     status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
@@ -864,10 +890,10 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
                          "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";
 
   char
-    buffer[MaxTextExtent],
-    basename[MaxTextExtent],
-    name[MaxTextExtent],
-    symbol[MaxTextExtent];
+    buffer[MagickPathExtent],
+    basename[MagickPathExtent],
+    name[MagickPathExtent],
+    symbol[MagickPathExtent];
 
   MagickBooleanType
     status;
@@ -895,20 +921,20 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
     Open output image file.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
   if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
     (void) TransformImageColorspace(image,sRGBColorspace,exception);
   opacity=(-1);
-  if (image->alpha_trait != BlendPixelTrait)
+  if (image->alpha_trait == UndefinedPixelTrait)
     {
       if ((image->storage_class == DirectClass) || (image->colors > 256))
         (void) SetImageType(image,PaletteType,exception);
@@ -923,7 +949,7 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
         Identify transparent colormap index.
       */
       if ((image->storage_class == DirectClass) || (image->colors > 256))
-        (void) SetImageType(image,PaletteBilevelMatteType,exception);
+        (void) SetImageType(image,PaletteBilevelAlphaType,exception);
       for (i=0; i < (ssize_t) image->colors; i++)
         if (image->colormap[i].alpha != OpaqueAlpha)
           {
@@ -941,7 +967,7 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
           }
       if (opacity == -1)
         {
-          (void) SetImageType(image,PaletteBilevelMatteType,exception);
+          (void) SetImageType(image,PaletteBilevelAlphaType,exception);
           for (i=0; i < (ssize_t) image->colors; i++)
             if (image->colormap[i].alpha != OpaqueAlpha)
               {
@@ -978,19 +1004,19 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
   GetPathComponent(image->filename,BasePath,basename);
   if (isalnum((int) ((unsigned char) *basename)) == 0)
     {
-      (void) FormatLocaleString(buffer,MaxTextExtent,"xpm_%s",basename);
-      (void) CopyMagickString(basename,buffer,MaxTextExtent);
+      (void) FormatLocaleString(buffer,MagickPathExtent,"xpm_%s",basename);
+      (void) CopyMagickString(basename,buffer,MagickPathExtent);
     }
   if (isalpha((int) ((unsigned char) basename[0])) == 0)
     basename[0]='_';
   for (i=1; basename[i] != '\0'; i++)
     if (isalnum((int) ((unsigned char) basename[i])) == 0)
       basename[i]='_';
-  (void) FormatLocaleString(buffer,MaxTextExtent,
+  (void) FormatLocaleString(buffer,MagickPathExtent,
     "static char *%s[] = {\n",basename);
   (void) WriteBlobString(image,buffer);
   (void) WriteBlobString(image,"/* columns rows colors chars-per-pixel */\n");
-  (void) FormatLocaleString(buffer,MaxTextExtent,
+  (void) FormatLocaleString(buffer,MagickPathExtent,
     "\"%.20g %.20g %.20g %.20g \",\n",(double) image->columns,(double)
     image->rows,(double) image->colors,(double) characters_per_pixel);
   (void) WriteBlobString(image,buffer);
@@ -1006,7 +1032,7 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
     pixel.alpha=(double) OpaqueAlpha;
     (void) QueryColorname(image,&pixel,XPMCompliance,name,exception);
     if (i == opacity)
-      (void) CopyMagickString(name,"None",MaxTextExtent);
+      (void) CopyMagickString(name,"None",MagickPathExtent);
     /*
       Write XPM color.
     */
@@ -1018,7 +1044,7 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
       symbol[j]=Cixel[k];
     }
     symbol[j]='\0';
-    (void) FormatLocaleString(buffer,MaxTextExtent,"\"%s c %s\",\n",symbol,
+    (void) FormatLocaleString(buffer,MagickPathExtent,"\"%s c %s\",\n",symbol,
       name);
     (void) WriteBlobString(image,buffer);
   }
@@ -1042,11 +1068,11 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image,
         symbol[j]=Cixel[k];
       }
       symbol[j]='\0';
-      (void) CopyMagickString(buffer,symbol,MaxTextExtent);
+      (void) CopyMagickString(buffer,symbol,MagickPathExtent);
       (void) WriteBlobString(image,buffer);
       p+=GetPixelChannels(image);
     }
-    (void) FormatLocaleString(buffer,MaxTextExtent,"\"%s\n",
+    (void) FormatLocaleString(buffer,MagickPathExtent,"\"%s\n",
       (y == (ssize_t) (image->rows-1) ? "" : ","));
     (void) WriteBlobString(image,buffer);
     if (image->previous == (Image *) NULL)