From e4ba736d03722723f0b5ea55a5267aba8b7d78d6 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Fri, 15 Mar 2024 18:45:45 +0100
Subject: [PATCH] input/{async,rewind}, decoder/dsdiff: use std::cmp_*() for
 safer integer comparisons

---
 src/decoder/plugins/DsdiffDecoderPlugin.cxx | 2 +-
 src/input/AsyncInputStream.cxx              | 2 +-
 src/input/RewindInputStream.cxx             | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/decoder/plugins/DsdiffDecoderPlugin.cxx b/src/decoder/plugins/DsdiffDecoderPlugin.cxx
index 72c0917fd..38d092459 100644
--- a/src/decoder/plugins/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/plugins/DsdiffDecoderPlugin.cxx
@@ -387,7 +387,7 @@ dsdiff_decode_chunk(DecoderClient &client, InputStream &is,
 		/* see how much aligned data from the remaining chunk
 		   fits into the local buffer */
 		size_t now_size = buffer_size;
-		if (remaining_bytes < (offset_type)now_size) {
+		if (std::cmp_less(remaining_bytes, now_size)) {
 			unsigned now_frames = remaining_bytes / frame_size;
 			now_size = now_frames * frame_size;
 		}
diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx
index 185319d02..599aaf799 100644
--- a/src/input/AsyncInputStream.cxx
+++ b/src/input/AsyncInputStream.cxx
@@ -109,7 +109,7 @@ AsyncInputStream::Seek(std::unique_lock<Mutex> &lock,
 			break;
 
 		const size_t nbytes =
-			new_offset - offset < (offset_type)r.size()
+			std::cmp_less(new_offset - offset, r.size())
 			? new_offset - offset
 			: r.size();
 
diff --git a/src/input/RewindInputStream.cxx b/src/input/RewindInputStream.cxx
index 6b0147a83..600d06a69 100644
--- a/src/input/RewindInputStream.cxx
+++ b/src/input/RewindInputStream.cxx
@@ -82,7 +82,7 @@ RewindInputStream::Read(std::unique_lock<Mutex> &lock,
 
 		size_t nbytes = input->Read(lock, ptr, read_size);
 
-		if (input->GetOffset() > (offset_type)sizeof(buffer))
+		if (std::cmp_greater(input->GetOffset(), sizeof(buffer)))
 			/* disable buffering */
 			tail = 0;
 		else if (tail == (size_t)offset) {