dml: Fix bug when binary data was presented inside a STR field

This commit is contained in:
Joshua Scott 2018-05-05 14:48:53 +01:00
parent cb4d89dad9
commit 1c013677ea
2 changed files with 6 additions and 6 deletions

View File

@ -14,7 +14,7 @@ namespace dml
if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8)) if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8))
std::reverse(&data.buff[0], &data.buff[2]); std::reverse(&data.buff[0], &data.buff[2]);
ostream.write(data.buff, sizeof(USHRT)); ostream.write(data.buff, sizeof(USHRT));
ostream.write(m_value.c_str(), m_value.length()); ostream.write(m_value.data(), m_value.length());
} }
template <> template <>
@ -36,7 +36,7 @@ namespace dml
std::reverse(&length_data.buff[0], &length_data.buff[2]); std::reverse(&length_data.buff[0], &length_data.buff[2]);
// Read the data into a buffer // 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); istream.read(data, length_data.value);
if (istream.fail()) if (istream.fail())
{ {
@ -45,7 +45,7 @@ namespace dml
throw parse_error(oss.str()); throw parse_error(oss.str());
} }
m_value = STR(data); m_value = STR(data, length_data.value);
delete[] data; delete[] data;
} }

View File

@ -16,7 +16,7 @@ namespace dml
if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8)) if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8))
std::reverse(&data.buff[0], &data.buff[2]); std::reverse(&data.buff[0], &data.buff[2]);
ostream.write(data.buff, sizeof(USHRT)); 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 <> template <>
@ -39,7 +39,7 @@ namespace dml
// Read the data into a buffer // Read the data into a buffer
size_t length = length_data.value * sizeof(char16_t); 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); istream.read(data, length);
if (istream.fail()) if (istream.fail())
{ {
@ -56,7 +56,7 @@ namespace dml
std::reverse(&data[i], &data[i + 2]); std::reverse(&data[i], &data[i + 2]);
} }
m_value = WSTR((char16_t *)data); m_value = WSTR((char16_t *)data, length_data.value);
delete[] data; delete[] data;
} }