libtiff: Try to silence new Coverity Scan false positives

From dd29a569fb1b965c02b5d88e11c6526562e957bb Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Mon, 24 Jun 2024 21:39:13 +0200
Subject: [PATCH] Try to silence new Coverity Scan false positives

There are other warnings in tools/ that I'll let others deal with.
---
 libtiff/tif_dir.c  | 6 ++++--
 libtiff/tif_unix.c | 4 ++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c
index 09602e64..a491097b 100644
--- a/libtiff/tif_dir.c
+++ b/libtiff/tif_dir.c
@@ -2160,8 +2160,10 @@ int TIFFSetSubDirectory(TIFF *tif, uint64_t diroff)
             probablySubIFD = 1;
         }
         /* -1 because TIFFReadDirectory() will increment tif_curdir. */
-        tif->tif_curdir =
-            curdir == 0 ? TIFF_NON_EXISTENT_DIR_NUMBER : curdir - 1;
+        if (curdir >= 1)
+            tif->tif_curdir = curdir - 1;
+        else
+            tif->tif_curdir = TIFF_NON_EXISTENT_DIR_NUMBER;
     }
 
     tif->tif_nextdiroff = diroff;
diff --git a/libtiff/tif_unix.c b/libtiff/tif_unix.c
index d9254d45..e65da872 100644
--- a/libtiff/tif_unix.c
+++ b/libtiff/tif_unix.c
@@ -83,6 +83,8 @@ static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
         size_t io_size = bytes_total - bytes_read;
         if (io_size > TIFF_IO_MAX)
             io_size = TIFF_IO_MAX;
+        /* Below is an obvious false positive of Coverity Scan */
+        /* coverity[overflow_sink] */
         count = read(fdh.fd, buf_offset, (TIFFIOSize_t)io_size);
         if (count <= 0)
             break;
@@ -110,6 +112,8 @@ static tmsize_t _tiffWriteProc(thandle_t fd, void *buf, tmsize_t size)
         size_t io_size = bytes_total - bytes_written;
         if (io_size > TIFF_IO_MAX)
             io_size = TIFF_IO_MAX;
+        /* Below is an obvious false positive of Coverity Scan */
+        /* coverity[overflow_sink] */
         count = write(fdh.fd, buf_offset, (TIFFIOSize_t)io_size);
         if (count <= 0)
             break;