1
0
Fork 0

Codechange: Replace static_cast<size_t>(-1) with SIZE_MAX

pull/12455/head
Rubidium 2024-04-15 21:29:45 +02:00
parent 3007df23bc
commit e942f3d642
4 changed files with 10 additions and 10 deletions

View File

@ -184,7 +184,7 @@ struct SelectGameWindow : public Window {
this->ReadIntroGameViewportCommands(); this->ReadIntroGameViewportCommands();
this->cur_viewport_command_index = static_cast<size_t>(-1); this->cur_viewport_command_index = SIZE_MAX;
this->cur_viewport_command_time = 0; this->cur_viewport_command_time = 0;
this->mouse_idle_time = 0; this->mouse_idle_time = 0;
this->mouse_idle_pos = _cursor.pos; this->mouse_idle_pos = _cursor.pos;

View File

@ -142,7 +142,7 @@ static std::string convert_tofrom_fs(iconv_t convd, const std::string &name)
size_t outlen = buf.size(); size_t outlen = buf.size();
char *outbuf = buf.data(); char *outbuf = buf.data();
iconv(convd, nullptr, nullptr, nullptr, nullptr); iconv(convd, nullptr, nullptr, nullptr, nullptr);
if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == static_cast<size_t>(-1)) { if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == SIZE_MAX) {
Debug(misc, 0, "[iconv] error converting '{}'. Errno {}", name, errno); Debug(misc, 0, "[iconv] error converting '{}'. Errno {}", name, errno);
return name; return name;
} }

View File

@ -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 str the current value of the setting for which a value needs found
* @param len length of the string * @param len length of the string
* @param many full domain of values the ONEofMANY setting can have * @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<std::string> &many) size_t OneOfManySettingDesc::ParseSingleValue(const char *str, size_t len, const std::vector<std::string> &many)
{ {
@ -190,7 +190,7 @@ size_t OneOfManySettingDesc::ParseSingleValue(const char *str, size_t len, const
idx++; idx++;
} }
return static_cast<size_t>(-1); return SIZE_MAX;
} }
/** /**
@ -212,7 +212,7 @@ std::optional<bool> BoolSettingDesc::ParseSingleValue(const char *str)
* @param many full domain of values the MANYofMANY setting can have * @param many full domain of values the MANYofMANY setting can have
* @param str the current string value of the setting, each individual * @param str the current string value of the setting, each individual
* of separated by a whitespace,tab or | character * 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<std::string> &many, const char *str) static size_t LookupManyOfMany(const std::vector<std::string> &many, const char *str)
{ {
@ -229,7 +229,7 @@ static size_t LookupManyOfMany(const std::vector<std::string> &many, const char
while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++; while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++;
r = OneOfManySettingDesc::ParseSingleValue(str, s - str, many); r = OneOfManySettingDesc::ParseSingleValue(str, s - str, many);
if (r == static_cast<size_t>(-1)) return r; if (r == SIZE_MAX) return r;
SetBit(res, (uint8_t)r); // value found, set it SetBit(res, (uint8_t)r); // value found, set it
if (*s == 0) break; 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); size_t r = OneOfManySettingDesc::ParseSingleValue(str, strlen(str), this->many);
/* if the first attempt of conversion from string to the appropriate value fails, /* 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. */ * look if we have defined a converter from old value to new value. */
if (r == static_cast<size_t>(-1) && this->many_cnvt != nullptr) r = this->many_cnvt(str); if (r == SIZE_MAX && this->many_cnvt != nullptr) r = this->many_cnvt(str);
if (r != static_cast<size_t>(-1)) return r; // and here goes converted value if (r != SIZE_MAX) return r; // and here goes converted value
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
msg.SetDParamStr(0, str); 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 ManyOfManySettingDesc::ParseValue(const char *str) const
{ {
size_t r = LookupManyOfMany(this->many, str); size_t r = LookupManyOfMany(this->many, str);
if (r != static_cast<size_t>(-1)) return r; if (r != SIZE_MAX) return r;
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
msg.SetDParamStr(0, str); msg.SetDParamStr(0, str);
msg.SetDParamStr(1, this->GetName()); msg.SetDParamStr(1, this->GetName());

View File

@ -117,7 +117,7 @@ static bool SetBankSource(MixerChannel *mc, const SoundEntry *sound)
assert(sound != nullptr); assert(sound != nullptr);
/* Check for valid sound size. */ /* Check for valid sound size. */
if (sound->file_size == 0 || sound->file_size > static_cast<size_t>(-1) - 2) return false; if (sound->file_size == 0 || sound->file_size > SIZE_MAX - 2) return false;
int8_t *mem = MallocT<int8_t>(sound->file_size + 2); int8_t *mem = MallocT<int8_t>(sound->file_size + 2);
/* Add two extra bytes so rate conversion can read these /* Add two extra bytes so rate conversion can read these