Common/StringUtil: Handle error returns in StdStringFromFormatV()

This commit is contained in:
Connor McLaughlin authored and refractionpcsx2 committed 2022-05-22 13:58:56 +01:00
1 parent b1d6d84e6f
commit c07c942659
1 file changed
+8 -2
+8 -2
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;
}