From 32a48679d5c0ae46376ae6a9f3afa6ce75db8b9a Mon Sep 17 00:00:00 2001 From: esaunders <esaunders@basistech.com> Date: Tue, 20 Oct 2015 12:50:34 -0400 Subject: [PATCH] Remove null bytes from strings before returning. --- rejistry++/src/RegistryByteBuffer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rejistry++/src/RegistryByteBuffer.cpp b/rejistry++/src/RegistryByteBuffer.cpp index f3e781b77..04202c0ab 100644 --- a/rejistry++/src/RegistryByteBuffer.cpp +++ b/rejistry++/src/RegistryByteBuffer.cpp @@ -77,9 +77,13 @@ namespace Rejistry { std::wstring RegistryByteBuffer::getUTF16String(const uint32_t offset, const uint32_t length) const { ByteBuffer::ByteArray &data = getData(offset, length); - std::wstring_convert<std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t> conv; - return conv.from_bytes(reinterpret_cast<const char*>(&data[0]), reinterpret_cast<const char *>(&data[0] + length)); + std::wstring result = conv.from_bytes(reinterpret_cast<const char*>(&data[0]), reinterpret_cast<const char*>(&data[0] + length)); + std::size_t firstNull = result.find_first_of(L'\0'); + if (firstNull != std::string::npos) { + result.erase(firstNull, result.size()); + } + return result; } ByteBuffer::ByteArray RegistryByteBuffer::getData() const { -- GitLab