libtiff: Change "long" to "int32_t" in two test apps, because can be either int32_t or int64_t, depending on compiler and system.

From 12140bfdb27ecfede41eb3f087f69926d0a87a03 Mon Sep 17 00:00:00 2001
From: Su_Laus <[EMAIL REDACTED]>
Date: Sun, 23 Jul 2023 13:50:14 +0200
Subject: [PATCH] Change "long" to "int32_t" in two test apps, because can be
 either int32_t or int64_t, depending on compiler and system.

---
 test/custom_dir_EXIF_231.c       | 110 +++++++++++++++----------------
 test/rational_precision2double.c |  24 +++----
 2 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/test/custom_dir_EXIF_231.c b/test/custom_dir_EXIF_231.c
index 1e8df768..eef88375 100644
--- a/test/custom_dir_EXIF_231.c
+++ b/test/custom_dir_EXIF_231.c
@@ -164,15 +164,15 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
     char auxChar = 0;
     uint32_t auxUint32 = 0;
     short auxShort = 0;
-    long auxLong = 0;
+    int32_t auxInt32 = 0;
     void *pVoid;
     int blnIsRational2Double;
 
     int i, j;
-    long nTags;
+    int32_t nTags;
 
     const TIFFFieldArray *tFieldArray;
-    unsigned long tTag;
+    uint32_t tTag;
     TIFFDataType tType;
     short tWriteCount;
     TIFFSetGetFieldType tSetFieldType;
@@ -188,7 +188,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
     /* -- Test data for writing -- */
     char auxCharArrayW[N_SIZE];
     short auxShortArrayW[N_SIZE];
-    long auxLongArrayW[N_SIZE];
+    int32_t auxInt32ArrayW[N_SIZE];
     float auxFloatArrayW[N_SIZE];
     double auxDoubleArrayW[N_SIZE];
     char auxTextArrayW[N_SIZE][STRSIZE];
@@ -207,11 +207,11 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
     uint16_t count16 = 0;
     union
     {
-        long Long;
+        int32_t Int32;
         short Short1;
         short Short2[2];
         char Char[4];
-    } unionLong;
+    } unionInt32;
     union
     {
         double dbl;
@@ -222,7 +222,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
     char *pAscii;
     char auxCharArray[2 * STRSIZE];
     short auxShortArray[2 * N_SIZE];
-    long auxLongArray[2 * N_SIZE];
+    int32_t auxInt32Array[2 * N_SIZE];
     float auxFloatArray[2 * N_SIZE];
     double auxDoubleArray[2 * N_SIZE];
     double dblDiff, dblDiffLimit;
@@ -245,7 +245,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
     }
     for (i = 0; i < N_SIZE; i++)
     {
-        auxLongArrayW[i] = (i + 1) * 133;
+        auxInt32ArrayW[i] = (i + 1) * 133;
     }
     for (i = 0; i < N_SIZE; i++)
     {
@@ -352,8 +352,8 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
     }
 
     /*- TIFFTAG_YCBCRPOSITIONING is a SHORT parameter */
