Skip to content
Snippets Groups Projects
Commit 0cfcd8ac authored by U-BASIS\cray's avatar U-BASIS\cray
Browse files

Changes from standup

Brian had concerns with provding a pointer to memory we did not own
to from_bytes(). We add a character to the string so we can refernce
data.size() -2 and still get back the original string.
parent 067e0b6a
No related branches found
No related tags found
No related merge requests found
...@@ -130,9 +130,23 @@ namespace Rejistry { ...@@ -130,9 +130,23 @@ namespace Rejistry {
return L""; return L"";
} }
// We do this so we can reference the last character in the string
// data.size() -2. if we didn't add a char to the string then returned
// string would be missing the last character.
data.push_back('\0');
data.push_back('\0');
// We are unsure how from_bytes() works. Microsofts docs seem to indicate that the second pointer
// should point to the last character which will be included in the conversion.[1] However, another
// reference indicates that the data pointed to by the second pointer will not be included, which is
// what our testing has shown.[2] We previously had the second pointer point to data.size() but there were
// concerns that we were pointing to memory we did not own. As a result, we add a char to the end of every
// string so we can use data.size() - 2 and still get the original string back.
// 1. https://docs.microsoft.com/en-us/cpp/standard-library/wstring-convert-class?view=vs-2017#from_bytes
// 2. http://www.cplusplus.com/reference/locale/wstring_convert/from_bytes/
std::wstring result; std::wstring result;
try { try {
result = conv.from_bytes(reinterpret_cast<const char*>(&data[0]), reinterpret_cast<const char*>(&data[data.size()])); result = conv.from_bytes(reinterpret_cast<const char*>(&data[0]), reinterpret_cast<const char*>(&data[data.size()-2]));
} }
catch (std::exception&) catch (std::exception&)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment