GraphicsMagick: ReadXPMImage() More work on Coverity issue 38186...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.14828.1667948096.1350.graphicsmagick-commit@lists.sourceforge.net>
changeset 819c2c57d38c in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=819c2c57d38c
summary: ReadXPMImage() More work on Coverity issue 381862 "(DEADCODE)"

diffstat:

 ChangeLog          |   3 +++
 coders/xpm.c       |  43 +++++++++++++++++++++----------------------
 www/Changelog.html |   2 ++
 3 files changed, 26 insertions(+), 22 deletions(-)

diffs (113 lines):

diff -r 57db798fa1b8 -r 819c2c57d38c ChangeLog
--- a/ChangeLog	Tue Nov 08 15:33:17 2022 -0600
+++ b/ChangeLog	Tue Nov 08 16:54:45 2022 -0600
@@ -1,5 +1,8 @@
 2022-11-08  Bob Friesenhahn  <[email protected]>
 
+	* coders/xpm.c (ReadXPMImage): More work on Coverity issue 381862
+	"(DEADCODE)".
+
 	* magick/operator.c (QuantumLogCB): Fix Coverity issue 381861
 	"Control flow issues (DEADCODE)".
 
diff -r 57db798fa1b8 -r 819c2c57d38c coders/xpm.c
--- a/coders/xpm.c	Tue Nov 08 15:33:17 2022 -0600
+++ b/coders/xpm.c	Tue Nov 08 16:54:45 2022 -0600
@@ -50,7 +50,7 @@
 #include "magick/utility.h"
 
 
-#define MAX_XPM_SUPPORTED_COLORS	Max(0x20000,MaxColormapSize)
+#define MAX_XPM_SUPPORTED_COLORS        Max(0x20000,MaxColormapSize)
 
 /*
   Forward declarations.
@@ -375,7 +375,7 @@
       (image->columns == 0) || (image->rows == 0) ||
       (image->colors == 0))
     ThrowXPMReaderException(CorruptImageError,ImproperImageHeader,image);
-  if(image->colors > MAX_XPM_SUPPORTED_COLORS)
+  if (image->colors > MAX_XPM_SUPPORTED_COLORS)
     ThrowXPMReaderException(CoderError,ColormapTooLarge,image);
   image->depth=16;
 
@@ -447,19 +447,20 @@
       keys[i].index=0;
       keys[i].keyval=0;
     }
-  if(image->colors <= MaxColormapSize)
-  {
-    if (!AllocateImageColormap(image,image->colors))
-      ThrowXPMReaderException(ResourceLimitError,MemoryAllocationFailed,image);
-  }
-  else		/* Allocate temporary palette. */
-  {
-    if(image->colormap != (PixelPacket *)NULL)
+  if (image->colors <= MaxColormapSize)
+    {
+      if (!AllocateImageColormap(image,image->colors))
+        ThrowXPMReaderException(ResourceLimitError,MemoryAllocationFailed,image);
+    }
+  else
+    {
+      /* Allocate temporary palette. */
+      if (image->colormap != (PixelPacket *)NULL)
         MagickFreeMemory(image->colormap);
-    image->colormap=MagickAllocateMemory(PixelPacket *,MagickArraySize((size_t) image->colors,sizeof(PixelPacket)));
-    if(image->colormap==NULL)
-      ThrowXPMReaderException(ResourceLimitError,MemoryAllocationFailed,image);
-  }
+      image->colormap=MagickAllocateMemory(PixelPacket *,MagickArraySize((size_t) image->colors,sizeof(PixelPacket)));
+      if (image->colormap==NULL)
+        ThrowXPMReaderException(ResourceLimitError,MemoryAllocationFailed,image);
+    }
 
   /*
     Read image colormap.
@@ -603,7 +604,6 @@
                 {
                   if (p[k] == '\0')
                     {
-                      status=MagickFail;
                       (void) LogMagickEvent(CoderEvent,GetMagickModule(),
                                             "Unexpected end of row %ld! (k=%u)", y, k);
                       ThrowXPMReaderException(CorruptImageError,UnexpectedEndOfFile,
@@ -612,8 +612,6 @@
                     }
                   keyval |= ((xpmkeyval_t) p[k]) << (k * 8);
                 }
-              if (MagickFail == status)
-                break;
               if (keyval != key.keyval)
                 {
                   key.keyval = keyval;
@@ -656,11 +654,12 @@
   MagickFreeResourceLimitedMemory(textlist);
   MagickFreeResourceLimitedMemory(xpm_buffer);
   if (image->colors > MaxColormapSize)
-  {					/* Release temporary palette. */
-    MagickFreeMemory(image->colormap);
-    image->colors = 0;
-    image->storage_class = DirectClass;
-  }
+    {
+      /* Release temporary palette. */
+      MagickFreeMemory(image->colormap);
+      image->colors = 0;
+      image->storage_class = DirectClass;
+    }
   CloseBlob(image);
   StopTimer(&image->timer);
   return(image);
diff -r 57db798fa1b8 -r 819c2c57d38c www/Changelog.html
--- a/www/Changelog.html	Tue Nov 08 15:33:17 2022 -0600
+++ b/www/Changelog.html	Tue Nov 08 16:54:45 2022 -0600
@@ -40,6 +40,8 @@
 <p>2022-11-08  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 <ul class="simple">
+<li><p>coders/xpm.c (ReadXPMImage): More work on Coverity issue 381862
+&quot;(DEADCODE)&quot;.</p></li>
 <li><p>magick/operator.c (QuantumLogCB): Fix Coverity issue 381861
 &quot;Control flow issues (DEADCODE)&quot;.</p></li>
 <li><p>coders/xpm.c (ReadXPMImage): Fix Coverity issue 381862
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.