diff --git a/test/tools/llvm-objdump/Inputs/section.macho-armv7 b/test/tools/llvm-objdump/Inputs/section.macho-armv7 index 456cd3e5f69..810d5c52d33 100644 Binary files a/test/tools/llvm-objdump/Inputs/section.macho-armv7 and b/test/tools/llvm-objdump/Inputs/section.macho-armv7 differ diff --git a/test/tools/llvm-objdump/macho-sections.test b/test/tools/llvm-objdump/macho-sections.test index a7e2e81be5d..7b0d89ce505 100644 --- a/test/tools/llvm-objdump/macho-sections.test +++ b/test/tools/llvm-objdump/macho-sections.test @@ -4,4 +4,8 @@ # RUN: llvm-objdump -macho -section=__data %p/Inputs/section.macho-armv7 | FileCheck -check-prefix CHECK-ADDR %s -# CHECK-ADDR: 00000004 00000001 +# CHECK-ADDR: 00000004 00000001 00000002 + +# RUN: llvm-objdump -macho -section=__const %p/Inputs/section.macho-armv7 | FileCheck -check-prefix CHECK-BYTES %s + +# CHECK-BYTES: 0000000c 00000003 04 05 06 diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 3d5c6eceada..bcce08ec51b 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -1004,7 +1004,7 @@ static void DumpRawSectionContents(MachOObjectFile *O, const char *sect, outs() << format("%08" PRIx64, addr) << "\t"; for (j = 0; j < 4 * sizeof(int32_t) && i + j < size; j += sizeof(int32_t)) { - if (i + j + sizeof(int32_t) < size) { + if (i + j + sizeof(int32_t) <= size) { uint32_t long_word; memcpy(&long_word, sect + i + j, sizeof(int32_t)); if (O->isLittleEndian() != sys::IsLittleEndianHost) @@ -1012,7 +1012,7 @@ static void DumpRawSectionContents(MachOObjectFile *O, const char *sect, outs() << format("%08" PRIx32, long_word) << " "; } else { for (uint32_t k = 0; i + j + k < size; k++) { - uint8_t byte_word = *(sect + i + j); + uint8_t byte_word = *(sect + i + j + k); outs() << format("%02" PRIx32, (uint32_t)byte_word) << " "; } }