Index: llvm/lib/Object/Archive.cpp =================================================================== --- llvm/lib/Object/Archive.cpp +++ llvm/lib/Object/Archive.cpp @@ -168,22 +168,25 @@ } // Verify it. - if (StringOffset >= Parent->getStringTable().size()) { + StringRef ST = Parent->getStringTable(); + if (StringOffset >= ST.size()) { uint64_t ArchiveOffset = reinterpret_cast(ArMemHdr) - Parent->getData().data(); return malformedError("long name offset " + Twine(StringOffset) + " past " "the end of the string table for archive member " "header at offset " + Twine(ArchiveOffset)); } - const char *addr = Parent->getStringTable().begin() + StringOffset; + const char *Start = ST.begin() + StringOffset; // GNU long file names end with a "/\n". if (Parent->kind() == Archive::K_GNU || Parent->kind() == Archive::K_GNU64) { - StringRef::size_type End = StringRef(addr).find('\n'); - return StringRef(addr, End - 1); + StringRef::size_type End = ST.find('\n', StringOffset); + if (End == StringRef::npos) + End = ST.size(); + return StringRef(Start, End - StringOffset - 1); } - return addr; + return Start; } if (Name.startswith("#1/")) {