diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp --- a/llvm/tools/llvm-readobj/ObjDumper.cpp +++ b/llvm/tools/llvm-readobj/ObjDumper.cpp @@ -54,10 +54,16 @@ void ObjDumper::printAsStringList(StringRef StringContent, size_t StringDataOffset) { - if (StringContent.size() < StringDataOffset) { - reportUniqueWarning("error: offset is out of string contents"); + size_t StrSize = StringContent.size(); + if (StrSize == 0) + return; + if (StrSize < StringDataOffset) { + reportUniqueWarning("offset (0x" + Twine::utohexstr(StringDataOffset) + + ") is past the end of the contents (size 0x" + + Twine::utohexstr(StrSize) + ")"); return; } + const uint8_t *StrContent = StringContent.bytes_begin(); // Some formats contain additional metadata at the start which should not be // interpreted as strings. Skip these bytes, but account for them in the