GraphicsMagick: Add casts to prevent unnecessary value truncatio...

GraphicsMagick Commits <[email protected]> Sat, 21 Oct 2023 17:33:51 -0500
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.10685.1697927640.1961.graphicsmagick-commit@lists.sourceforge.net>
changeset 81427600ed1a in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=81427600ed1a
summary: Add casts to prevent unnecessary value truncation in WIN64 build

diffstat:

 Magick++/lib/Image.cpp   |   2 +-
 Magick++/lib/Options.cpp |   4 +-
 coders/bmp.c             |  66 ++++++++++++++++++++++++------------------------
 coders/dpx.c             |   8 ++--
 coders/jpeg.c            |   6 ++--
 coders/logo.c            |   8 ++--
 coders/mat.c             |  20 +++++++-------
 coders/miff.c            |  14 +++++-----
 coders/mpc.c             |   2 +-
 coders/msl.c             |  10 +++---
 coders/pcd.c             |  30 ++++++++++----------
 coders/pcx.c             |   2 +-
 coders/png.c             |  28 ++++++++++----------
 coders/sfw.c             |   4 +-
 coders/tiff.c            |   8 ++--
 coders/topol.c           |  26 +++++++++---------
 coders/txt.c             |   2 +-
 coders/wmf.c             |  12 ++++----
 coders/wpg.c             |   2 +-
 magick/colorspace.c      |  12 ++++----
 magick/gem.c             |   6 ++--
 tests/bitstream.c        |   4 +-
 wand/magick_wand.c       |   4 +-
 23 files changed, 140 insertions(+), 140 deletions(-)

diffs (truncated from 1126 to 500 lines):

diff -r ded17020a237 -r 81427600ed1a Magick++/lib/Image.cpp
--- a/Magick++/lib/Image.cpp	Sat Oct 21 18:40:01 2023 +0200
+++ b/Magick++/lib/Image.cpp	Sat Oct 21 17:33:39 2023 -0500
@@ -2377,7 +2377,7 @@
 void Magick::Image::cacheThreshold ( const unsigned int threshold_ )
 {
   (void) SetMagickResourceLimit(MemoryResource,threshold_);
-  (void) SetMagickResourceLimit(MapResource,2*threshold_);
+  (void) SetMagickResourceLimit(MapResource,(size_t)2*threshold_);
 }
 
 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
diff -r ded17020a237 -r 81427600ed1a Magick++/lib/Options.cpp
--- a/Magick++/lib/Options.cpp	Sat Oct 21 18:40:01 2023 +0200
+++ b/Magick++/lib/Options.cpp	Sat Oct 21 17:33:39 2023 -0500
@@ -506,7 +506,7 @@
       unsigned int x;
       for (x=0; strokeDashArray_[x]; x++) {};
       // Allocate elements
-      _drawInfo->dash_pattern = MagickAllocateMemory(double*,(x+1)*sizeof(double));
+      _drawInfo->dash_pattern = MagickAllocateMemory(double*,((size_t)x+1)*sizeof(double));
 
       if (!_drawInfo->dash_pattern)
         throwExceptionExplicit( ResourceLimitError,
@@ -515,7 +515,7 @@
       // Copy elements
       if (_drawInfo->dash_pattern)
         memcpy(_drawInfo->dash_pattern,strokeDashArray_,
-               (x+1)*sizeof(double));
+               ((size_t)x+1)*sizeof(double));
     }
 }
 const double* Magick::Options::strokeDashArray ( void ) const
diff -r ded17020a237 -r 81427600ed1a coders/bmp.c
--- a/coders/bmp.c	Sat Oct 21 18:40:01 2023 +0200
+++ b/coders/bmp.c	Sat Oct 21 17:33:39 2023 -0500
@@ -304,7 +304,7 @@
                 */
                 x=0;
                 y++;
-                q=pixels+y*image->columns;
+                q=pixels+y*(size_t) image->columns;
                 break;
               }
             case 0x02:
