From e942f3d6427b25ea9a9958e98b316ffa995ef625 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 15 Apr 2024 21:29:45 +0200 Subject: [PATCH] Codechange: Replace static_cast(-1) with SIZE_MAX --- src/intro_gui.cpp | 2 +- src/os/unix/unix.cpp | 2 +- src/settings.cpp | 14 +++++++------- src/sound.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index 596d099f93..99ca0d6e17 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -184,7 +184,7 @@ struct SelectGameWindow : public Window { this->ReadIntroGameViewportCommands(); - this->cur_viewport_command_index = static_cast(-1); + this->cur_viewport_command_index = SIZE_MAX; this->cur_viewport_command_time = 0; this->mouse_idle_time = 0; this->mouse_idle_pos = _cursor.pos; diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index 48961d4078..2003f4692c 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -142,7 +142,7 @@ static std::string convert_tofrom_fs(iconv_t convd, const std::string &name) size_t outlen = buf.size(); char *outbuf = buf.data(); iconv(convd, nullptr, nullptr, nullptr, nullptr); - if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == static_cast(-1)) { + if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == SIZE_MAX) { Debug(misc, 0, "[iconv] error converting '{}'. Errno {}", name, errno); return name; } diff --git a/src/settings.cpp b/src/settings.cpp index 191f8aed58..df6bcfba51 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -177,7 +177,7 @@ const uint16_t INIFILE_VERSION = (IniFileVersion)(IFV_MAX_VERSION - 1); ///< Cur * @param str the current value of the setting for which a value needs found * @param len length of the string * @param many full domain of values the ONEofMANY setting can have - * @return the integer index of the full-list, or -1 if not found + * @return the integer index of the full-list, or SIZE_MAX if not found */ size_t OneOfManySettingDesc::ParseSingleValue(const char *str, size_t len, const std::vector &many) { @@ -190,7 +190,7 @@ size_t OneOfManySettingDesc::ParseSingleValue(const char *str, size_t len, const idx++; } - return static_cast(-1); + return SIZE_MAX; } /** @@ -212,7 +212,7 @@ std::optional BoolSettingDesc::ParseSingleValue(const char *str) * @param many full domain of values the MANYofMANY setting can have * @param str the current string value of the setting, each individual * of separated by a whitespace,tab or | character - * @return the 'fully' set integer, or -1 if a set is not found + * @return the 'fully' set integer, or SIZE_MAX if a set is not found */ static size_t LookupManyOfMany(const std::vector &many, const char *str) { @@ -229,7 +229,7 @@ static size_t LookupManyOfMany(const std::vector &many, const char while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++; r = OneOfManySettingDesc::ParseSingleValue(str, s - str, many); - if (r == static_cast(-1)) return r; + if (r == SIZE_MAX) return r; SetBit(res, (uint8_t)r); // value found, set it if (*s == 0) break; @@ -419,8 +419,8 @@ size_t OneOfManySettingDesc::ParseValue(const char *str) const size_t r = OneOfManySettingDesc::ParseSingleValue(str, strlen(str), this->many); /* if the first attempt of conversion from string to the appropriate value fails, * look if we have defined a converter from old value to new value. */ - if (r == static_cast(-1) && this->many_cnvt != nullptr) r = this->many_cnvt(str); - if (r != static_cast(-1)) return r; // and here goes converted value + if (r == SIZE_MAX && this->many_cnvt != nullptr) r = this->many_cnvt(str); + if (r != SIZE_MAX) return r; // and here goes converted value ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE); msg.SetDParamStr(0, str); @@ -432,7 +432,7 @@ size_t OneOfManySettingDesc::ParseValue(const char *str) const size_t ManyOfManySettingDesc::ParseValue(const char *str) const { size_t r = LookupManyOfMany(this->many, str); - if (r != static_cast(-1)) return r; + if (r != SIZE_MAX) return r; ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE); msg.SetDParamStr(0, str); msg.SetDParamStr(1, this->GetName()); diff --git a/src/sound.cpp b/src/sound.cpp index 107737fbd3..7bb6d1ef26 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -117,7 +117,7 @@ static bool SetBankSource(MixerChannel *mc, const SoundEntry *sound) assert(sound != nullptr); /* Check for valid sound size. */ - if (sound->file_size == 0 || sound->file_size > static_cast(-1) - 2) return false; + if (sound->file_size == 0 || sound->file_size > SIZE_MAX - 2) return false; int8_t *mem = MallocT(sound->file_size + 2); /* Add two extra bytes so rate conversion can read these