-    auxLong = auxShort = 5;
-    if (!TIFFSetField(tif, TIFFTAG_YCBCRPOSITIONING, auxLong))
+    auxInt32 = auxShort = 5;
+    if (!TIFFSetField(tif, TIFFTAG_YCBCRPOSITIONING, auxInt32))
     {
         fprintf(stderr, "Can't set TIFFTAG_YCBCRPOSITIONING tag.\n");
         goto failure;
@@ -736,11 +736,11 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                 /* Shorter strings than in auxTextArraxW need a
                  * NULL-termination. Therefore copy the string. */
                 if (tWriteCount > 0)
-                    auxLong = tWriteCount - 1;
+                    auxInt32 = tWriteCount - 1;
                 else
-                    auxLong = (long)strlen(auxTextArrayW[i]) - 1;
-                strncpy(auxCharArray, auxTextArrayW[i], auxLong);
-                auxCharArray[auxLong] = 0;
+                    auxInt32 = (int32_t)strlen(auxTextArrayW[i]) - 1;
+                strncpy(auxCharArray, auxTextArrayW[i], auxInt32);
+                auxCharArray[auxInt32] = 0;
                 if (!TIFFSetField(tif, tTag, auxCharArray))
                 {
                     fprintf(stderr, "Can't write %s\n",
@@ -755,7 +755,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
             case TIFF_SETGET_INT:
                 /*-- All those can be written with char, short or long
                  * parameter. Only value range should be in line. */
-                if (!TIFFSetField(tif, tTag, auxLongArrayW[i]))
+                if (!TIFFSetField(tif, tTag, auxInt32ArrayW[i]))
                 {
                     fprintf(stderr, "Can't write %s\n",
                             tFieldArray->fields[i].field_name);
@@ -767,7 +767,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
             case TIFF_SETGET_SINT32:
                 /*-- All those can be written with char, short or long
                  * parameter. Only value range should be in line. */
-                if (!TIFFSetField(tif, tTag, -1.0 * auxLongArrayW[i]))
+                if (!TIFFSetField(tif, tTag, -1.0 * auxInt32ArrayW[i]))
                 {
                     fprintf(stderr, "Can't write %s\n",
                             tFieldArray->fields[i].field_name);
@@ -876,7 +876,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
             case TIFF_SETGET_C16_SINT32:
             case TIFF_SETGET_C32_UINT32:
             case TIFF_SETGET_C32_SINT32:
-                pVoid = &auxLongArrayW[i];
+                pVoid = &auxInt32ArrayW[i];
                 deferredSetField = true;
                 break;
             default:
@@ -1485,10 +1485,10 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                 strncpy(auxCharArray, pAscii, sizeof(auxCharArray) - 1u);
                 auxCharArray[sizeof(auxCharArray) - 1u] = '\0';
                 if (tWriteCount > 0)
-                    auxLong = tWriteCount - 1;
+                    auxInt32 = tWriteCount - 1;
                 else
-                    auxLong = (long)strlen(auxCharArray);
-                retCode2 = strncmp(auxCharArray, auxTextArrayW[i], auxLong);
+                    auxInt32 = (int32_t)strlen(auxCharArray);
+                retCode2 = strncmp(auxCharArray, auxTextArrayW[i], auxInt32);
                 if (retCode2 != 0)
                 {
                     fprintf(
@@ -1509,13 +1509,13 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                     break;
                 }
                 /* compare read values with written ones */
-                auxLong = auxChar;
-                if (auxLong != (char)auxLongArrayW[i])
+                auxInt32 = auxChar;
+                if (auxInt32 != (char)auxInt32ArrayW[i])
                 {
                     fprintf(
                         stderr,
-                        "%d:Read value of %s %ld differs from set value %ld\n",
-                        i, tFieldName, auxLong, auxLongArrayW[i]);
+                        "%d:Read value of %s %d differs from set value %d\n", i,
+                        tFieldName, auxInt32, auxInt32ArrayW[i]);
                 }
                 break;
             case TIFF_SETGET_UINT16:
@@ -1528,13 +1528,13 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                     break;
                 }
                 /* compare read values with written ones */
-                auxLong = auxShort;
-                if (auxLong != (short)auxLongArrayW[i])
+                auxInt32 = auxShort;
+                if (auxInt32 != (short)auxInt32ArrayW[i])
                 {
                     fprintf(
                         stderr,
-                        "%d:Read value of %s %ld differs from set value %ld\n",
-                        i, tFieldName, auxLong, auxLongArrayW[i]);
+                        "%d:Read value of %s %d differs from set value %d\n", i,
+                        tFieldName, auxInt32, auxInt32ArrayW[i]);
                 }
                 break;
             case TIFF_SETGET_UINT32:
@@ -1549,13 +1549,13 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                     break;
                 }
                 /* compare read values with written ones */
-                auxLong = auxUint32;
-                if (auxLong != auxLongArrayW[i])
+                auxInt32 = auxUint32;
+                if (auxInt32 != auxInt32ArrayW[i])
                 {
                     fprintf(
                         stderr,
-                        "%d:Read value of %s %ld differs from set value %ld\n",
-                        i, tFieldName, auxLong, auxLongArrayW[i]);
+                        "%d:Read value of %s %d differs from set value %d\n", i,
+                        tFieldName, auxInt32, auxInt32ArrayW[i]);
                 }
                 break;
             case TIFF_SETGET_FLOAT:
@@ -1691,14 +1691,14 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                         }
                         /* set tWriteCount to number of read samples for next
                          * steps */
