summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/DataEncoder.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2017-12-10 22:54:07 +0000
committerDavide Italiano <davide@freebsd.org>2017-12-10 22:54:07 +0000
commitd752d6b4bec468a6c3eab28c213909a7a8aa2f9b (patch)
tree43d06ccce4131b243ccb4d1a1d8135f5cc37fcbd /lldb/source/Utility/DataEncoder.cpp
parent6b1f532ccfb6983b04e8d9064d00be25eba45710 (diff)
downloadbcm5719-llvm-d752d6b4bec468a6c3eab28c213909a7a8aa2f9b.tar.gz
bcm5719-llvm-d752d6b4bec468a6c3eab28c213909a7a8aa2f9b.zip
[DataEncoder] Replace buggy versions of write functions.
They cause an ubsan error when ran through the testsuite (store to misaligned address is UB). This commit kills two birds with one stone, as we also remove some code while fixing it. <rdar://problem/35941757> llvm-svn: 320335
Diffstat (limited to 'lldb/source/Utility/DataEncoder.cpp')
-rw-r--r--lldb/source/Utility/DataEncoder.cpp44
1 files changed, 8 insertions, 36 deletions
diff --git a/lldb/source/Utility/DataEncoder.cpp b/lldb/source/Utility/DataEncoder.cpp
index f7ce46889d2..94cc19769ab 100644
--- a/lldb/source/Utility/DataEncoder.cpp
+++ b/lldb/source/Utility/DataEncoder.cpp
@@ -12,6 +12,7 @@
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/Endian.h"
+#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h" // for llvm_unreachable
#include "llvm/Support/MathExtras.h"
@@ -22,36 +23,7 @@
using namespace lldb;
using namespace lldb_private;
-
-static inline void WriteInt16(unsigned char *ptr, unsigned offset,
- uint16_t value) {
- *(uint16_t *)(ptr + offset) = value;
-}
-
-static inline void WriteInt32(unsigned char *ptr, unsigned offset,
- uint32_t value) {
- *(uint32_t *)(ptr + offset) = value;
-}
-
-static inline void WriteInt64(unsigned char *ptr, unsigned offset,
- uint64_t value) {
- *(uint64_t *)(ptr + offset) = value;
-}
-
-static inline void WriteSwappedInt16(unsigned char *ptr, unsigned offset,
- uint16_t value) {
- *(uint16_t *)(ptr + offset) = llvm::ByteSwap_16(value);
-}
-
-static inline void WriteSwappedInt32(unsigned char *ptr, unsigned offset,
- uint32_t value) {
- *(uint32_t *)(ptr + offset) = llvm::ByteSwap_32(value);
-}
-
-static inline void WriteSwappedInt64(unsigned char *ptr, unsigned offset,
- uint64_t value) {
- *(uint64_t *)(ptr + offset) = llvm::ByteSwap_64(value);
-}
+using namespace llvm::support::endian;
//----------------------------------------------------------------------
// Default constructor.
@@ -202,9 +174,9 @@ uint32_t DataEncoder::PutU8(uint32_t offset, uint8_t value) {
uint32_t DataEncoder::PutU16(uint32_t offset, uint16_t value) {
if (ValidOffsetForDataOfSize(offset, sizeof(value))) {
if (m_byte_order != endian::InlHostByteOrder())
- WriteSwappedInt16(m_start, offset, value);
+ write16be(m_start, offset + value);
else
- WriteInt16(m_start, offset, value);
+ write16le(m_start, offset + value);
return offset + sizeof(value);
}
@@ -214,9 +186,9 @@ uint32_t DataEncoder::PutU16(uint32_t offset, uint16_t value) {
uint32_t DataEncoder::PutU32(uint32_t offset, uint32_t value) {
if (ValidOffsetForDataOfSize(offset, sizeof(value))) {
if (m_byte_order != endian::InlHostByteOrder())
- WriteSwappedInt32(m_start, offset, value);
+ write32be(m_start, offset + value);
else
- WriteInt32(m_start, offset, value);
+ write32le(m_start, offset + value);
return offset + sizeof(value);
}
@@ -226,9 +198,9 @@ uint32_t DataEncoder::PutU32(uint32_t offset, uint32_t value) {
uint32_t DataEncoder::PutU64(uint32_t offset, uint64_t value) {
if (ValidOffsetForDataOfSize(offset, sizeof(value))) {
if (m_byte_order != endian::InlHostByteOrder())
- WriteSwappedInt64(m_start, offset, value);
+ write64be(m_start, offset + value);
else
- WriteInt64(m_start, offset, value);
+ write64le(m_start, offset + value);
return offset + sizeof(value);
}
OpenPOWER on IntegriCloud