mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
Merge pull request #14038 from unknownbrackets/savestate-str
SaveState: Load misaligned wide strings properly
This commit is contained in:
commit
5d62610a93
@ -111,14 +111,22 @@ void Do(PointerWrap &p, std::string &x) {
|
||||
}
|
||||
|
||||
void Do(PointerWrap &p, std::wstring &x) {
|
||||
int stringLen = sizeof(wchar_t)*((int)x.length() + 1);
|
||||
int stringLen = sizeof(wchar_t) * ((int)x.length() + 1);
|
||||
Do(p, stringLen);
|
||||
|
||||
auto read = [&]() {
|
||||
std::wstring r;
|
||||
// In case unaligned, use memcpy.
|
||||
r.resize((stringLen / sizeof(wchar_t)) - 1);
|
||||
memcpy(&r[0], *p.ptr, stringLen - sizeof(wchar_t));
|
||||
return r;
|
||||
};
|
||||
|
||||
switch (p.mode) {
|
||||
case PointerWrap::MODE_READ: x = (wchar_t*)*p.ptr; break;
|
||||
case PointerWrap::MODE_READ: x = read(); break;
|
||||
case PointerWrap::MODE_WRITE: memcpy(*p.ptr, x.c_str(), stringLen); break;
|
||||
case PointerWrap::MODE_MEASURE: break;
|
||||
case PointerWrap::MODE_VERIFY: _dbg_assert_msg_(x == (wchar_t*)*p.ptr, "Savestate verification failure: \"%ls\" != \"%ls\" (at %p).\n", x.c_str(), (wchar_t*)*p.ptr, p.ptr); break;
|
||||
case PointerWrap::MODE_VERIFY: _dbg_assert_msg_(x == read(), "Savestate verification failure: \"%ls\" != \"%ls\" (at %p).\n", x.c_str(), read().c_str(), p.ptr); break;
|
||||
}
|
||||
(*p.ptr) += stringLen;
|
||||
}
|
||||
@ -127,11 +135,19 @@ void Do(PointerWrap &p, std::u16string &x) {
|
||||
int stringLen = sizeof(char16_t) * ((int)x.length() + 1);
|
||||
Do(p, stringLen);
|
||||
|
||||
auto read = [&]() {
|
||||
std::u16string r;
|
||||
// In case unaligned, use memcpy.
|
||||
r.resize((stringLen / sizeof(char16_t)) - 1);
|
||||
memcpy(&r[0], *p.ptr, stringLen - sizeof(char16_t));
|
||||
return r;
|
||||
};
|
||||
|
||||
switch (p.mode) {
|
||||
case PointerWrap::MODE_READ: x = (char16_t*)*p.ptr; break;
|
||||
case PointerWrap::MODE_READ: x = read(); break;
|
||||
case PointerWrap::MODE_WRITE: memcpy(*p.ptr, x.c_str(), stringLen); break;
|
||||
case PointerWrap::MODE_MEASURE: break;
|
||||
case PointerWrap::MODE_VERIFY: _dbg_assert_msg_(x == (char16_t*)*p.ptr, "Savestate verification failure: (at %p).\n", x.c_str()); break;
|
||||
case PointerWrap::MODE_VERIFY: _dbg_assert_msg_(x == read(), "Savestate verification failure: (at %p).\n", p.ptr); break;
|
||||
}
|
||||
(*p.ptr) += stringLen;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user