From b9e1e230f9120eeee063e5c44a68bb207b2e59cd Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Sat, 15 Jul 2023 11:24:31 +0200 Subject: [PATCH] RMG-Core: minor code fixes --- Source/RMG-Core/Cheats.cpp | 8 ++++---- Source/RMG-Core/ConvertStringEncoding.cpp | 3 +-- Source/RMG-Core/Rom.cpp | 6 ++---- Source/RMG-Core/SaveState.cpp | 2 +- Source/RMG-Core/Settings/Settings.cpp | 4 ++-- Source/RMG-Core/Unzip.cpp | 4 ++-- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Source/RMG-Core/Cheats.cpp b/Source/RMG-Core/Cheats.cpp index 252df8ac..aac3ca14 100644 --- a/Source/RMG-Core/Cheats.cpp +++ b/Source/RMG-Core/Cheats.cpp @@ -175,7 +175,7 @@ static std::string join_split_string(std::vector splitStr, char sep std::string joinedString; std::string element; int skippedElements = 0; - for (int i = 0; i < splitStr.size(); i++) + for (uint32_t i = 0; i < splitStr.size(); i++) { // allow for skipping elements if (skippedElements++ < skip) @@ -201,7 +201,7 @@ static bool parse_cheat(std::vector lines, int startIndex, CoreChea { std::string error; std::string line; - for (int i = startIndex; i < lines.size(); i++) + for (uint32_t i = startIndex; i < lines.size(); i++) { line = lines.at(i); @@ -340,7 +340,7 @@ static bool parse_cheat_file(std::vector lines, CoreCheatFile& chea bool readHeader = false; bool readHeaderName = false; - for (int index = 0; index < lines.size(); index++) + for (uint32_t index = 0; index < lines.size(); index++) { line = lines.at(index); @@ -911,7 +911,7 @@ bool CoreGetCheatOption(CoreCheat cheat, CoreCheatOption& option) for (CoreCheatOption& cheatOption : cheat.CheatOptions) { - if (cheatOption.Value == value) + if (cheatOption.Value == (uint32_t)value) { option = cheatOption; return true; diff --git a/Source/RMG-Core/ConvertStringEncoding.cpp b/Source/RMG-Core/ConvertStringEncoding.cpp index 02a27783..4a3ca540 100644 --- a/Source/RMG-Core/ConvertStringEncoding.cpp +++ b/Source/RMG-Core/ConvertStringEncoding.cpp @@ -27,7 +27,6 @@ std::string CoreConvertStringEncoding(std::string str, CoreStringEncoding encodi iconv_t cd; - char inputBuf[256] = {0}; char outputBuf[256] = {0}; char* inputBufPtr = (char*)str.c_str(); @@ -56,7 +55,7 @@ std::string CoreConvertStringEncoding(std::string str, CoreStringEncoding encodi } size_t ret = iconv(cd, &inputBufPtr, &inputBufSize, &outputBufPtr, &outputBufSize); - if (ret == -1) + if (ret == (size_t)-1) { error = "CoreConvertStringEncoding Failed: "; error += "iconv Failed: "; diff --git a/Source/RMG-Core/Rom.cpp b/Source/RMG-Core/Rom.cpp index 5791bb35..e38a74c3 100644 --- a/Source/RMG-Core/Rom.cpp +++ b/Source/RMG-Core/Rom.cpp @@ -138,8 +138,6 @@ static bool read_zip_file(std::filesystem::path file, std::filesystem::path* ext { std::string error; std::fstream fileStream; - int fileStreamLen; - char* fileStreamBuf; unzFile zipFile; unz_global_info64 zipInfo; @@ -181,7 +179,7 @@ static bool read_zip_file(std::filesystem::path file, std::filesystem::path* ext return false; } - for (int i = 0; i < zipInfo.number_entry; i++) + for (uint64_t i = 0; i < zipInfo.number_entry; i++) { unz_file_info fileInfo; char fileName[PATH_MAX]; @@ -377,7 +375,7 @@ static bool read_7zip_file(std::filesystem::path file, std::filesystem::path* ex return false; } - for (int i = 0; i < db.NumFiles; i++) + for (uint32_t i = 0; i < db.NumFiles; i++) { size_t filename_size = 0; uint16_t fileName[PATH_MAX]; diff --git a/Source/RMG-Core/SaveState.cpp b/Source/RMG-Core/SaveState.cpp index 865f73d2..f7451bed 100644 --- a/Source/RMG-Core/SaveState.cpp +++ b/Source/RMG-Core/SaveState.cpp @@ -25,7 +25,7 @@ // replaces all occurences of any chars in replace with c inside str static void str_replace_chars(std::string& str, const std::string replace, const char c) { - for (int i = 0; i < str.size(); i++) + for (uint32_t i = 0; i < str.size(); i++) { char str_char = str.at(i); if (replace.find(str_char) != std::string::npos) diff --git a/Source/RMG-Core/Settings/Settings.cpp b/Source/RMG-Core/Settings/Settings.cpp index 2c3d72b2..69b176be 100644 --- a/Source/RMG-Core/Settings/Settings.cpp +++ b/Source/RMG-Core/Settings/Settings.cpp @@ -1495,7 +1495,7 @@ static bool config_option_default_set(std::string section, std::string key, m64p static bool int_list_to_string(std::vector intList, std::string& string) { - for (int i = 0; i < intList.size(); i++) + for (uint32_t i = 0; i < intList.size(); i++) { int num = intList.at(i); string += std::to_string(num); @@ -1539,7 +1539,7 @@ static bool string_list_to_string(std::vector stringList, std::stri { std::string error; - for (int i = 0; i < stringList.size(); i++) + for (uint32_t i = 0; i < stringList.size(); i++) { std::string str = stringList.at(i); diff --git a/Source/RMG-Core/Unzip.cpp b/Source/RMG-Core/Unzip.cpp index eb63c15e..84d14f87 100644 --- a/Source/RMG-Core/Unzip.cpp +++ b/Source/RMG-Core/Unzip.cpp @@ -33,7 +33,7 @@ bool CoreUnzip(std::filesystem::path file, std::filesystem::path path) unz_global_info zipInfo; std::ofstream outputStream; char* read_buffer = (char*)malloc(UNZIP_READ_SIZE); - size_t bytes_read = 0; + int bytes_read = 0; if (read_buffer == nullptr) { @@ -60,7 +60,7 @@ bool CoreUnzip(std::filesystem::path file, std::filesystem::path path) } - for (int i = 0; i < zipInfo.number_entry; i++) + for (uint64_t i = 0; i < zipInfo.number_entry; i++) { unz_file_info fileInfo; char fileName[PATH_MAX];