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) {
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) {
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) {
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) {
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 {
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) {
strcpy(curInfo->curSubAnimStr, PlayerAnims::FindStr(packet->subActName));
} else {
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->curSubAnim = packet->subActName;