mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-16 12:05:38 +00:00
(Windows) Added error handling to StringUtil::stringToWideString() and StringUtil::wideStringToString() to avoid crashes caused by invalid characters.
This commit is contained in:
parent
56665af45e
commit
f550ba7dfc
|
@ -12,6 +12,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "utils/StringUtil.h"
|
#include "utils/StringUtil.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
@ -617,13 +618,27 @@ namespace Utils
|
||||||
std::wstring stringToWideString(const std::string& stringArg)
|
std::wstring stringToWideString(const std::string& stringArg)
|
||||||
{
|
{
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> stringConverter;
|
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> stringConverter;
|
||||||
return stringConverter.from_bytes(stringArg);
|
try {
|
||||||
|
return stringConverter.from_bytes(stringArg);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
LOG(LogError) << "StringUtil::stringToWideString(): Conversion failed, invalid "
|
||||||
|
"characters in source string?";
|
||||||
|
return L"";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string wideStringToString(const std::wstring& stringArg)
|
std::string wideStringToString(const std::wstring& stringArg)
|
||||||
{
|
{
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> stringConverter;
|
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> stringConverter;
|
||||||
return stringConverter.to_bytes(stringArg);
|
try {
|
||||||
|
return stringConverter.to_bytes(stringArg);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
LOG(LogError) << "StringUtil::wideStringToString(): Conversion failed, invalid "
|
||||||
|
"characters in source string?";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool startsWith(const std::string& stringArg, const std::string& start)
|
bool startsWith(const std::string& stringArg, const std::string& start)
|
||||||
|
|
Loading…
Reference in a new issue