GraphicsMagick: coders/tiff.c Fix sign comparison warning.

GraphicsMagick Commits <[email protected]> Sat, 27 Jan 2024 09:06:43 -0600
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.6717.1706368019.16032.graphicsmagick-commit@lists.sourceforge.net>
changeset b7d6c142161e in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=b7d6c142161e
summary: coders/tiff.c Fix sign comparison warning.

diffstat:

 coders/tiff.c |  35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)

diffs (48 lines):

diff -r da696c4cff69 -r b7d6c142161e coders/tiff.c
--- a/coders/tiff.c	Sat Jan 27 15:13:41 2024 +0100
+++ b/coders/tiff.c	Sat Jan 27 16:06:20 2024 +0100
@@ -4647,23 +4647,30 @@
                          if(FDT!=TIFF_RATIONAL) break;
                          if(WriteCount!=1)
                          {
-                           if(WriteCount!=TIFF_VARIABLE && WriteCount!=TIFF_VARIABLE2)
+                           if(WriteCount>0)
                            {
-                             if(WriteCount>0)
+                             double *ArrayD;
+                             magick_uint32_t i;
+                             if(Long2<(magick_uint32_t)WriteCount) break;		/* Too small amount of mandatory items. */
+                             if(Value+8*WriteCount>=profile_length-1) break;
+                             ArrayD = MagickAllocateResourceLimitedMemory(double *, sizeof(double)*WriteCount);
+                             if(ArrayD==NULL) break;
+                             for(i=0; i<WriteCount; i++)
                              {
-                               double *ArrayD;
-                               magick_uint32_t i;
-                               if(Long2<WriteCount) break;		/* Too small amount of mandatory items. */
-                               if(Value+8*WriteCount>=profile_length-1) break;
-                               ArrayD = MagickAllocateResourceLimitedMemory(double *, sizeof(double)*WriteCount);
-                               if(ArrayD==NULL) break;
-                               for(i=0; i<WriteCount; i++)
-                                   ArrayD[i] = LD_UINT32(profile_data+Value+8*i) / (double)LD_UINT32(profile_data+Value+4+8*i);
-                               if(TIFFSetField(tiff, Tag, ArrayD))
-                                   FieldCount++;
-                               MagickFreeResourceLimitedMemory(ArrayD);
-                               break;
+                               const magick_uint32_t val = LD_UINT32(profile_data+Value+4+8*i);
+                               ArrayD[i] = (val==0) ? 0.0 : (LD_UINT32(profile_data+Value+8*i) / (double)val);
                              }
+                             if(TIFFSetField(tiff, Tag, ArrayD))
+                                 FieldCount++;
+                             MagickFreeResourceLimitedMemory(ArrayD);
+                             break;
+                           }
+
+                           if(WriteCount==TIFF_VARIABLE || WriteCount==TIFF_VARIABLE2)
+                           {
+                             if(logging && (Flags & FLAG_BASE)!=0)
+                                 (void)LogMagickEvent(CoderEvent,GetMagickModule(),"Variable size fractional arrays are not supported yet.");
+                             break;
                            }
                            break;
                          }