From ab11ebea014949a513c841d90c8954f63185e1fc Mon Sep 17 00:00:00 2001 From: crs Date: Fri, 26 Mar 2004 20:59:21 +0000 Subject: [PATCH] Fixed handling of reading strings from the registry. This was broken when support for binary data was added. The terminating NUL was included in the string as a character (that's in addition to the terminating NUL added by std::string). --- lib/arch/CArchMiscWindows.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/arch/CArchMiscWindows.cpp b/lib/arch/CArchMiscWindows.cpp index 6f4e9ca2..b4010040 100644 --- a/lib/arch/CArchMiscWindows.cpp +++ b/lib/arch/CArchMiscWindows.cpp @@ -222,6 +222,11 @@ CArchMiscWindows::readBinaryOrString(HKEY key, const TCHAR* name, DWORD type) return std::string(); } + // if zero size then return empty string + if (size == 0) { + return std::string(); + } + // allocate space char* buffer = new char[size]; @@ -234,6 +239,10 @@ CArchMiscWindows::readBinaryOrString(HKEY key, const TCHAR* name, DWORD type) } // clean up and return value + if (type == REG_SZ && buffer[size - 1] == '\0') { + // don't include terminating nul; std::string will add one. + --size; + } std::string value(buffer, size); delete[] buffer; return value;