From f5889084338760fa65522436d2b4440b0ffeb190 Mon Sep 17 00:00:00 2001 From: Laz <16494336+Lazrius@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:23:07 +0000 Subject: [PATCH 1/2] fix: handle wstrings being different lengths and constructed correctly --- include/rfl/parsing/Parser_wstring.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rfl/parsing/Parser_wstring.hpp b/include/rfl/parsing/Parser_wstring.hpp index 49ac0111..8520cfb0 100644 --- a/include/rfl/parsing/Parser_wstring.hpp +++ b/include/rfl/parsing/Parser_wstring.hpp @@ -34,7 +34,7 @@ struct Parser { std::mbstate_t state = std::mbstate_t(); auto val = inStr.value(); - std::wstring outStr(L'\0', val.size()); + std::wstring outStr(val.size() * 2, L'\0'); // Explicitly set the size so we don't empty it when we truncate outStr.resize(val.size()); @@ -57,7 +57,7 @@ struct Parser { } std::mbstate_t state = std::mbstate_t(); - std::string outStr('\0', _str.size()); + std::string outStr(_str.size(), '\0'); outStr.resize(_str.size()); auto* ptr = _str.c_str(); @@ -71,4 +71,4 @@ struct Parser { } // namespace parsing } // namespace rfl -#endif \ No newline at end of file +#endif From bb94793da83fb6850c70ab8912beeaba5aa9bd02 Mon Sep 17 00:00:00 2001 From: Laz <16494336+Lazrius@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:27:51 +0000 Subject: [PATCH 2/2] Update Parser_wstring.hpp --- include/rfl/parsing/Parser_wstring.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rfl/parsing/Parser_wstring.hpp b/include/rfl/parsing/Parser_wstring.hpp index 8520cfb0..d9d290c7 100644 --- a/include/rfl/parsing/Parser_wstring.hpp +++ b/include/rfl/parsing/Parser_wstring.hpp @@ -37,7 +37,7 @@ struct Parser { std::wstring outStr(val.size() * 2, L'\0'); // Explicitly set the size so we don't empty it when we truncate - outStr.resize(val.size()); + outStr.resize(val.size() * 2); auto* ptr = val.c_str(); @@ -57,8 +57,8 @@ struct Parser { } std::mbstate_t state = std::mbstate_t(); - std::string outStr(_str.size(), '\0'); - outStr.resize(_str.size()); + std::string outStr(_str.size() + 1, '\0'); + outStr.resize(_str.size() + 1); auto* ptr = _str.c_str(); auto len = std::wcsrtombs(outStr.data(), &ptr, _str.size(), &state) + 1;