@@ -320,7 +320,7 @@
                 if (byte == EOF)
                   return MagickFail;
                 y+=byte;
-                q=pixels+y*image->columns+x;
+                q=pixels+y*(size_t) image->columns+x;
                 break;
               }
             default:
@@ -460,7 +460,7 @@
       /*
         Determine runlength.
       */
-      for (i=1; ((x+i) < bytes_per_line); i++)
+      for (i=1; (((size_t) x+i) < bytes_per_line); i++)
         if ((i == 255) || (*(p+i) != *p))
           break;
       *q++=(unsigned char) i;
@@ -1307,7 +1307,7 @@
           if ((offset < start_position) ||
               (SeekBlob(image,offset,SEEK_SET) != (magick_off_t) offset))
             ThrowBMPReaderException(CorruptImageError,ImproperImageHeader,image);
-          if (ReadBlob(image,packet_size*image->colors,(char *) bmp_colormap)
+          if (ReadBlob(image,(size_t) packet_size*image->colors,(char *) bmp_colormap)
               != (size_t) packet_size*image->colors)
             ThrowBMPReaderException(CorruptImageError,UnexpectedEndOfFile,image);
           p=bmp_colormap;
@@ -1435,7 +1435,7 @@
             DecodeImage() normally decompresses to rows*columns bytes of data.
           */
           status=DecodeImage(image,bmp_info.compression,pixels,
-                             image->rows*image->columns);
+                             (size_t) image->rows*image->columns);
           if (status == MagickFail)
             ThrowBMPReaderException(CorruptImageError,UnableToRunlengthDecodeImage,
                                     image);
