From 1c013677ea4b3eb29f702b7fe7547385b78f7f62 Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Sat, 5 May 2018 14:48:53 +0100 Subject: [PATCH] dml: Fix bug when binary data was presented inside a STR field --- src/dml/types/StrField.cpp | 6 +++--- src/dml/types/WStrField.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dml/types/StrField.cpp b/src/dml/types/StrField.cpp index 028b108..aba8f8e 100644 --- a/src/dml/types/StrField.cpp +++ b/src/dml/types/StrField.cpp @@ -14,7 +14,7 @@ namespace dml if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8)) std::reverse(&data.buff[0], &data.buff[2]); ostream.write(data.buff, sizeof(USHRT)); - ostream.write(m_value.c_str(), m_value.length()); + ostream.write(m_value.data(), m_value.length()); } template <> @@ -36,7 +36,7 @@ namespace dml std::reverse(&length_data.buff[0], &length_data.buff[2]); // Read the data into a buffer - char *data = new char[length_data.value + 1] { 0 }; + char *data = new char[length_data.value]; istream.read(data, length_data.value); if (istream.fail()) { @@ -45,7 +45,7 @@ namespace dml throw parse_error(oss.str()); } - m_value = STR(data); + m_value = STR(data, length_data.value); delete[] data; } diff --git a/src/dml/types/WStrField.cpp b/src/dml/types/WStrField.cpp index c1c140a..abc6a31 100644 --- a/src/dml/types/WStrField.cpp +++ b/src/dml/types/WStrField.cpp @@ -16,7 +16,7 @@ namespace dml if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8)) std::reverse(&data.buff[0], &data.buff[2]); ostream.write(data.buff, sizeof(USHRT)); - ostream.write((char *)m_value.c_str(), m_value.length() * sizeof(char16_t)); + ostream.write((char *)m_value.data(), m_value.length() * sizeof(char16_t)); } template <> @@ -39,7 +39,7 @@ namespace dml // Read the data into a buffer size_t length = length_data.value * sizeof(char16_t); - char *data = new char[length + sizeof(char16_t)]{ 0 }; + char *data = new char[length]; istream.read(data, length); if (istream.fail()) { @@ -56,7 +56,7 @@ namespace dml std::reverse(&data[i], &data[i + 2]); } - m_value = WSTR((char16_t *)data); + m_value = WSTR((char16_t *)data, length_data.value); delete[] data; }