libtiff: warning fixes, tidy-up. use 4.2.0 types and macros.

From 8deaa5758560cfaa52661ff4b9d3d17e19621180 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 21 Oct 2023 23:33:32 +0300
Subject: [PATCH] warning fixes, tidy-up. use 4.2.0 types and macros.

---
 libtiff/tif_dir.c  | 12 +++---
 libtiff/tif_lzma.c |  2 +-
 libtiff/tif_webp.c |  4 +-
 tools/tiff2pdf.c   |  4 +-
 tools/tiffcrop.c   | 91 ++++++++++++++++++++++------------------------
 tools/tiffset.c    |  3 +-
 6 files changed, 54 insertions(+), 62 deletions(-)

diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c
index 0b8fc773..38ddedee 100644
--- a/libtiff/tif_dir.c
+++ b/libtiff/tif_dir.c
@@ -31,8 +31,6 @@
 #include "tiffiop.h"
 #include <float.h>	/*--: for Rational2Double */
 
-#include <inttypes.h>
-
 /*
  * These are used in the backwards compatibility code...
  */
@@ -162,7 +160,7 @@ countInkNamesString(TIFF *tif, uint32 slen, const char *s)
 	}
 bad:
 	TIFFErrorExt(tif->tif_clientdata, "TIFFSetField",
-	    "%s: Invalid InkNames value; no NUL at given buffer end location %"PRIu32", after %"PRIu16" ink",
+	    "%s: Invalid InkNames value; no NUL at given buffer end location %u, after %u ink",
             tif->tif_name, slen, i);
 	return (0);
 }