@@ -1549,7 +1549,7 @@
             */
             for (y=(long) image->rows-1; y >= 0; y--)
               {
-                p=pixels+(image->rows-y-1)*bytes_per_line;
+                p=pixels+((size_t)image->rows-y-1)*bytes_per_line;
                 q=SetImagePixels(image,0,y,image->columns,1);
                 if (q == (PixelPacket *) NULL)
                   break;
@@ -1561,7 +1561,7 @@
                 if (image->previous == (Image *) NULL)
                   if (QuantumTick(y,image->rows))
                     {
-                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                      status=MagickMonitorFormatted((size_t)image->rows-y-1,image->rows,
                                                     exception,LoadImageText,
                                                     image->filename,
                                                     image->columns,image->rows);
@@ -1581,7 +1581,7 @@
               bytes_per_line=image->columns;
             for (y=(long) image->rows-1; y >= 0; y--)
               {
-                p=pixels+(image->rows-y-1)*bytes_per_line;
+                p=pixels+((size_t)image->rows-y-1)*bytes_per_line;
                 q=SetImagePixels(image,0,y,image->columns,1);
                 if (q == (PixelPacket *) NULL)
                   break;
@@ -1593,7 +1593,7 @@
                 if (image->previous == (Image *) NULL)
                   if (QuantumTick(y,image->rows))
                     {
-                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                      status=MagickMonitorFormatted((size_t)image->rows-y-1,image->rows,
                                                     exception,LoadImageText,
                                                     image->filename,
                                                     image->columns,image->rows);
@@ -1615,11 +1615,11 @@
                 bmp_info.compression != BI_BITFIELDS &&
                 bmp_info.compression != BI_ALPHABITFIELDS)
               ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression,image)
-                bytes_per_line=2*(image->columns+image->columns%2);
+                bytes_per_line=2*((size_t)image->columns+image->columns%2);
             image->storage_class=DirectClass;
             for (y=(long) image->rows-1; y >= 0; y--)
               {
-                p=pixels+(image->rows-y-1)*bytes_per_line;
+                p=pixels+((size_t)image->rows-y-1)*bytes_per_line;
                 q=SetImagePixels(image,0,y,image->columns,1);
                 if (q == (PixelPacket *) NULL)
                   break;
@@ -1658,7 +1658,7 @@
                 if (image->previous == (Image *) NULL)
                   if (QuantumTick(y,image->rows))
                     {
-                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                      status=MagickMonitorFormatted((size_t)image->rows-y-1,image->rows,
                                                     exception,LoadImageText,
                                                     image->filename,
                                                     image->columns,image->rows);
@@ -1673,10 +1673,10 @@
             /*
               Convert DirectColor scanline.
             */
-            bytes_per_line=4*((image->columns*24+31)/32);
+            bytes_per_line=4*(((size_t)image->columns*24+31)/32);
             for (y=(long) image->rows-1; y >= 0; y--)
               {
-                p=pixels+(image->rows-y-1)*bytes_per_line;
+                p=pixels+((size_t)image->rows-y-1)*bytes_per_line;
                 q=SetImagePixels(image,0,y,image->columns,1);
                 if (q == (PixelPacket *) NULL)
                   break;
@@ -1692,7 +1692,7 @@
                 if (image->previous == (Image *) NULL)
                   if (QuantumTick(y,image->rows))
                     {
-                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                      status=MagickMonitorFormatted((size_t)image->rows-y-1,image->rows,
                                                     exception,LoadImageText,
                                                     image->filename,
                                                     image->columns,image->rows);
@@ -1712,13 +1712,13 @@
                bmp_info.compression != BI_BITFIELDS &&
                bmp_info.compression != BI_ALPHABITFIELDS)
               ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression,image)
-                bytes_per_line=4*(image->columns);
+                bytes_per_line=4*((size_t) image->columns);
             for (y=(long) image->rows-1; y >= 0; y--)
               {
                 magick_uint32_t
                   pixel;
 
-                p=pixels+(image->rows-y-1)*bytes_per_line;
+                p=pixels+((size_t) image->rows-y-1)*bytes_per_line;
                 q=SetImagePixels(image,0,y,image->columns,1);
                 if (q == (PixelPacket *) NULL)
                   break;
@@ -1760,7 +1760,7 @@
                 if (image->previous == (Image *) NULL)
                   if (QuantumTick(y,image->rows))
                     {
-                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                      status=MagickMonitorFormatted((size_t)image->rows-y-1,image->rows,
                                                     exception,LoadImageText,
                                                     image->filename,
                                                     image->columns,image->rows);
@@ -1780,7 +1780,7 @@
             */
             for(y=(long) image->rows-1; y >= 0; y--)
               {
-                p = pixels+(image->rows-y-1)*bytes_per_line;
+                p = pixels+((size_t) image->rows-y-1)*bytes_per_line;
                 q = SetImagePixels(image,0,y,image->columns,1);
                 if(q == (PixelPacket *) NULL)
                   break;
@@ -1799,7 +1799,7 @@
                 if(image->previous == (Image *) NULL)
                   if(QuantumTick(y,image->rows))
                     {
-                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                      status=MagickMonitorFormatted((size_t)image->rows-y-1,image->rows,
                                                     exception,LoadImageText,
                                                     image->filename,
                                                     image->columns,image->rows);
@@ -1818,7 +1818,7 @@
             */
             for(y=(long) image->rows-1; y >= 0; y--)
               {
-                p = pixels+(image->rows-y-1)*bytes_per_line;
+                p = pixels+((size_t) image->rows-y-1)*bytes_per_line;
                 q = SetImagePixels(image,0,y,image->columns,1);
                 if(q == (PixelPacket *) NULL)
                   break;
@@ -1838,7 +1838,7 @@
                 if(image->previous == (Image *) NULL)
                   if(QuantumTick(y,image->rows))
                     {
-                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                      status=MagickMonitorFormatted((size_t) image->rows-y-1,image->rows,
                                                     exception,LoadImageText,
                                                     image->filename,
                                                     image->columns,image->rows);
@@ -2267,11 +2267,11 @@
               (void) SetImageType(image,TrueColorType);
             else
               {
-                bmp_info.file_size+=3U*(1U << bmp_info.bits_per_pixel);
+                bmp_info.file_size+=3U*(((size_t)1U) << bmp_info.bits_per_pixel);
                 bmp_info.offset_bits+=3U*(1U << bmp_info.bits_per_pixel);
                 if (type > 2)
                   {
-                    bmp_info.file_size+=(size_t) (1U << bmp_info.bits_per_pixel);
+                    bmp_info.file_size+=((size_t)1U << bmp_info.bits_per_pixel);
                     bmp_info.offset_bits+=(1U << bmp_info.bits_per_pixel);
                   }
               }
@@ -2404,14 +2404,14 @@
                                     "  Output %u-bit PseudoClass pixels",
                                     bmp_info.bits_per_pixel);
             ExportPixelAreaOptionsInit(&export_options);
-            export_options.pad_bytes=(unsigned long) (bytes_per_line - ((image->columns+7)/8));
+            export_options.pad_bytes=(unsigned long) (bytes_per_line - (((size_t) image->columns+7)/8));
             export_options.pad_value=0x00;
             for (y=0; y < image->rows; y++)
               {
                 p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
                 if (p == (const PixelPacket *) NULL)
                   break;
-                q=pixels+(image->rows-y-1)*bytes_per_line;
+                q=pixels+((size_t) image->rows-y-1)*bytes_per_line;
                 if (ExportImagePixelArea(image,IndexQuantum,1,q,&export_options,0)
                     == MagickFail)
                   {
@@ -2446,7 +2446,7 @@
                 p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
                 if (p == (const PixelPacket *) NULL)
                   break;
-                q=pixels+(image->rows-y-1)*bytes_per_line;
+                q=pixels+((size_t) image->rows-y-1)*bytes_per_line;
                 if (ExportImagePixelArea(image,IndexQuantum,4,q,&export_options,0)
                     == MagickFail)
                   {
@@ -2480,7 +2480,7 @@
                 p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
                 if (p == (const PixelPacket *) NULL)
                   break;
-                q=pixels+(image->rows-y-1)*bytes_per_line;
+                q=pixels+((size_t) image->rows-y-1)*bytes_per_line;
                 if (ExportImagePixelArea(image,IndexQuantum,8,q,&export_options,0)
                     == MagickFail)
                   {
@@ -2515,7 +2515,7 @@
                 p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
                 if (p == (const PixelPacket *) NULL)
                   break;
-                q=pixels+(image->rows-y-1)*bytes_per_line;
+                q=pixels+((size_t) image->rows-y-1)*bytes_per_line;
                 for (x=0; x < image->columns; x++)
                   {
                     *q++=ScaleQuantumToChar(p->blue);
@@ -2558,7 +2558,7 @@
             /*
               Convert run-length encoded raster pixels.
             */
-            length=2*(bytes_per_line+2)*(image->rows+2)+2;
+            length=2*(bytes_per_line+2)*((size_t)image->rows+2)+2;
             bmp_data=MagickAllocateResourceLimitedMemory(unsigned char *,length);
             if (bmp_data == (unsigned char *) NULL)
               {
@@ -2738,7 +2738,7 @@
               (void) LogMagickEvent(CoderEvent,GetMagickModule(),
                                   "  Colormap: %u entries",image->colors);
             bmp_colormap=MagickAllocateResourceLimitedArray(unsigned char *,4,
-                                                          (size_t) (1L << bmp_info.bits_per_pixel));
+                                                           ((size_t)1L << bmp_info.bits_per_pixel));
             if (bmp_colormap == (unsigned char *) NULL)
               {
                 MagickFreeResourceLimitedMemory(pixels);
@@ -2762,10 +2762,10 @@
                   *q++=(Quantum) 0x0;
                 }
             if (type <= 2)
-              (void) WriteBlob(image,3*(1UL << bmp_info.bits_per_pixel),
+              (void) WriteBlob(image,3*((size_t)1UL << bmp_info.bits_per_pixel),
                              (char *) bmp_colormap);
             else
-              (void) WriteBlob(image,4*(1UL << bmp_info.bits_per_pixel),
+              (void) WriteBlob(image,4*((size_t)1UL << bmp_info.bits_per_pixel),
                              (char *) bmp_colormap);
             MagickFreeResourceLimitedMemory(bmp_colormap);
           }
diff -r ded17020a237 -r 81427600ed1a coders/dpx.c
--- a/coders/dpx.c	Sat Oct 21 18:40:01 2023 +0200
+++ b/coders/dpx.c	Sat Oct 21 17:33:39 2023 -0500
@@ -699,7 +699,7 @@
           (packing_method == PackingMethodWordsFillMSB))
         {
           /* C.3 Three 10-bit samples per 32-bit word */
-          octets=(((((magick_int64_t) (rows*samples_per_row+2)/3)*sizeof(U32)*8)+31)/32)*sizeof(U32);
+          octets=((((((magick_int64_t) rows*samples_per_row+2)/3)* (magick_int64_t)sizeof(U32)*8)+31)/32)*sizeof(U32);
         }
       else
         {
@@ -2380,13 +2380,13 @@
                         "Maximum number of bits per sample in any element: %u",
                         max_bits_per_sample);
   map_Y=MagickAllocateResourceLimitedArray(Quantum *,
-                            MaxValueGivenBits(max_bits_per_sample)+1,
+                            (size_t)MaxValueGivenBits(max_bits_per_sample)+1,
                             sizeof(Quantum));
   if (map_Y == (Quantum *) NULL)
     ThrowDPXReaderException(ResourceLimitError,MemoryAllocationFailed,image);
 
   map_CbCr=MagickAllocateResourceLimitedArray(Quantum *,
-                               MaxValueGivenBits(max_bits_per_sample)+1,
+                               (size_t)MaxValueGivenBits(max_bits_per_sample)+1,
                                sizeof(Quantum));
   if (map_CbCr == (Quantum *) NULL)
     ThrowDPXReaderException(ResourceLimitError,MemoryAllocationFailed,image);
@@ -4338,7 +4338,7 @@
                               max_samples_per_pixel*sizeof(sample_t));
   if (samples == (sample_t *) NULL)
     ThrowDPXWriterException(ResourceLimitError,MemoryAllocationFailed,image);
-  (void) memset((void *) samples,0,max_samples_per_pixel*image->columns*
+  (void) memset((void *) samples,0,(size_t) max_samples_per_pixel*image->columns*
                 sizeof(sample_t));
   /*
     Allocate row scanline.
diff -r ded17020a237 -r 81427600ed1a coders/jpeg.c
--- a/coders/jpeg.c	Sat Oct 21 18:40:01 2023 +0200
+++ b/coders/jpeg.c	Sat Oct 21 17:33:39 2023 -0500
@@ -553,9 +553,9 @@
                                                                         \
     if (((_c = GetCharacter(jpeg_info)) != EOF) && (_c >= 0))           \
       {                                                                 \
-        length=_c*256;                                                  \
+        length=(size_t) _c*256;                                         \
         if (((_c = GetCharacter(jpeg_info)) != EOF) && (_c >= 0))       \
-          length+=_c;                                                   \
+          length+=(size_t)_c;                                           \
         else                                                            \
           length=0;                                                     \
       }                                                                 \
@@ -3097,7 +3097,7 @@
     Convert MIFF to JPEG raster pixels.
   */
   jpeg_pixels=MagickAllocateResourceLimitedArray(JSAMPLE *,
-    jpeg_info.input_components*image->columns,sizeof(JSAMPLE));
+      (size_t)jpeg_info.input_components*image->columns,sizeof(JSAMPLE));
   if (jpeg_pixels == (JSAMPLE *) NULL)
     {
       if (huffman_memory)
diff -r ded17020a237 -r 81427600ed1a coders/logo.c
--- a/coders/logo.c	Sat Oct 21 18:40:01 2023 +0200
+++ b/coders/logo.c	Sat Oct 21 17:33:39 2023 -0500
@@ -5281,17 +5281,17 @@
       (logo_image->columns*logo_image->rows < 4097))
     {
       (void) strlcpy(logo_image->magick,"PBM",sizeof(logo_image->magick));
-      length=((logo_image->columns*logo_image->rows)/8)+16;
+      length=(((size_t)logo_image->columns*logo_image->rows)/8)+16;
     }
   else if (LocaleCompare(image_info->magick,"ROSE") == 0)
     {
       (void) strlcpy(logo_image->magick,"PPM",sizeof(logo_image->magick));
-      length=3*logo_image->columns*logo_image->rows;
+      length=3* (size_t)logo_image->columns*logo_image->rows;
     }
   else
     {
       (void) strlcpy(logo_image->magick,"GIF",sizeof(logo_image->magick));
-      length=logo_image->columns*logo_image->rows;
+      length= (size_t)logo_image->columns*logo_image->rows;
     }
   blob=ImageToBlob(image_info,logo_image,&length,&image->exception);
   if (blob == (void *) NULL)
@@ -5314,7 +5314,7 @@
   p=(char *) blob;
   for (i=0; i < length ; i++)
   {
-    FormatString(buffer,"0x%02X%s",*p & 0xff, i+1 < length ? ", " : "");
+    FormatString(buffer,"0x%02X%s",*p & 0xff, (size_t)i+1 < length ? ", " : "");
     (void) WriteBlobString(image,buffer);
     if (((i+1) % 12) == 0)
       {
diff -r ded17020a237 -r 81427600ed1a coders/mat.c
--- a/coders/mat.c	Sat Oct 21 18:40:01 2023 +0200
+++ b/coders/mat.c	Sat Oct 21 17:33:39 2023 -0500
@@ -415,8 +415,8 @@
           ThrowException(exception,CorruptImageError, UnableToUncompressImage, orig->filename);
           return NULL;
         }
-      fwrite(decompress_block, 4096-zip_info.avail_out, 1, mat_file);
-      TotalSize += 4096-zip_info.avail_out;
+      fwrite(decompress_block, (size_t) 4096-zip_info.avail_out, 1, mat_file);
+      TotalSize += (size_t) 4096-zip_info.avail_out;
 
       if(zip_status == Z_STREAM_END) goto DblBreak;
     }
@@ -629,7 +629,7 @@
     if(HDR.Type[1]==0)          /* Find Min and Max Values for doubles */
     {
       if (MagickFindRawImageMinMax(image, import_options->endian, HDR.nRows,
-                                      HDR.nCols, DoublePixel, ldblk, BImgBuff,
+                                      HDR.nCols, DoublePixel, (unsigned int)ldblk, BImgBuff,
                                       &import_options->double_minvalue,
                                    &import_options->double_maxvalue) != MagickPass)
         goto skip_reading_current;
@@ -637,7 +637,7 @@
     if(HDR.Type[1]==1)          /* Find Min and Max Values for floats */
     {
       if (MagickFindRawImageMinMax(image, import_options->endian, HDR.nRows,
-                                      HDR.nCols, FloatPixel, ldblk, BImgBuff,
+                                      HDR.nCols, FloatPixel, (unsigned int)ldblk, BImgBuff,
                                       &import_options->double_minvalue,
                                       &import_options->double_maxvalue) != MagickPass)
         goto skip_reading_current;
@@ -685,7 +685,7 @@
       if(HDR.Type[1]==0)                /* Find Min and Max Values for doubles */
       {
         if (MagickFindRawImageMinMax(image, import_options->endian, HDR.nRows,
-                                     HDR.nCols, DoublePixel, ldblk, BImgBuff,
+                                     HDR.nCols, DoublePixel, (unsigned int)ldblk, BImgBuff,
                                      &MinVal_c, &MaxVal_c) != MagickPass)
           goto skip_reading_current;
         for(i=0; i<(long)HDR.nCols; i++)
@@ -702,7 +702,7 @@
       if(HDR.Type[1]==1)                /* Find Min and Max Values for floats */
       {
         if (MagickFindRawImageMinMax(image, import_options->endian, HDR.nRows,
-                                     HDR.nCols, FloatPixel, ldblk, BImgBuff,
+                                     HDR.nCols, FloatPixel, (unsigned int)ldblk, BImgBuff,
                                      &MinVal_c, &MaxVal_c) != MagickPass)
           goto skip_reading_current;
         for(i=0; i<(long)HDR.nCols; i++)
@@ -1154,7 +1154,7 @@
     if (CellType==miDOUBLE)        /* Find Min and Max Values for floats */
     {
       if (MagickFindRawImageMinMax(image2, import_options.endian,MATLAB_HDR.SizeX,
-                                   MATLAB_HDR.SizeY,DoublePixel, ldblk, BImgBuff,
+                                   MATLAB_HDR.SizeY,DoublePixel, (unsigned int)ldblk, BImgBuff,
                                    &import_options.double_minvalue,
                                    &import_options.double_maxvalue) != MagickPass)
         goto skip_reading_current;
@@ -1165,7 +1165,7 @@
     if (CellType==miSINGLE)        /* Find Min and Max Values for floats */
     {
       if (MagickFindRawImageMinMax(image2, import_options.endian,MATLAB_HDR.SizeX,
-                                   MATLAB_HDR.SizeY,FloatPixel, ldblk, BImgBuff,
+                                   MATLAB_HDR.SizeY,FloatPixel, (unsigned int)ldblk, BImgBuff,
                                    &import_options.double_minvalue,
                                    &import_options.double_maxvalue) != MagickPass)
         goto skip_reading_current;
@@ -1251,14 +1251,14 @@
       if (CellType==miDOUBLE)
       {
         if (MagickFindRawImageMinMax(image2, import_options.endian, MATLAB_HDR.SizeX,
-                                     MATLAB_HDR.SizeY, DoublePixel, ldblk, BImgBuff,
+                                     MATLAB_HDR.SizeY, DoublePixel, (unsigned int)ldblk, BImgBuff,
                                      &MinVal_c, &MaxVal_c) != MagickPass)
           ThrowImg2MATReaderException(CorruptImageError,UnexpectedEndOfFile,image);
       }
       if(CellType==miSINGLE)
       {
         if (MagickFindRawImageMinMax(image2, import_options.endian, MATLAB_HDR.SizeX,
-                                     MATLAB_HDR.SizeY, FloatPixel, ldblk, BImgBuff,
+                                     MATLAB_HDR.SizeY, FloatPixel, (unsigned int)ldblk, BImgBuff,
                                      &MinVal_c, &MaxVal_c)  != MagickPass)
           ThrowImg2MATReaderException(CorruptImageError,UnexpectedEndOfFile,image);
       }
diff -r ded17020a237 -r 81427600ed1a coders/miff.c
--- a/coders/miff.c	Sat Oct 21 18:40:01 2023 +0200
+++ b/coders/miff.c	Sat Oct 21 17:33:39 2023 -0500
@@ -1106,7 +1106,7 @@
                       ThrowMIFFReaderException(CorruptImageError,ImproperImageHeader,image);
                     i=number_of_profiles;
                     new_profiles=MagickReallocateResourceLimitedArray(ProfileInfo *,profiles,
-                                                                      number_of_profiles+1,sizeof(ProfileInfo));
+                                                                     (size_t)number_of_profiles+1,sizeof(ProfileInfo));