-                        auxLong = tWriteCount;
+                        auxInt32 = tWriteCount;
                     }
                     else
                     {
                         /* Special treatment of variable array. */
                         /* Dependent on Cxx, the count parameter is char, short
-                         * or long. Therefore use unionLong! */
-                        if (!TIFFGetField(tif, tTag, &unionLong, &pVoidArray))
+                         * or long. Therefore use unionInt32! */
+                        if (!TIFFGetField(tif, tTag, &unionInt32, &pVoidArray))
                         {
                             fprintf(stderr, "Can't read %s\n",
                                     tFieldArray->fields[i].field_name);
@@ -1707,7 +1707,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                         }
                         /* set tWriteCount to number of read samples for next
                          * steps */
-                        auxLong = unionLong.Short1;
+                        auxInt32 = unionInt32.Short1;
                     }
                     /* Save values from temporary array */
                     if (tSetFieldType == TIFF_SETGET_C0_FLOAT ||
@@ -1715,13 +1715,13 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                         tSetFieldType == TIFF_SETGET_C32_FLOAT)
                     {
                         memcpy(&auxFloatArray, pVoidArray,
-                               (auxLong * sizeof(auxFloatArray[0])));
+                               (auxInt32 * sizeof(auxFloatArray[0])));
                         /* compare read values with written ones */
                         if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL)
                             dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i];
                         else
                             dblDiffLimit = 1e-6;
-                        for (j = 0; j < auxLong; j++)
+                        for (j = 0; j < auxInt32; j++)
                         {
                             dblDiff = auxFloatArray[j] - auxFloatArrayW[i + j];
                             if (fabs(dblDiff) > fabs(dblDiffLimit))
@@ -1740,13 +1740,13 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                     else
                     {
                         memcpy(&auxDoubleArray, pVoidArray,
-                               (auxLong * sizeof(auxDoubleArray[0])));
+                               (auxInt32 * sizeof(auxDoubleArray[0])));
                         /* compare read values with written ones */
                         if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL)
                             dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i];
                         else
                             dblDiffLimit = 1e-6;
-                        for (j = 0; j < auxLong; j++)
+                        for (j = 0; j < auxInt32; j++)
                         {
                             dblDiff =
                                 auxDoubleArray[j] - auxDoubleArrayW[i + j];
@@ -1829,13 +1829,13 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                     }
                     /* set tWriteCount to number of read samples for next steps
                      */
-                    auxLong = tWriteCount;
+                    auxInt32 = tWriteCount;
                 }
                 else
                 {
                     /* special treatment of variable array */
                     /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
-                    if (!TIFFGetField(tif, tTag, &unionLong, &pVoidArray))
+                    if (!TIFFGetField(tif, tTag, &unionInt32, &pVoidArray))
                     {
                         fprintf(stderr, "Can't read %s\n",
                                 tFieldArray->fields[i].field_name);
@@ -1844,7 +1844,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                     }
                     /* set tWriteCount to number of read samples for next steps
                      */
-                    auxLong = unionLong.Short1;
+                    auxInt32 = unionInt32.Short1;
                 }
                 /* Save values from temporary array */
                 if (tSetFieldType == TIFF_SETGET_C0_UINT8 ||
@@ -1855,9 +1855,9 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                     tSetFieldType == TIFF_SETGET_C32_SINT8)
                 {
                     memcpy(&auxCharArray, pVoidArray,
-                           (auxLong * sizeof(auxCharArray[0])));
+                           (auxInt32 * sizeof(auxCharArray[0])));
                     /* Compare and check values  */