@@ -491,7 +489,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
 				{
 					if (td->td_numberofinks != ninksinstring) {
 						TIFFErrorExt(tif->tif_clientdata, module,
-							"Warning %s; Tag %s:\n  Value %"PRIu16" of NumberOfInks is different from the number of inks %"PRIu16".\n  -> NumberOfInks value adapted to %"PRIu16"",
+							"Warning %s; Tag %s:\n  Value %u of NumberOfInks is different from the number of inks %u.\n  -> NumberOfInks value adapted to %u",
 							tif->tif_name, fip->field_name, td->td_numberofinks, ninksinstring, ninksinstring);
 						td->td_numberofinks = ninksinstring;
 					}
@@ -503,7 +501,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
 				{
 					if (td->td_numberofinks != td->td_samplesperpixel) {
 						TIFFErrorExt(tif->tif_clientdata, module,
-							"Warning %s; Tag %s:\n  Value %"PRIu16" of NumberOfInks is different from the SamplesPerPixel value %"PRIu16"",
+							"Warning %s; Tag %s:\n  Value %u of NumberOfInks is different from the SamplesPerPixel value %u",
 							tif->tif_name, fip->field_name, td->td_numberofinks, td->td_samplesperpixel);
 					}
 				}
@@ -517,7 +515,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
 		{
 			if (v != td->td_numberofinks) {
 				TIFFErrorExt(tif->tif_clientdata, module,
-					"Error %s; Tag %s:\n  It is not possible to set the value %"PRIu32" for NumberOfInks\n  which is different from the number of inks in the InkNames tag (%"PRIu16")",
+					"Error %s; Tag %s:\n  It is not possible to set the value %u for NumberOfInks\n  which is different from the number of inks in the InkNames tag (%u)",
 					tif->tif_name, fip->field_name, v, td->td_numberofinks);
 				/* Do not set / overwrite number of inks already set by InkNames case accordingly. */
 				status = 0;
@@ -528,7 +526,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
 			{
 				if (td->td_numberofinks != td->td_samplesperpixel) {
 					TIFFErrorExt(tif->tif_clientdata, module,
-						"Warning %s; Tag %s:\n  Value %"PRIu32" of NumberOfInks is different from the SamplesPerPixel value %"PRIu16"",
+						"Warning %s; Tag %s:\n  Value %u of NumberOfInks is different from the SamplesPerPixel value %u",
 						tif->tif_name, fip->field_name, v, td->td_samplesperpixel);
 				}
 			}
diff --git a/libtiff/tif_lzma.c b/libtiff/tif_lzma.c
index e150bd63..7b153943 100644
--- a/libtiff/tif_lzma.c
+++ b/libtiff/tif_lzma.c
@@ -185,7 +185,7 @@ LZMADecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
 		 * Save the current stream state to properly recover from the
 		 * decoding errors later.
 		 */
-		const uint8_t *next_in = sp->stream.next_in;
+		const uint8 *next_in = sp->stream.next_in;
 		size_t avail_in = sp->stream.avail_in;
 
 		lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN);
diff --git a/libtiff/tif_webp.c b/libtiff/tif_webp.c
index a00478f6..b7eac379 100644
--- a/libtiff/tif_webp.c
+++ b/libtiff/tif_webp.c
@@ -71,7 +71,7 @@ static int TWebPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
 static int TWebPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
 
 static
-int TWebPDatasetWriter(const uint8_t* data, size_t data_size,
+int TWebPDatasetWriter(const uint8* data, size_t data_size,
                       const WebPPicture* const picture)
 {
   static const char module[] = "TWebPDatasetWriter";
@@ -153,7 +153,7 @@ TWebPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
     return 0;
   } else {
     int current_y, stride;
-    uint8_t* buf;
+    uint8* buf;
 
     /* Returns the RGB/A image decoded so far */
     buf = WebPIDecGetRGB(sp->psDecoder, &current_y, NULL, NULL, &stride);
diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c
index acaef0d6..db45b59c 100644
--- a/tools/tiff2pdf.c
+++ b/tools/tiff2pdf.c
@@ -1021,6 +1021,7 @@ void t2p_free(T2P* t2p)
 */
 
 void t2p_validate(T2P* t2p){
+	(void)t2p;
 
 #ifdef JPEG_SUPPORT
 	if(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){
@@ -1049,7 +1050,6 @@ void t2p_validate(T2P* t2p){
 		if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}
 	}
 #endif
-	(void)0;
 
 	return;
 }
@@ -3331,7 +3331,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
 
 	if (TIFFStripSize(output) > t2p->tiff_datasize) {
 		TIFFError(TIFF2PDF_MODULE,
-		         "Size mismatch input %ld, output %ld",
+		         "Size mismatch input " TIFF_SSIZE_FORMAT ", output " TIFF_SSIZE_FORMAT,
 		          t2p->tiff_datasize, TIFFStripSize(output));
 		_TIFFfree(buffer);
 		t2p->t2p_error = T2P_ERR_ERROR;
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
index 57d7d259..132fb0e0 100644
--- a/tools/tiffcrop.c
+++ b/tools/tiffcrop.c
@@ -124,10 +124,6 @@ static   char tiffcrop_rev_date[] = "03-03-2010";
 # include <unistd.h>
 #endif
 
-#ifdef HAVE_STDINT_H
-# include <inttypes.h>
-#endif
-
 #ifndef EXIT_SUCCESS
 #define EXIT_SUCCESS 0
 #endif
@@ -1243,13 +1239,13 @@ writeBufferToSeparateStrips (TIFF* out, uint8* buf,
         {
           if (scanlinesize > 0x0ffffffffULL) {
               dump_info(dump->infile, dump->format, "loadImage",
-                  "Attention: scanlinesize %"PRIu64" is larger than UINT32_MAX.\nFollowing dump might be wrong.",
+                  "Attention: scanlinesize " TIFF_SSIZE_FORMAT " is larger than UINT32_MAX.\nFollowing dump might be wrong.",
                   scanlinesize);
           }
           dump_info(dump->outfile, dump->format,"",
-                  "Sample %2d, Strip: %2d, bytes: %4d, Row %4d, bytes: %4d, Input offset: %6d", 
-                  s + 1, strip + 1, stripsize, row + 1, (uint32_t)scanlinesize, src - buf);
-        dump_buffer(dump->outfile, dump->format, nrows, (uint32_t)scanlinesize, row, obuf);
+                  "Sample %2d, Strip: %2d, bytes: %4d, Row %4d, bytes: %4d, Input offset: %6d",
+                  s + 1, strip + 1, stripsize, row + 1, (uint32)scanlinesize, src - buf);
+        dump_buffer(dump->outfile, dump->format, nrows, (uint32)scanlinesize, row, obuf);
 	}
 
       if (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0)
@@ -3219,13 +3215,13 @@ extractContigSamples32bits (uint8 *in, uint8 *out, uint32 cols,
       /* If we have a full buffer's worth, write it out */
       if (ready_bits >= 32)
         {
-        bytebuff1 = (uint8_t)(buff2 >> 56);
+        bytebuff1 = (uint8)(buff2 >> 56);
         *dst++ = bytebuff1;
-        bytebuff2 = (uint8_t)(buff2 >> 48);
+        bytebuff2 = (uint8)(buff2 >> 48);
         *dst++ = bytebuff2;
-        bytebuff3 = (uint8_t)(buff2 >> 40);
+        bytebuff3 = (uint8)(buff2 >> 40);
         *dst++ = bytebuff3;
-        bytebuff4 = (uint8_t)(buff2 >> 32);
+        bytebuff4 = (uint8)(buff2 >> 32);
         *dst++ = bytebuff4;
         ready_bits -= 32;
                     
@@ -3600,13 +3596,13 @@ extractContigSamplesShifted32bits (uint8 *in, uint8 *out, uint32 cols,
         }
       else  /* If we have a full buffer's worth, write it out */
         {
-        bytebuff1 = (uint8_t)(buff2 >> 56);
+        bytebuff1 = (uint8)(buff2 >> 56);
         *dst++ = bytebuff1;
-        bytebuff2 = (uint8_t)(buff2 >> 48);
+        bytebuff2 = (uint8)(buff2 >> 48);
         *dst++ = bytebuff2;
-        bytebuff3 = (uint8_t)(buff2 >> 40);
+        bytebuff3 = (uint8)(buff2 >> 40);
         *dst++ = bytebuff3;
-        bytebuff4 = (uint8_t)(buff2 >> 32);
+        bytebuff4 = (uint8)(buff2 >> 32);
         *dst++ = bytebuff4;
         ready_bits -= 32;
                     
@@ -3799,13 +3795,12 @@ static int readContigStripsIntoBuffer (TIFF* in, uint8* buf)
                 bytes_read = TIFFReadEncodedStrip (in, strip, bufp, -1);
                 rows = bytes_read / scanline_size;
                 if ((strip < (nstrips - 1)) && (bytes_read != (int32)stripsize))
-                        TIFFError("", "Strip %"PRIu32": read %"PRId64" bytes, strip size %"PRIu64,
-                                  (int)strip + 1, (unsigned long) bytes_read,
-                                  (unsigned long)stripsize);
+                        TIFFError("", "Strip %u: read " TIFF_SSIZE_FORMAT " bytes, strip size " TIFF_SSIZE_FORMAT,
+                                  strip + 1, bytes_read, stripsize);
 
                 if (bytes_read < 0 && !ignore) {
-                        TIFFError("", "Error reading strip %"PRIu32" after %"PRIu64" rows",
-                                  (unsigned long) strip, (unsigned long)rows);
+                        TIFFError("", "Error reading strip %u after " TIFF_SSIZE_FORMAT " rows",
+                                  strip, rows);
                         return 0;
                 }
                 bufp += stripsize;
@@ -4269,13 +4264,13 @@ combineSeparateSamples32bits (uint8 *in[], uint8 *out, uint32 cols,
 	/* If we have a full buffer's worth, write it out */
 	if (ready_bits >= 32)
 	  {
-	  bytebuff1 = (uint8_t)(buff2 >> 56);
+	  bytebuff1 = (uint8)(buff2 >> 56);
 	  *dst++ = bytebuff1;
-	  bytebuff2 = (uint8_t)(buff2 >> 48);
+	  bytebuff2 = (uint8)(buff2 >> 48);
 	  *dst++ = bytebuff2;
-	  bytebuff3 = (uint8_t)(buff2 >> 40);
+	  bytebuff3 = (uint8)(buff2 >> 40);
 	  *dst++ = bytebuff3;
-	  bytebuff4 = (uint8_t)(buff2 >> 32);
+	  bytebuff4 = (uint8)(buff2 >> 32);
 	  *dst++ = bytebuff4;
 	  ready_bits -= 32;
                     
@@ -4794,13 +4789,13 @@ combineSeparateTileSamples32bits (uint8 *in[], uint8 *out, uint32 cols,
 	/* If we have a full buffer's worth, write it out */
 	if (ready_bits >= 32)
 	  {
-	  bytebuff1 = (uint8_t)(buff2 >> 56);
+	  bytebuff1 = (uint8)(buff2 >> 56);
 	  *dst++ = bytebuff1;
-	  bytebuff2 = (uint8_t)(buff2 >> 48);
+	  bytebuff2 = (uint8)(buff2 >> 48);
 	  *dst++ = bytebuff2;
-	  bytebuff3 = (uint8_t)(buff2 >> 40);
+	  bytebuff3 = (uint8)(buff2 >> 40);
 	  *dst++ = bytebuff3;
-	  bytebuff4 = (uint8_t)(buff2 >> 32);
+	  bytebuff4 = (uint8)(buff2 >> 32);
 	  *dst++ = bytebuff4;
 	  ready_bits -= 32;
                     
@@ -4958,7 +4953,7 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length,
       buff = srcbuffs[s];
       strip = (s * strips_per_sample) + j; 
       bytes_read = TIFFReadEncodedStrip (in, strip, buff, stripsize);
-      rows_this_strip = (uint32_t)(bytes_read / src_rowsize);
+      rows_this_strip = (uint32)(bytes_read / src_rowsize);
       if (bytes_read < 0 && !ignore)
         {
         TIFFError(TIFFFileName(in),
@@ -6385,11 +6380,11 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c
 
     if (scanlinesize > 0x0ffffffffULL) {
         dump_info(dump->infile, dump->format, "loadImage",
-            "Attention: scanlinesize %"PRIu64" is larger than UINT32_MAX.\nFollowing dump might be wrong.",
+            "Attention: scanlinesize " TIFF_SSIZE_FORMAT " is larger than UINT32_MAX.\nFollowing dump might be wrong.",
             scanlinesize);
     }
     for (i = 0; i < length; i++)
-      dump_buffer(dump->infile, dump->format, 1, (uint32_t)scanlinesize, 
+      dump_buffer(dump->infile, dump->format, 1, (uint32)scanlinesize,
                   i, read_buff + (i * scanlinesize));
     }
   return (0);
@@ -6420,7 +6415,7 @@ static int  correct_orientation(struct image_data *image, unsigned char **work_b
 
   if (image->adjustments & ROTATE_ANY)
     {
-    uint32_t width, length;
+    uint32 width, length;
     if (image->adjustments & ROTATECW_90)
       rotation = (uint16) 90;
     else
@@ -6504,9 +6499,9 @@ extractCompositeRegions(struct image_data *image,  struct crop_mask *crop,
         case EDGE_BOTTOM:
             for (i = 1; i < crop->selections; i++)
             {
-                uint32_t crop_width0 =
+                uint32 crop_width0 =
                     crop->regionlist[i - 1].x2 - crop->regionlist[i - 1].x1 + 1;
-                uint32_t crop_width1 =
+                uint32 crop_width1 =
                     crop->regionlist[i].x2 - crop->regionlist[i].x1 + 1;
                 if (crop_width0 != crop_width1)
                 {
@@ -6521,9 +6516,9 @@ extractCompositeRegions(struct image_data *image,  struct crop_mask *crop,
         case EDGE_RIGHT:
             for (i = 1; i < crop->selections; i++)
             {
-                uint32_t crop_length0 =
+                uint32 crop_length0 =
                     crop->regionlist[i - 1].y2 - crop->regionlist[i - 1].y1 + 1;
-                uint32_t crop_length1 =
+                uint32 crop_length1 =
                     crop->regionlist[i].y2 - crop->regionlist[i].y1 + 1;
                 if (crop_length0 != crop_length1)
                 {
@@ -6980,7 +6975,7 @@ extractImageSection(struct image_data *image, struct pageseg *section,
         sprintf(&bitarray[j], (bitset) ? "1" : "0");
         }
       bitarray[18] = '\0';
-      TIFFError ("", "Row: %3d Offset1: %"PRIu32",  Shift1: %"PRIu32",    Offset2: %"PRIu32",  Trailing_bits:  %"PRIu32"\n", 
+      TIFFError ("", "Row: %3d Offset1: %u,  Shift1: %u,    Offset2: %u,  Trailing_bits:  %u\n",
                  row, offset1, shift1, offset1+full_bytes, trailing_bits); 
 #endif
 
@@ -7053,11 +7048,11 @@ extractImageSection(struct image_data *image, struct pageseg *section,
         if (trailing_bits != 0)
           {
 #ifdef DEVELMODE
-          TIFFError("", "        Trailing bits %4"PRIu32"   src offset: %8"PRIu32", Dst offset: %8"PRIu32"\n", trailing_bits, offset1 + full_bytes, dst_offset);
+          TIFFError("", "        Trailing bits %4u   src offset: %8u, Dst offset: %8u\n", trailing_bits, offset1 + full_bytes, dst_offset);
 #endif
           /* More than necessary bits are already copied into last destination buffer, 
            * only masking of last byte in destination buffer is necessary.*/ 
-          sect_buff[dst_offset] &= ((uint8_t)0xFF << (8 - trailing_bits));
+          sect_buff[dst_offset] &= ((uint8)0xFF << (8 - trailing_bits));
             }
 #ifdef DEVELMODE
 	  sprintf(&bitarray[28], " ");
@@ -8535,13 +8530,13 @@ rotateContigSamples32bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width,
         }
       else /* If we have a full buffer's worth, write it out */
         {
-        bytebuff1 = (uint8_t)(buff2 >> 56);
+        bytebuff1 = (uint8)(buff2 >> 56);
         *dst++ = bytebuff1;
-        bytebuff2 = (uint8_t)(buff2 >> 48);
+        bytebuff2 = (uint8)(buff2 >> 48);
         *dst++ = bytebuff2;
-        bytebuff3 = (uint8_t)(buff2 >> 40);
+        bytebuff3 = (uint8)(buff2 >> 40);
         *dst++ = bytebuff3;
-        bytebuff4 = (uint8_t)(buff2 >> 32);
+        bytebuff4 = (uint8)(buff2 >> 32);
         *dst++ = bytebuff4;
         ready_bits -= 32;
                     
@@ -9152,13 +9147,13 @@ reverseSamples32bits (uint16 spp, uint16 bps, uint32 width,
         }
       else /* If we have a full buffer's worth, write it out */
         {
-        bytebuff1 = (uint8_t)(buff2 >> 56);
+        bytebuff1 = (uint8)(buff2 >> 56);
         *dst++ = bytebuff1;
-        bytebuff2 = (uint8_t)(buff2 >> 48);
+        bytebuff2 = (uint8)(buff2 >> 48);
         *dst++ = bytebuff2;
-        bytebuff3 = (uint8_t)(buff2 >> 40);
+        bytebuff3 = (uint8)(buff2 >> 40);
         *dst++ = bytebuff3;
-        bytebuff4 = (uint8_t)(buff2 >> 32);
+        bytebuff4 = (uint8)(buff2 >> 32);
         *dst++ = bytebuff4;
         ready_bits -= 32;
                     
diff --git a/tools/tiffset.c b/tools/tiffset.c
index 1330d828..e1f10c4f 100644
--- a/tools/tiffset.c
+++ b/tools/tiffset.c
@@ -32,7 +32,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdint.h>
 
 #include "tiffio.h"
 
@@ -152,7 +151,7 @@ main(int argc, char* argv[])
                 if(TIFFFieldPassCount( fip )) {
                     size_t len;
                     len = strlen(argv[arg_index]) + 1;
-                    if (len > UINT16_MAX || TIFFSetField(tiff, TIFFFieldTag(fip),
+                    if (len > 0xffff || TIFFSetField(tiff, TIFFFieldTag(fip),
                             (uint16)len, argv[arg_index]) != 1)
                         fprintf( stderr, "Failed to set %s=%s\n",
                             TIFFFieldName(fip), argv[arg_index] );