From a1689a142ca171d1e8449c6d0a7d4d3b016a2948 Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Fri, 30 Mar 2018 21:40:05 +0100 Subject: [PATCH] dml: Fix a problem that would have only been apparent on big-endian PCs --- src/dml/types/DblField.cpp | 4 ++-- src/dml/types/FltField.cpp | 4 ++-- src/dml/types/GidField.cpp | 4 ++-- src/dml/types/IntField.cpp | 4 ++-- src/dml/types/ShrtField.cpp | 4 ++-- src/dml/types/StrField.cpp | 4 ++-- src/dml/types/UIntField.cpp | 4 ++-- src/dml/types/UShrtField.cpp | 4 ++-- src/dml/types/WStrField.cpp | 6 +++--- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/dml/types/DblField.cpp b/src/dml/types/DblField.cpp index a7c2133..86e389a 100644 --- a/src/dml/types/DblField.cpp +++ b/src/dml/types/DblField.cpp @@ -14,7 +14,7 @@ namespace dml ValueBytes data; data.value = m_value; if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[7]); + std::reverse(&data.buff[0], &data.buff[8]); ostream.write(data.buff, sizeof(DBL)); } @@ -26,7 +26,7 @@ namespace dml ValueBytes data; istream.read(data.buff, sizeof(DBL)); if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[3]); + std::reverse(&data.buff[0], &data.buff[8]); m_value = data.value; } diff --git a/src/dml/types/FltField.cpp b/src/dml/types/FltField.cpp index e79b144..59ae031 100644 --- a/src/dml/types/FltField.cpp +++ b/src/dml/types/FltField.cpp @@ -14,7 +14,7 @@ namespace dml ValueBytes data; data.value = m_value; if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[3]); + std::reverse(&data.buff[0], &data.buff[4]); ostream.write(data.buff, sizeof(FLT)); } @@ -26,7 +26,7 @@ namespace dml ValueBytes data; istream.read(data.buff, sizeof(FLT)); if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[3]); + std::reverse(&data.buff[0], &data.buff[4]); m_value = data.value; } diff --git a/src/dml/types/GidField.cpp b/src/dml/types/GidField.cpp index 94ccd53..d38a69f 100644 --- a/src/dml/types/GidField.cpp +++ b/src/dml/types/GidField.cpp @@ -12,7 +12,7 @@ namespace dml ValueBytes data; data.value = m_value; if (data.buff[0] == ((m_value & 0xFF00000000000000) >> 56)) - std::reverse(&data.buff[0], &data.buff[7]); + std::reverse(&data.buff[0], &data.buff[8]); ostream.write(data.buff, sizeof(GID)); } @@ -24,7 +24,7 @@ namespace dml ValueBytes data; istream.read(data.buff, sizeof(GID)); if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[7]); + std::reverse(&data.buff[0], &data.buff[8]); m_value = data.value; } diff --git a/src/dml/types/IntField.cpp b/src/dml/types/IntField.cpp index 0183585..aa4995e 100644 --- a/src/dml/types/IntField.cpp +++ b/src/dml/types/IntField.cpp @@ -12,7 +12,7 @@ namespace dml ValueBytes data; data.value = m_value; if (data.buff[0] == ((m_value & 0xFF000000) >> 24)) - std::reverse(&data.buff[0], &data.buff[3]); + std::reverse(&data.buff[0], &data.buff[4]); ostream.write(data.buff, sizeof(INT)); } @@ -24,7 +24,7 @@ namespace dml ValueBytes data; istream.read(data.buff, sizeof(INT)); if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[3]); + std::reverse(&data.buff[0], &data.buff[4]); m_value = data.value; } diff --git a/src/dml/types/ShrtField.cpp b/src/dml/types/ShrtField.cpp index cfde347..17bcb60 100644 --- a/src/dml/types/ShrtField.cpp +++ b/src/dml/types/ShrtField.cpp @@ -12,7 +12,7 @@ namespace dml ValueBytes data; data.value = m_value; if (data.buff[0] == ((m_value & 0xFF00) >> 8)) - std::reverse(&data.buff[0], &data.buff[1]); + std::reverse(&data.buff[0], &data.buff[2]); ostream.write(data.buff, sizeof(SHRT)); } @@ -24,7 +24,7 @@ namespace dml ValueBytes data; istream.read(data.buff, sizeof(SHRT)); if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[1]); + std::reverse(&data.buff[0], &data.buff[2]); m_value = data.value; } diff --git a/src/dml/types/StrField.cpp b/src/dml/types/StrField.cpp index bf709d5..88e22dc 100644 --- a/src/dml/types/StrField.cpp +++ b/src/dml/types/StrField.cpp @@ -12,7 +12,7 @@ namespace dml ValueBytes data; data.value = m_value.length(); if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8)) - std::reverse(&data.buff[0], &data.buff[1]); + std::reverse(&data.buff[0], &data.buff[2]); ostream.write(data.buff, sizeof(USHRT)); ostream.write(m_value.c_str(), m_value.length()); } @@ -26,7 +26,7 @@ namespace dml ValueBytes length_data; istream.read(length_data.buff, sizeof(USHRT)); if (endianness_check.buff[0] == 0x01) - std::reverse(&length_data.buff[0], &length_data.buff[1]); + 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 }; diff --git a/src/dml/types/UIntField.cpp b/src/dml/types/UIntField.cpp index dbe5b74..40326d0 100644 --- a/src/dml/types/UIntField.cpp +++ b/src/dml/types/UIntField.cpp @@ -12,7 +12,7 @@ namespace dml ValueBytes data; data.value = m_value; if (data.buff[0] == ((m_value & 0xFF000000) >> 24)) - std::reverse(&data.buff[0], &data.buff[3]); + std::reverse(&data.buff[0], &data.buff[4]); ostream.write(data.buff, sizeof(UINT)); } @@ -24,7 +24,7 @@ namespace dml ValueBytes data; istream.read(data.buff, sizeof(UINT)); if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[3]); + std::reverse(&data.buff[0], &data.buff[4]); m_value = data.value; } diff --git a/src/dml/types/UShrtField.cpp b/src/dml/types/UShrtField.cpp index 41b409c..88aabfa 100644 --- a/src/dml/types/UShrtField.cpp +++ b/src/dml/types/UShrtField.cpp @@ -12,7 +12,7 @@ namespace dml ValueBytes data; data.value = m_value; if (data.buff[0] == ((m_value & 0xFF00) >> 8)) - std::reverse(&data.buff[0], &data.buff[1]); + std::reverse(&data.buff[0], &data.buff[2]); ostream.write(data.buff, sizeof(USHRT)); } @@ -24,7 +24,7 @@ namespace dml ValueBytes data; istream.read(data.buff, sizeof(USHRT)); if (endianness_check.buff[0] == 0x01) - std::reverse(&data.buff[0], &data.buff[1]); + std::reverse(&data.buff[0], &data.buff[2]); m_value = data.value; } diff --git a/src/dml/types/WStrField.cpp b/src/dml/types/WStrField.cpp index e0c9fa7..3cb5dad 100644 --- a/src/dml/types/WStrField.cpp +++ b/src/dml/types/WStrField.cpp @@ -12,7 +12,7 @@ namespace dml ValueBytes data; data.value = m_value.length(); if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8)) - std::reverse(&data.buff[0], &data.buff[1]); + 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)); } @@ -26,7 +26,7 @@ namespace dml ValueBytes length_data; istream.read(length_data.buff, sizeof(USHRT)); if (endianness_check.buff[0] == 0x01) - std::reverse(&length_data.buff[0], &length_data.buff[1]); + std::reverse(&length_data.buff[0], &length_data.buff[2]); // Read the data into a buffer size_t length = length_data.value * sizeof(char16_t); @@ -35,7 +35,7 @@ namespace dml for (int i = 0; i < length; i += 2) { if (endianness_check.buff[0] == 0x01) - std::reverse(&data[i], &data[i + 1]); + std::reverse(&data[i], &data[i + 2]); } m_value = WSTR((char16_t *)data); delete[] data;