-                    for (j = 0; j < auxLong; j++)
+                    for (j = 0; j < auxInt32; j++)
                     {
                         if (tTag == EXIFTAG_EXIFVERSION)
                         {
@@ -1895,9 +1895,9 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                          tSetFieldType == TIFF_SETGET_C32_SINT16)
                 {
                     memcpy(&auxShortArray, pVoidArray,
-                           (auxLong * sizeof(auxShortArray[0])));
+                           (auxInt32 * sizeof(auxShortArray[0])));
                     /* Compare and check values  */
-                    for (j = 0; j < auxLong; j++)
+                    for (j = 0; j < auxInt32; j++)
                     {
                         if (auxShortArray[j] != auxShortArrayW[i + j])
                         {
@@ -1917,18 +1917,18 @@ int write_test_tiff(TIFF *tif, const char *filenameRead)
                          tSetFieldType == TIFF_SETGET_C32_UINT32 ||
                          tSetFieldType == TIFF_SETGET_C32_SINT32)
                 {
-                    memcpy(&auxLongArray, pVoidArray,
-                           (auxLong * sizeof(auxLongArray[0])));
+                    memcpy(&auxInt32Array, pVoidArray,
+                           (auxInt32 * sizeof(auxInt32Array[0])));
                     /* Compare and check values  */
-                    for (j = 0; j < auxLong; j++)
+                    for (j = 0; j < auxInt32; j++)
                     {
-                        if (auxLongArray[j] != auxLongArrayW[i + j])
+                        if (auxInt32Array[j] != auxInt32ArrayW[i + j])
                         {
                             fprintf(stderr,
-                                    "Read value %d of %s #%d %ld differs from "
-                                    "set value %ld\n",
-                                    i, tFieldName, j, auxLongArray[j],
-                                    auxLongArrayW[i + j]);
+                                    "Read value %d of %s #%d %d differs from "
+                                    "set value %d\n",
+                                    i, tFieldName, j, auxInt32Array[j],
+                                    auxInt32ArrayW[i + j]);
                             GOTOFAILURE_ALL_EXIF
                         }
                     }
diff --git a/test/rational_precision2double.c b/test/rational_precision2double.c
index 0c27a4e1..55b77dd9 100644
--- a/test/rational_precision2double.c
+++ b/test/rational_precision2double.c
@@ -305,15 +305,15 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
     double auxDouble = 0.0;
     uint16_t auxUint16 = 0;
     uint32_t auxUint32 = 0;
-    long auxLong = 0;
+    int32_t auxInt32 = 0;
     void *pVoid;
     int blnIsRational2Double;
 
     int i, j;
-    long nTags;
+    int32_t nTags;
 
     const TIFFFieldArray *tFieldArray;
-    unsigned long tTag;
+    uint32_t tTag;
     TIFFDataType tType;
     short tWriteCount;
     TIFFSetGetFieldType tSetFieldType;
@@ -337,11 +337,11 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
     uint16_t count16 = 0;
     union
     {
-        long Long;
+        int32_t Int32;
         short Short1;
         short Short2[2];
         char Char[4];
-    } auxLongUnion;
+    } auxInt32Union;
     union
     {
         double dbl;
@@ -1223,7 +1223,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
                                 }
                                 /* set tWriteCount to number of read samples for
                                  * next steps */
-                                auxLong = tWriteCount;
+                                auxInt32 = tWriteCount;
                             }
                             else
                             {
@@ -1231,7 +1231,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
                                 /* Dependent on Cxx, the count parameter is
                                  * char, short or long. Therefore use unionLong!
                                  */
-                                if (!TIFFGetField(tif, tTag, &auxLongUnion,
+                                if (!TIFFGetField(tif, tTag, &auxInt32Union,
                                                   &pVoidArray))
                                 {
                                     fprintf(stderr, "Can't read %s\n",
@@ -1241,7 +1241,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
                                 }
                                 /* set tWriteCount to number of read samples for
                                  * next steps */
-                                auxLong = auxLongUnion.Short1;
+                                auxInt32 = auxInt32Union.Short1;
                             }
                             /* Save values from temporary array */
                             if (tSetFieldType == TIFF_SETGET_C0_FLOAT ||
@@ -1249,7 +1249,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
                                 tSetFieldType == TIFF_SETGET_C32_FLOAT)
                             {
                                 memcpy(&auxFloatArray, pVoidArray,
-                                       (auxLong * sizeof(auxFloatArray[0])));
+                                       (auxInt32 * sizeof(auxFloatArray[0])));
                                 /* compare read values with written ones */
                                 if (tType == TIFF_RATIONAL ||
                                     tType == TIFF_SRATIONAL)
@@ -1257,7 +1257,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
                                         RATIONAL_EPS * auxDoubleArrayW[i];
                                 else
                                     dblDiffLimit = 1e-6;
-                                for (j = 0; j < auxLong; j++)
+                                for (j = 0; j < auxInt32; j++)
                                 {
                                     dblDiff = auxFloatArray[j] -
                                               auxFloatArrayW[i + j];
@@ -1278,7 +1278,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
                             else
                             {
                                 memcpy(&auxDoubleArray, pVoidArray,
-                                       (auxLong * sizeof(auxDoubleArray[0])));
+                                       (auxInt32 * sizeof(auxDoubleArray[0])));
                                 /* compare read values with written ones */
                                 if (tType == TIFF_RATIONAL ||
                                     tType == TIFF_SRATIONAL)
@@ -1286,7 +1286,7 @@ int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags)
                                         RATIONAL_EPS * auxDoubleArrayW[i];
                                 else
                                     dblDiffLimit = 1e-6;
-                                for (j = 0; j < auxLong; j++)
+                                for (j = 0; j < auxInt32; j++)
                                 {
                                     dblDiff = auxDoubleArray[j] -
                                               auxDoubleArrayW[i + j];