diff options
Diffstat (limited to 'lldb/source/Utility/DataExtractor.cpp')
| -rw-r--r-- | lldb/source/Utility/DataExtractor.cpp | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/lldb/source/Utility/DataExtractor.cpp b/lldb/source/Utility/DataExtractor.cpp index 61aacf4169a..79a1f75d737 100644 --- a/lldb/source/Utility/DataExtractor.cpp +++ b/lldb/source/Utility/DataExtractor.cpp @@ -318,7 +318,7 @@ lldb::offset_t DataExtractor::SetData(const DataBufferSP &data_sp, // // RETURNS the byte that was extracted, or zero on failure. uint8_t DataExtractor::GetU8(offset_t *offset_ptr) const { - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, 1); + const uint8_t *data = static_cast<const uint8_t *>(GetData(offset_ptr, 1)); if (data) return *data; return 0; @@ -332,7 +332,8 @@ uint8_t DataExtractor::GetU8(offset_t *offset_ptr) const { // buffer due to being out of bounds, or insufficient data. void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst, uint32_t count) const { - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, count); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, count)); if (data) { // Copy the data into the buffer memcpy(dst, data, count); @@ -349,7 +350,8 @@ void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst, // RETURNS the uint16_t that was extracted, or zero on failure. uint16_t DataExtractor::GetU16(offset_t *offset_ptr) const { uint16_t val = 0; - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val))); if (data) { if (m_byte_order != endian::InlHostByteOrder()) val = ReadSwapInt16(data); @@ -398,10 +400,11 @@ uint64_t DataExtractor::GetU64_unchecked(offset_t *offset_ptr) const { void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint16_t) * count; - const uint16_t *src = (const uint16_t *)GetData(offset_ptr, src_size); + const uint16_t *src = + static_cast<const uint16_t *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - uint16_t *dst_pos = (uint16_t *)void_dst; + uint16_t *dst_pos = static_cast<uint16_t *>(void_dst); uint16_t *dst_end = dst_pos + count; const uint16_t *src_pos = src; while (dst_pos < dst_end) { @@ -425,7 +428,8 @@ void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst, // RETURNS the uint32_t that was extracted, or zero on failure. uint32_t DataExtractor::GetU32(offset_t *offset_ptr) const { uint32_t val = 0; - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val))); if (data) { if (m_byte_order != endian::InlHostByteOrder()) { val = ReadSwapInt32(data); @@ -445,10 +449,11 @@ uint32_t DataExtractor::GetU32(offset_t *offset_ptr) const { void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint32_t) * count; - const uint32_t *src = (const uint32_t *)GetData(offset_ptr, src_size); + const uint32_t *src = + static_cast<const uint32_t *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - uint32_t *dst_pos = (uint32_t *)void_dst; + uint32_t *dst_pos = static_cast<uint32_t *>(void_dst); uint32_t *dst_end = dst_pos + count; const uint32_t *src_pos = src; while (dst_pos < dst_end) { @@ -472,7 +477,8 @@ void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst, // RETURNS the uint64_t that was extracted, or zero on failure. uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const { uint64_t val = 0; - const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); + const uint8_t *data = + static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val))); if (data) { if (m_byte_order != endian::InlHostByteOrder()) { val = ReadSwapInt64(data); @@ -491,10 +497,11 @@ uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const { void *DataExtractor::GetU64(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint64_t) * count; - const uint64_t *src = (const uint64_t *)GetData(offset_ptr, src_size); + const uint64_t *src = + static_cast<const uint64_t *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - uint64_t *dst_pos = (uint64_t *)void_dst; + uint64_t *dst_pos = static_cast<uint64_t *>(void_dst); uint64_t *dst_end = dst_pos + count; const uint64_t *src_pos = src; while (dst_pos < dst_end) { @@ -595,10 +602,11 @@ int64_t DataExtractor::GetMaxS64Bitfield(offset_t *offset_ptr, size_t size, lsbcount = size * 8 - bitfield_bit_offset - bitfield_bit_size; if (lsbcount > 0) sval64 >>= lsbcount; - uint64_t bitfield_mask = (((uint64_t)1) << bitfield_bit_size) - 1; + uint64_t bitfield_mask = + ((static_cast<uint64_t>(1)) << bitfield_bit_size) - 1; sval64 &= bitfield_mask; // sign extend if needed - if (sval64 & (((uint64_t)1) << (bitfield_bit_size - 1))) + if (sval64 & ((static_cast<uint64_t>(1)) << (bitfield_bit_size - 1))) sval64 |= ~bitfield_mask; } return sval64; @@ -608,11 +616,12 @@ float DataExtractor::GetFloat(offset_t *offset_ptr) const { typedef float float_type; float_type val = 0.0; const size_t src_size = sizeof(float_type); - const float_type *src = (const float_type *)GetData(offset_ptr, src_size); + const float_type *src = + static_cast<const float_type *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - const uint8_t *src_data = (const uint8_t *)src; - uint8_t *dst_data = (uint8_t *)&val; + const uint8_t *src_data = reinterpret_cast<const uint8_t *>(src); + uint8_t *dst_data = reinterpret_cast<uint8_t *>(&val); for (size_t i = 0; i < sizeof(float_type); ++i) dst_data[sizeof(float_type) - 1 - i] = src_data[i]; } else { @@ -626,11 +635,12 @@ double DataExtractor::GetDouble(offset_t *offset_ptr) const { typedef double float_type; float_type val = 0.0; const size_t src_size = sizeof(float_type); - const float_type *src = (const float_type *)GetData(offset_ptr, src_size); + const float_type *src = + static_cast<const float_type *>(GetData(offset_ptr, src_size)); if (src) { if (m_byte_order != endian::InlHostByteOrder()) { - const uint8_t *src_data = (const uint8_t *)src; - uint8_t *dst_data = (uint8_t *)&val; + const uint8_t *src_data = reinterpret_cast<const uint8_t *>(src); + uint8_t *dst_data = reinterpret_cast<uint8_t *>(&val); for (size_t i = 0; i < sizeof(float_type); ++i) dst_data[sizeof(float_type) - 1 - i] = src_data[i]; } else { @@ -690,7 +700,7 @@ size_t DataExtractor::ExtractBytes(offset_t offset, offset_t length, length == 10 || length == 16 || length == 32); for (uint32_t i = 0; i < length; ++i) - ((uint8_t *)dst)[i] = src[length - i - 1]; + (static_cast<uint8_t *>(dst))[i] = src[length - i - 1]; } else ::memcpy(dst, src, length); return length; @@ -736,8 +746,8 @@ DataExtractor::CopyByteOrderedData(offset_t src_offset, offset_t src_len, !(m_byte_order == eByteOrderBig || m_byte_order == eByteOrderLittle)) return 0; - uint8_t *dst = (uint8_t *)dst_void_ptr; - const uint8_t *src = (const uint8_t *)PeekData(src_offset, src_len); + uint8_t *dst = static_cast<uint8_t *>(dst_void_ptr); + const uint8_t *src = PeekData(src_offset, src_len); if (src) { if (dst_len >= src_len) { // We are copying the entire value from src into dst. Calculate how many, @@ -806,10 +816,10 @@ DataExtractor::CopyByteOrderedData(offset_t src_offset, offset_t src_len, // non-zero and there aren't enough available bytes, nullptr will be returned // and "offset_ptr" will not be updated. const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { - const char *cstr = (const char *)PeekData(*offset_ptr, 1); + const char *cstr = reinterpret_cast<const char *>(PeekData(*offset_ptr, 1)); if (cstr) { const char *cstr_end = cstr; - const char *end = (const char *)m_end; + const char *end = reinterpret_cast<const char *>(m_end); while (cstr_end < end && *cstr_end) ++cstr_end; @@ -837,7 +847,7 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { // contain a NULL terminator byte, nullptr will be returned and "offset_ptr" // will not be updated. const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const { - const char *cstr = (const char *)PeekData(*offset_ptr, len); + const char *cstr = reinterpret_cast<const char *>(PeekData(*offset_ptr, len)); if (cstr != nullptr) { if (memchr(cstr, '\0', len) == nullptr) { return nullptr; @@ -855,7 +865,7 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const { // Returns a valid C string pointer if "offset" is a valid offset in this // object's data, else nullptr is returned. const char *DataExtractor::PeekCStr(offset_t offset) const { - return (const char *)PeekData(offset, 1); + return reinterpret_cast<const char *>(PeekData(offset, 1)); } // Extracts an unsigned LEB128 number from this object's data starting at the @@ -865,7 +875,7 @@ const char *DataExtractor::PeekCStr(offset_t offset) const { // // Returned the extracted integer value. uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { - const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); + const uint8_t *src = PeekData(*offset_ptr, 1); if (src == nullptr) return 0; @@ -878,7 +888,7 @@ uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { int shift = 7; while (src < end) { uint8_t byte = *src++; - result |= (uint64_t)(byte & 0x7f) << shift; + result |= static_cast<uint64_t>(byte & 0x7f) << shift; if ((byte & 0x80) == 0) break; shift += 7; @@ -898,7 +908,7 @@ uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { // // Returned the extracted integer value. int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { - const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); + const uint8_t *src = PeekData(*offset_ptr, 1); if (src == nullptr) return 0; @@ -915,7 +925,7 @@ int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { while (src < end) { bytecount++; byte = *src++; - result |= (int64_t)(byte & 0x7f) << shift; + result |= static_cast<int64_t>(byte & 0x7f) << shift; shift += 7; if ((byte & 0x80) == 0) break; @@ -939,7 +949,7 @@ int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { // Returns the number of bytes consumed during the extraction. uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const { uint32_t bytes_consumed = 0; - const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); + const uint8_t *src = PeekData(*offset_ptr, 1); if (src == nullptr) return 0; @@ -986,7 +996,7 @@ lldb::offset_t DataExtractor::PutToLog(Log *log, offset_t start_offset, // Reset string offset and fill the current line string with address: if (base_addr != LLDB_INVALID_ADDRESS) sstr.Printf("0x%8.8" PRIx64 ":", - (uint64_t)(base_addr + (offset - start_offset))); + static_cast<uint64_t>(base_addr + (offset - start_offset))); } switch (type) { |

