Common/StringUtil: Handle error returns in StdStringFromFormatV()

This commit is contained in:
Connor McLaughlin 2022-05-21 14:38:25 +10:00 committed by refractionpcsx2
parent b1d6d84e6f
commit c07c942659
1 changed files with 8 additions and 2 deletions

View File

@ -49,8 +49,14 @@ namespace StringUtil
va_end(ap_copy);
std::string ret;
ret.resize(len);
std::vsnprintf(ret.data(), ret.size() + 1, format, ap);
// If an encoding error occurs, len is -1. Which we definitely don't want to resize to.
if (len > 0)
{
ret.resize(len);
std::vsnprintf(ret.data(), ret.size() + 1, format, ap);
}
return ret;
}