From d0eae7bab195e8724f4dce6507927d6cf65382df Mon Sep 17 00:00:00 2001
From: JohnHolmesII <jedistephen@hotmail.com>
Date: Tue, 21 May 2019 20:47:47 -0700
Subject: [PATCH] Fix -Wsign-compare a little bit Explicitly mark loop types
 (per review)

---
 Utilities/address_range.h             | 2 +-
 Utilities/cfmt.h                      | 8 +++++---
 rpcs3/Emu/Cell/Modules/StaticHLE.cpp  | 4 ++--
 rpcs3/Emu/Cell/Modules/cellAdec.cpp   | 2 +-
 rpcs3/Emu/Cell/Modules/cellL10n.cpp   | 2 +-
 rpcs3/Emu/Cell/Modules/cellPngDec.cpp | 4 ++--
 6 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/Utilities/address_range.h b/Utilities/address_range.h
index 6c852f20ff..c1ae078c9b 100644
--- a/Utilities/address_range.h
+++ b/Utilities/address_range.h
@@ -589,4 +589,4 @@ namespace std {
 			return (size_t{ k.start } << 32) | size_t{ k.end };
 		}
 	};
-}
\ No newline at end of file
+}
diff --git a/Utilities/cfmt.h b/Utilities/cfmt.h
index da58eeec95..34bd511592 100644
--- a/Utilities/cfmt.h
+++ b/Utilities/cfmt.h
@@ -7,6 +7,8 @@
 #include <vector>
 #include <algorithm>
 
+static const size_t size_dropped = std::numeric_limits<size_t>::max();
+
 /*
 C-style format parser. Appends formatted string to `out`, returns number of characters written.
 `out`: mutable reference to std::string, std::vector<char> or other compatible container
@@ -41,7 +43,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src)
 	const auto drop_sequence = [&]
 	{
 		out.insert(out.end(), fmt - ctx.size, fmt);
-		ctx.size = -1;
+		ctx.size = size_dropped;
 	};
 
 	const auto read_decimal = [&](uint result) -> uint
@@ -112,7 +114,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src)
 		ctx = {0};
 		out.push_back(ch);
 	}
-	else if (ctx.size == -1)
+	else if (ctx.size == size_dropped)
 	{
 		out.push_back(ch);
 	}
@@ -626,7 +628,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src)
 	}
 
 	// Handle unfinished sequence
-	if (ctx.size && ctx.size != -1)
+	if (ctx.size && ctx.size != size_dropped)
 	{
 		fmt--, drop_sequence();
 	}
diff --git a/rpcs3/Emu/Cell/Modules/StaticHLE.cpp b/rpcs3/Emu/Cell/Modules/StaticHLE.cpp
index a20d87ca6d..8af27f8792 100644
--- a/rpcs3/Emu/Cell/Modules/StaticHLE.cpp
+++ b/rpcs3/Emu/Cell/Modules/StaticHLE.cpp
@@ -32,7 +32,7 @@ statichle_handler::~statichle_handler()
 
 bool statichle_handler::load_patterns()
 {
-	for (int i = 0; i < shle_patterns_list.size(); i++)
+	for (u32 i = 0; i < shle_patterns_list.size(); i++)
 	{
 		auto& pattern = shle_patterns_list[i];
 
@@ -77,7 +77,7 @@ bool statichle_handler::load_patterns()
 			return (hv << 4) | lv;
 		};
 
-		for (int j = 0; j < 32; j++)
+		for (u32 j = 0; j < 32; j++)
 			dapat.start_pattern[j] = char_to_u8(pattern[0][j * 2], pattern[0][(j * 2) + 1]);
 
 		dapat.crc16_length = char_to_u8(pattern[1][0], pattern[1][1]);
diff --git a/rpcs3/Emu/Cell/Modules/cellAdec.cpp b/rpcs3/Emu/Cell/Modules/cellAdec.cpp
index 8c6ea9054d..5090063ee6 100644
--- a/rpcs3/Emu/Cell/Modules/cellAdec.cpp
+++ b/rpcs3/Emu/Cell/Modules/cellAdec.cpp
@@ -428,7 +428,7 @@ next:
 	if (adecIsAtracX(adec.type) && !adec.reader.init)
 	{
 		OMAHeader oma(1 /* atrac3p id */, adec.sample_rate, adec.ch_cfg, adec.frame_size);
-		if (buf_size < sizeof(oma))
+		if (buf_size + 0u < sizeof(oma))
 		{
 			cellAdec.error("adecRead(): OMAHeader writing failed");
 			Emu.Pause();
diff --git a/rpcs3/Emu/Cell/Modules/cellL10n.cpp b/rpcs3/Emu/Cell/Modules/cellL10n.cpp
index 5b7a47a3d0..005f01fe62 100644
--- a/rpcs3/Emu/Cell/Modules/cellL10n.cpp
+++ b/rpcs3/Emu/Cell/Modules/cellL10n.cpp
@@ -410,7 +410,7 @@ s32 jstrnchk(vm::cptr<u8> src, s32 src_len)
 {
 	u8 r = 0;
 
-	for (u32 len = 0; len < src_len; len++)
+	for (s32 len = 0; len < src_len; len++)
 	{
 		if (src != vm::null)
 		{
diff --git a/rpcs3/Emu/Cell/Modules/cellPngDec.cpp b/rpcs3/Emu/Cell/Modules/cellPngDec.cpp
index 4698cc26e1..41a187913e 100644
--- a/rpcs3/Emu/Cell/Modules/cellPngDec.cpp
+++ b/rpcs3/Emu/Cell/Modules/cellPngDec.cpp
@@ -769,9 +769,9 @@ s32 pngDecodeData(ppu_thread& ppu, PHandle handle, PStream stream, vm::ptr<u8> d
 		// todo: commandptr
 		try
 		{
-			for (int j = 0; j < stream->passes; j++)
+			for (u32 j = 0; j < stream->passes; j++)
 			{
-				for (int i = 0; i < stream->out_param.outputHeight; ++i)
+				for (u32 i = 0; i < stream->out_param.outputHeight; ++i)
 				{
 					const u32 line = flip ? stream->out_param.outputHeight - i - 1 : i;
 					png_read_row(stream->png_ptr, &data[line*bytes_per_line], nullptr);