Anims/Types: Handle out of bounds FindStr accesses without throwing

Throwing tries to call `std::__throw_out_of_range_fmt` which results in a crash.
The cause of the out of bounds accesses needs to be investigated.
This commit is contained in:
Nick Renieris 2022-06-22 22:08:00 +03:00 committed by GRAnimated
parent 7e4a80b934
commit 60a5179e4b
5 changed files with 24 additions and 4 deletions

View file

@ -488,6 +488,10 @@ namespace CaptureAnims {
} }
static constexpr const char *FindStr(Type type) { static constexpr const char *FindStr(Type type) {
return s_Strs.at(ToValue(type)); const s16 type_ = (s16)type;
if (0 <= type_ && type_ < s_Strs.size())
return s_Strs[type_];
else
return "";
} }
} }

View file

@ -98,6 +98,10 @@ namespace CaptureTypes {
} }
static constexpr const char *FindStr(Type type) { static constexpr const char *FindStr(Type type) {
return s_Strs.at(ToValue(type)); const s16 type_ = (s16)type;
if (0 <= type_ && type_ < s_Strs.size())
return s_Strs[type_];
else
return "";
} }
} }

View file

@ -1154,6 +1154,10 @@ namespace PlayerAnims {
} }
static constexpr const char *FindStr(Type type) { static constexpr const char *FindStr(Type type) {
return s_Strs.at(ToValue(type)); const s16 type_ = (s16)type;
if (0 <= type_ && type_ < s_Strs.size())
return s_Strs[type_];
else
return "";
} }
} }

View file

@ -72,6 +72,10 @@ namespace WipeTypes {
} }
static constexpr const char *FindStr(Type type) { static constexpr const char *FindStr(Type type) {
return s_Strs.at(ToValue(type)); const s16 type_ = (s16)type;
if (0 <= type_ && type_ < s_Strs.size())
return s_Strs[type_];
else
return "";
} }
} }

View file

@ -783,12 +783,16 @@ void Client::updatePlayerInfo(PlayerInf *packet) {
} else { } else {
strcpy(curInfo->curAnimStr, "Wait"); strcpy(curInfo->curAnimStr, "Wait");
} }
if (strlen(curInfo->curAnimStr) == 0)
Logger::log("[ERROR] %s: actName was out of bounds: %d", __func__, packet->actName);
if(packet->subActName != PlayerAnims::Type::Unknown) { if(packet->subActName != PlayerAnims::Type::Unknown) {
strcpy(curInfo->curSubAnimStr, PlayerAnims::FindStr(packet->subActName)); strcpy(curInfo->curSubAnimStr, PlayerAnims::FindStr(packet->subActName));
} else { } else {
strcpy(curInfo->curSubAnimStr, ""); strcpy(curInfo->curSubAnimStr, "");
} }
if (strlen(curInfo->curSubAnimStr) == 0)
Logger::log("[ERROR] %s: subActName was out of bounds: %d", __func__, packet->subActName);
curInfo->curAnim = packet->actName; curInfo->curAnim = packet->actName;
curInfo->curSubAnim = packet->subActName; curInfo->curSubAnim = packet->subActName;