SaveState: Load misaligned wide strings properly.
This commit is contained in:
parent
8205f9b6f2
commit
be4c905373
1 changed files with 21 additions and 5 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue