Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Changes from standup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
U-BASIS\cray committed Jan 23, 2019
1 parent 067e0b6 commit 0cfcd8a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rejistry++/src/RegistryByteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,23 @@ namespace Rejistry {
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;
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&)
{
Expand Down

0 comments on commit 0cfcd8a

Please sign in to comment.