Commit ea2604471 for imagemagick.org

commit ea2604471bbdf9c2173f8f281b93a41c98a8b5ad
Author: Dirk Lemstra <dirk@lemstra.org>
Date:   Sun Jun 8 09:38:05 2025 +0200

    Use MagickSsanf in the coders.

diff --git a/coders/cals.c b/coders/cals.c
index c9a9e79eb..b6c2002ae 100644
--- a/coders/cals.c
+++ b/coders/cals.c
@@ -65,6 +65,7 @@
 #include "MagickCore/resource_.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/module.h"

 #if defined(MAGICKCORE_TIFF_DELEGATE)
@@ -215,17 +216,17 @@ static Image *ReadCALSImage(const ImageInfo *image_info,
       {
         if (LocaleNCompare(header,"rdensty:",8) == 0)
           {
-            (void) sscanf(header+8,"%lu",&density);
+            (void) MagickSscanf(header+8,"%lu",&density);
             break;
           }
         if (LocaleNCompare(header,"rpelcnt:",8) == 0)
           {
-            (void) sscanf(header+8,"%lu,%lu",&width,&height);
+            (void) MagickSscanf(header+8,"%lu,%lu",&width,&height);
             break;
           }
         if (LocaleNCompare(header,"rorient:",8) == 0)
           {
-            (void) sscanf(header+8,"%lu,%lu",&pel_path,&direction);
+            (void) MagickSscanf(header+8,"%lu,%lu",&pel_path,&direction);
             if (pel_path == 90)
               orientation=5;
             else
@@ -240,7 +241,7 @@ static Image *ReadCALSImage(const ImageInfo *image_info,
           }
         if (LocaleNCompare(header,"rtype:",6) == 0)
           {
-            (void) sscanf(header+6,"%lu",&type);
+            (void) MagickSscanf(header+6,"%lu",&type);
             break;
           }
         break;
diff --git a/coders/dcm.c b/coders/dcm.c
index df45d7174..5d680812b 100644
--- a/coders/dcm.c
+++ b/coders/dcm.c
@@ -3451,8 +3451,8 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                   subtype=0;
                   if (strlen(transfer_syntax) > 17)
                     {
-                      count=(ssize_t) sscanf(transfer_syntax+17,".%d.%d",&type,
-                        &subtype);
+                      count=(ssize_t) MagickSscanf(transfer_syntax+17,".%d.%d",
+                        &type,&subtype);
                       if (count < 1)
                         ThrowDCMException(CorruptImageError,
                           "ImproperImageHeader")
diff --git a/coders/exr.c b/coders/exr.c
index 10fa3639e..068e6e2d2 100644
--- a/coders/exr.c
+++ b/coders/exr.c
@@ -56,6 +56,7 @@
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/module.h"
 #include "MagickCore/resource_.h"
 #include "MagickCore/utility.h"
@@ -1104,7 +1105,7 @@ static MagickBooleanType WriteEXRImage(const ImageInfo *image_info,Image *image,
       /*
         Sampling factors, valid values are 1x1 or 2x2.
       */
-      if (sscanf(sampling_factor,"%d:%d:%d",factors,factors+1,factors+2) == 3)
+      if (MagickSscanf(sampling_factor,"%d:%d:%d",factors,factors+1,factors+2) == 3)
         {
           if ((factors[0] == factors[1]) && (factors[1] == factors[2]))
             factors[0]=1;
@@ -1113,7 +1114,7 @@ static MagickBooleanType WriteEXRImage(const ImageInfo *image_info,Image *image,
               factors[0]=2;
         }
       else
-        if (sscanf(sampling_factor,"%dx%d",factors,factors+1) == 2)
+        if (MagickSscanf(sampling_factor,"%dx%d",factors,factors+1) == 2)
           {
             if (factors[0] != factors[1])
               factors[0]=0;
diff --git a/coders/hdr.c b/coders/hdr.c
index eda71f547..7a0204259 100644
--- a/coders/hdr.c
+++ b/coders/hdr.c
@@ -316,7 +316,7 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception)
             {
               if (LocaleCompare(keyword,"primaries") == 0)
                 {
-                  chromaticity_count=sscanf(value,"%g %g %g %g %g %g %g %g",
+                  chromaticity_count=MagickSscanf(value,"%g %g %g %g %g %g %g %g",
                     &chromaticity[0],&chromaticity[1],&chromaticity[2],
                     &chromaticity[3],&chromaticity[4],&chromaticity[5],
                     &white_point[0],&white_point[1]);
@@ -338,7 +338,7 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     height,
                     width;

-                  if (sscanf(value,"%d +X %d",&height,&width) == 2)
+                  if (MagickSscanf(value,"%d +X %d",&height,&width) == 2)
                     {
                       image->columns=(size_t) width;
                       image->rows=(size_t) height;
diff --git a/coders/jp2.c b/coders/jp2.c
index c7d953501..e9a5e0158 100644
--- a/coders/jp2.c
+++ b/coders/jp2.c
@@ -1042,7 +1042,7 @@ static MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image,
         Set quality PSNR.
       */
       p=option;
-      for (i=0; sscanf(p,"%f",&parameters->tcp_distoratio[i]) == 1; i++)
+      for (i=0; MagickSscanf(p,"%f",&parameters->tcp_distoratio[i]) == 1; i++)
       {
         if (i > 100)
           break;
@@ -1080,7 +1080,7 @@ static MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image,
         Set compression rate.
       */
       p=option;
-      for (i=0; sscanf(p,"%f",&parameters->tcp_rates[i]) == 1; i++)
+      for (i=0; MagickSscanf(p,"%f",&parameters->tcp_rates[i]) == 1; i++)
       {
         if (i >= 100)
           break;
diff --git a/coders/meta.c b/coders/meta.c
index c76bbd5ce..690a9604b 100644
--- a/coders/meta.c
+++ b/coders/meta.c
@@ -213,7 +213,7 @@ static size_t convertHTMLcodes(char *s)
       }
   if ((length == 0) || (s == (char *) NULL) || (*s == '\0'))
     return(0);
-  if ((length > 3) && (s[1] == '#') && (sscanf(s,"&#%d;",&value) == 1))
+  if ((length > 3) && (s[1] == '#') && (MagickSscanf(s,"&#%d;",&value) == 1))
     {
       size_t
         o;
diff --git a/coders/mtv.c b/coders/mtv.c
index 99a9747c9..4612ae162 100644
--- a/coders/mtv.c
+++ b/coders/mtv.c
@@ -58,6 +58,7 @@
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/module.h"

 /*
@@ -145,7 +146,7 @@ static Image *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception)
   */
   (void) memset(buffer,0,sizeof(buffer));
   (void) ReadBlobString(image,buffer);
-  count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows);
+  count=(ssize_t) MagickSscanf(buffer,"%lu %lu\n",&columns,&rows);
   if (count != 2)
     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   do
@@ -215,7 +216,7 @@ static Image *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception)
     *buffer='\0';
     if (ReadBlobString(image,buffer) == (char *) NULL)
       break;
-    count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows);
+    count=(ssize_t) MagickSscanf(buffer,"%lu %lu\n",&columns,&rows);
     if (count > 0)
       {
         /*
diff --git a/coders/mvg.c b/coders/mvg.c
index 3c36e0b7d..f81a4523c 100644
--- a/coders/mvg.c
+++ b/coders/mvg.c
@@ -56,6 +56,7 @@
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"

 /*
   Forward declarations.
@@ -173,7 +174,7 @@ static Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
           count;

         for (p=primitive; (*p == ' ') || (*p == '\t'); p++) ;
-        count=sscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1,
+        count=MagickSscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1,
           &bounds.x2,&bounds.y2);
         if (count != 4)
           continue;
diff --git a/coders/pcl.c b/coders/pcl.c
index eda80a522..6c4dadde8 100644
--- a/coders/pcl.c
+++ b/coders/pcl.c
@@ -70,6 +70,7 @@
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/module.h"
 #include "MagickCore/token.h"
 #include "MagickCore/transform.h"
@@ -276,10 +277,10 @@ static Image *ReadPCLImage(const ImageInfo *image_info,ExceptionInfo *exception)
         /*
           Note region defined by crop box.
         */
-        count=(ssize_t) sscanf(command,"CropBox [%lf %lf %lf %lf",
+        count=(ssize_t) MagickSscanf(command,"CropBox [%lf %lf %lf %lf",
           &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
         if (count != 4)
-          count=(ssize_t) sscanf(command,"CropBox[%lf %lf %lf %lf",
+          count=(ssize_t) MagickSscanf(command,"CropBox[%lf %lf %lf %lf",
             &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
       }
     if (LocaleNCompare(MediaBox,command,strlen(MediaBox)) == 0)
@@ -287,10 +288,10 @@ static Image *ReadPCLImage(const ImageInfo *image_info,ExceptionInfo *exception)
         /*
           Note region defined by media box.
         */
-        count=(ssize_t) sscanf(command,"MediaBox [%lf %lf %lf %lf",
+        count=(ssize_t) MagickSscanf(command,"MediaBox [%lf %lf %lf %lf",
           &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
         if (count != 4)
-          count=(ssize_t) sscanf(command,"MediaBox[%lf %lf %lf %lf",
+          count=(ssize_t) MagickSscanf(command,"MediaBox[%lf %lf %lf %lf",
             &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
       }
     if (count != 4)
diff --git a/coders/pdf.c b/coders/pdf.c
index adc6ddacc..fb3f4da31 100644
--- a/coders/pdf.c
+++ b/coders/pdf.c
@@ -277,7 +277,7 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,
     if (CompareMagickByteBuffer(&buffer,PDFRotate,strlen(PDFRotate)) != MagickFalse)
       {
         p=GetMagickByteBufferDatum(&buffer);
-        (void) sscanf(p,PDFRotate" %lf",&pdf_info->angle);
+        (void) MagickSscanf(p,PDFRotate" %lf",&pdf_info->angle);
       }
     if (pdf_info->cmyk == MagickFalse)
       {
@@ -330,10 +330,10 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,
               Note region defined by crop box.
             */
             p=GetMagickByteBufferDatum(&buffer);
-            count=(ssize_t) sscanf(p,"CropBox [%lf %lf %lf %lf",&bounds.x1,
+            count=(ssize_t) MagickSscanf(p,"CropBox [%lf %lf %lf %lf",&bounds.x1,
               &bounds.y1,&bounds.x2,&bounds.y2);
             if (count != 4)
-              count=(ssize_t) sscanf(p,"CropBox[%lf %lf %lf %lf",&bounds.x1,
+              count=(ssize_t) MagickSscanf(p,"CropBox[%lf %lf %lf %lf",&bounds.x1,
                 &bounds.y1,&bounds.x2,&bounds.y2);
           }
       }
@@ -346,10 +346,10 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,
                 Note region defined by trim box.
               */
               p=GetMagickByteBufferDatum(&buffer);
-              count=(ssize_t) sscanf(p,"TrimBox [%lf %lf %lf %lf",&bounds.x1,
+              count=(ssize_t) MagickSscanf(p,"TrimBox [%lf %lf %lf %lf",&bounds.x1,
                 &bounds.y1,&bounds.x2,&bounds.y2);
               if (count != 4)
-                count=(ssize_t) sscanf(p,"TrimBox[%lf %lf %lf %lf",&bounds.x1,
+                count=(ssize_t) MagickSscanf(p,"TrimBox[%lf %lf %lf %lf",&bounds.x1,
                   &bounds.y1,&bounds.x2,&bounds.y2);
             }
         }
@@ -360,10 +360,10 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,
               Note region defined by media box.
             */
             p=GetMagickByteBufferDatum(&buffer);
-            count=(ssize_t) sscanf(p,"MediaBox [%lf %lf %lf %lf",&bounds.x1,
+            count=(ssize_t) MagickSscanf(p,"MediaBox [%lf %lf %lf %lf",&bounds.x1,
               &bounds.y1,&bounds.x2,&bounds.y2);
             if (count != 4)
-              count=(ssize_t) sscanf(p,"MediaBox[%lf %lf %lf %lf",&bounds.x1,
+              count=(ssize_t) MagickSscanf(p,"MediaBox[%lf %lf %lf %lf",&bounds.x1,
                 &bounds.y1,&bounds.x2,&bounds.y2);
           }
     if (count != 4)
diff --git a/coders/pgx.c b/coders/pgx.c
index 896f1a526..d897f5e25 100644
--- a/coders/pgx.c
+++ b/coders/pgx.c
@@ -60,6 +60,7 @@
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/module.h"

 /*
@@ -180,8 +181,8 @@ static Image *ReadPGXImage(const ImageInfo *image_info,ExceptionInfo *exception)
     }
   if (ReadBlobString(image,buffer) == (char *) NULL)
     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
-  count=(ssize_t) sscanf(buffer,"PG%[ \t]%2s%[ \t+-]%d%[ \t]%d%[ \t]%d",sans,
-    endian,sign,&precision,sans,&width,sans,&height);
+  count=(ssize_t) MagickSscanf(buffer,"PG%[ \t]%2s%[ \t+-]%d%[ \t]%d%[ \t]%d",
+    sans,endian,sign,&precision,sans,&width,sans,&height);
   if (count != 8)
     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   image->depth=(size_t) precision;
diff --git a/coders/png.c b/coders/png.c
index 08664131c..d5df8b5d2 100644
--- a/coders/png.c
+++ b/coders/png.c
@@ -7817,11 +7817,11 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info,
   assert(timestamp != (const char *) NULL);
   LogMagickEvent(CoderEvent,GetMagickModule(),
       "  Writing tIME chunk: timestamp property is %30s\n",timestamp);
-  ret=sscanf(timestamp,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,
+  ret=MagickSscanf(timestamp,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,
       &minute, &second);
   addhours=0;
   addminutes=0;
-  ret=sscanf(timestamp,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour,
+  ret=MagickSscanf(timestamp,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour,
       &minute, &second, &addhours, &addminutes);
     LogMagickEvent(CoderEvent,GetMagickModule(),
       "   Date format specified for png:tIME=%s" ,timestamp);
diff --git a/coders/ps.c b/coders/ps.c
index 434cb1551..7a82fe0f7 100644
--- a/coders/ps.c
+++ b/coders/ps.c
@@ -356,7 +356,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image,PSInfo *ps_info,
     if (CompareMagickByteBuffer(&buffer,ImageData,strlen(ImageData)) != MagickFalse)
       {
         p=GetMagickByteBufferDatum(&buffer);
-        (void) sscanf(p,ImageData " %lu %lu",&ps_info->columns,&ps_info->rows);
+        (void) MagickSscanf(p,ImageData " %lu %lu",&ps_info->columns,&ps_info->rows);
       }
     /*
       Is this a CMYK document?
@@ -473,7 +473,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image,PSInfo *ps_info,
         */
         p=GetMagickByteBufferDatum(&buffer);
         extent=0;
-        count=(ssize_t) sscanf(p,PhotoshopProfile " %lu",&extent);
+        count=(ssize_t) MagickSscanf(p,PhotoshopProfile " %lu",&extent);
         if ((count != 1) || (extent == 0))
           continue;
         if ((MagickSizeType) extent > GetBlobSize(image))
@@ -509,35 +509,35 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image,PSInfo *ps_info,
     if (CompareMagickByteBuffer(&buffer,BoundingBox,strlen(BoundingBox)) != MagickFalse)
       {
         p=GetMagickByteBufferDatum(&buffer);
-        count=(ssize_t) sscanf(p,BoundingBox " %lf %lf %lf %lf",
+        count=(ssize_t) MagickSscanf(p,BoundingBox " %lf %lf %lf %lf",
           &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
         i=2;
       }
     if (CompareMagickByteBuffer(&buffer,DocumentMedia,strlen(DocumentMedia)) != MagickFalse)
       {
         p=GetMagickByteBufferDatum(&buffer);
-        count=(ssize_t) sscanf(p,DocumentMedia " %lf %lf %lf %lf",
+        count=(ssize_t) MagickSscanf(p,DocumentMedia " %lf %lf %lf %lf",
           &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
         i=1;
       }
     if (CompareMagickByteBuffer(&buffer,HiResBoundingBox,strlen(HiResBoundingBox)) != MagickFalse)
       {
         p=GetMagickByteBufferDatum(&buffer);
-        count=(ssize_t) sscanf(p,HiResBoundingBox " %lf %lf %lf %lf",
+        count=(ssize_t) MagickSscanf(p,HiResBoundingBox " %lf %lf %lf %lf",
           &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
         i=3;
       }
     if (CompareMagickByteBuffer(&buffer,PageBoundingBox,strlen(PageBoundingBox)) != MagickFalse)
       {
         p=GetMagickByteBufferDatum(&buffer);
-        count=(ssize_t) sscanf(p,PageBoundingBox " %lf %lf %lf %lf",
+        count=(ssize_t) MagickSscanf(p,PageBoundingBox " %lf %lf %lf %lf",
           &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
         i=1;
       }
     if (CompareMagickByteBuffer(&buffer,PageMedia,strlen(PageMedia)) != MagickFalse)
       {
         p=GetMagickByteBufferDatum(&buffer);
-        count=(ssize_t) sscanf(p,PageMedia " %lf %lf %lf %lf",
+        count=(ssize_t) MagickSscanf(p,PageMedia " %lf %lf %lf %lf",
           &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
         i=1;
       }
diff --git a/coders/svg.c b/coders/svg.c
index c7d221c22..0d0f8046a 100644
--- a/coders/svg.c
+++ b/coders/svg.c
@@ -992,14 +992,14 @@ static void SVGProcessStyleElement(SVGInfo *svg_info,const xmlChar *name,
               font_size[MagickPathExtent],
               font_style[MagickPathExtent];

-            if (sscanf(value,"%2048s %2048s %2048s",font_style,font_size,
+            if (MagickSscanf(value,"%2048s %2048s %2048s",font_style,font_size,
                   font_family) != 3)
               break;
             if (GetUserSpaceCoordinateValue(svg_info,0,font_style) == 0)
               (void) FormatLocaleFile(svg_info->file,"font-style \"%s\"\n",
                 style);
             else
-              if (sscanf(value,"%2048s %2048s",font_size,font_family) != 2)
+              if (MagickSscanf(value,"%2048s %2048s",font_size,font_family) != 2)
                 break;
             (void) FormatLocaleFile(svg_info->file,"font-size \"%s\"\n",
               font_size);
diff --git a/coders/txt.c b/coders/txt.c
index a23e04e17..5d7860d60 100644
--- a/coders/txt.c
+++ b/coders/txt.c
@@ -67,6 +67,7 @@
 #include "MagickCore/static.h"
 #include "MagickCore/statistic.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/token.h"
 #include "coders/txt.h"

@@ -119,8 +120,8 @@ static MagickBooleanType IsTXT(const unsigned char *magick,const size_t length)
   if (LocaleNCompare((const char *) magick,MagickTXTID,
         strlen(MagickTXTID)) != 0)
     return(MagickFalse);
-  count=(ssize_t) sscanf((const char *) magick+32,"%lu,%lu,%lu,%32s",&columns,
-    &rows,&depth,colorspace);
+  count=(ssize_t) MagickSscanf((const char *) magick+32,"%lu,%lu,%lu,%32s",
+    &columns,&rows,&depth,colorspace);
   if (count != 4)
     return(MagickFalse);
   return(MagickTrue);
@@ -437,12 +438,12 @@ static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception)
       number_meta_channels = 0,
       width = 0;

-    count=(ssize_t) sscanf(text+32,"%lu,%lu,%lu,%lf,%32s",&width,&height,
+    count=(ssize_t) MagickSscanf(text+32,"%lu,%lu,%lu,%lf,%32s",&width,&height,
       &number_meta_channels,&max_value,colorspace);
     if (count < 5)
       {
         number_meta_channels=0;
-        count=(ssize_t) sscanf(text+32,"%lu,%lu,%lf,%32s",&width,&height,
+        count=(ssize_t) MagickSscanf(text+32,"%lu,%lu,%lf,%32s",&width,&height,
           &max_value,colorspace);
       }
     if ((count < 4) || (width == 0) || (height == 0) || (max_value == 0.0) ||
diff --git a/coders/xbm.c b/coders/xbm.c
index 9bebe1521..6b3696078 100644
--- a/coders/xbm.c
+++ b/coders/xbm.c
@@ -61,6 +61,7 @@
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/module.h"
 #include "MagickCore/utility.h"

@@ -237,12 +238,12 @@ static Image *ReadXBMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   height=0;
   *name='\0';
   while (ReadBlobString(image,buffer) != (char *) NULL)
-    if (sscanf(buffer,"#define %1024s %ld",name,&width) == 2)
+    if (MagickSscanf(buffer,"#define %1024s %ld",name,&width) == 2)
       if ((strlen(name) >= 6) &&
           (LocaleCompare(name+strlen(name)-6,"_width") == 0))
         break;
   while (ReadBlobString(image,buffer) != (char *) NULL)
-    if (sscanf(buffer,"#define %1024s %ld",name,&height) == 2)
+    if (MagickSscanf(buffer,"#define %1024s %ld",name,&height) == 2)
       if ((strlen(name) >= 7) &&
           (LocaleCompare(name+strlen(name)-7,"_height") == 0))
         break;
@@ -260,11 +261,11 @@ static Image *ReadXBMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   offset=TellBlob(image);
   while (ReadBlobString(image,buffer) != (char *) NULL)
   {
-    if (sscanf(buffer,"static short %1024s = {",name) == 1)
+    if (MagickSscanf(buffer,"static short %1024s = {",name) == 1)
       version=10;
-    else if (sscanf(buffer,"static unsigned char %1024s = {",name) == 1)
+    else if (MagickSscanf(buffer,"static unsigned char %1024s = {",name) == 1)
       version=11;
-    else if (sscanf(buffer,"static char %1024s = {",name) == 1)
+    else if (MagickSscanf(buffer,"static char %1024s = {",name) == 1)
       version=11;
     else
       {
diff --git a/coders/xpm.c b/coders/xpm.c
index 1dda89f5d..68acc7428 100644
--- a/coders/xpm.c
+++ b/coders/xpm.c
@@ -69,6 +69,7 @@
 #include "MagickCore/splay-tree.h"
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/threshold.h"
 #include "MagickCore/token.h"
 #include "MagickCore/utility.h"
@@ -353,8 +354,8 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     if (*p != '"')
       continue;
     (void) GetNextToken(p,(const char **) NULL,MagickPathExtent,properties);
-    count=(ssize_t) sscanf(properties,"%lu %lu %lu %lu",&columns,&rows,&colors,
-      &width);
+    count=(ssize_t) MagickSscanf(properties,"%lu %lu %lu %lu",&columns,&rows,
+      &colors,&width);
     image->columns=columns;
     image->rows=rows;
     image->colors=colors;