Mercurial > hg > CbC > CbC_llvm
diff lib/Object/Archive.cpp @ 147:c2174574ed3a
LLVM 10
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 16:55:33 +0900 |
parents | 3a76565eade5 |
children |
line wrap: on
line diff
--- a/lib/Object/Archive.cpp Sat Feb 17 09:57:20 2018 +0900 +++ b/lib/Object/Archive.cpp Wed Aug 14 16:55:33 2019 +0900 @@ -1,9 +1,8 @@ //===- Archive.cpp - ar File Format implementation ------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -175,15 +174,19 @@ "the end of the string table for archive member " "header at offset " + Twine(ArchiveOffset)); } - const char *addr = Parent->getStringTable().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); + size_t End = Parent->getStringTable().find('\n', /*From=*/StringOffset); + if (End == StringRef::npos || End < 1 || + Parent->getStringTable()[End - 1] != '/') { + return malformedError("string table at long name offset " + + Twine(StringOffset) + "not terminated"); + } + return Parent->getStringTable().slice(StringOffset, End - 1); } - return addr; + return Parent->getStringTable().begin() + StringOffset; } if (Name.startswith("#1/")) { @@ -220,8 +223,8 @@ return Name.drop_back(1); } -Expected<uint32_t> ArchiveMemberHeader::getSize() const { - uint32_t Ret; +Expected<uint64_t> ArchiveMemberHeader::getSize() const { + uint64_t Ret; if (StringRef(ArMemHdr->Size, sizeof(ArMemHdr->Size)).rtrim(" ").getAsInteger(10, Ret)) { std::string Buf; @@ -508,7 +511,7 @@ StringRef Name = NameOrErr.get(); Expected<StringRef> Buf = getBuffer(); if (!Buf) - return Buf.takeError(); + return createFileError(Name, Buf.takeError()); return MemoryBufferRef(*Buf, Name); } @@ -775,19 +778,18 @@ return child_end(); if (SkipInternal) - return child_iterator(Child(this, FirstRegularData, - FirstRegularStartOfFile), - &Err); + return child_iterator::itr( + Child(this, FirstRegularData, FirstRegularStartOfFile), Err); const char *Loc = Data.getBufferStart() + strlen(Magic); Child C(this, Loc, &Err); if (Err) return child_end(); - return child_iterator(C, &Err); + return child_iterator::itr(C, Err); } Archive::child_iterator Archive::child_end() const { - return child_iterator(Child(nullptr, nullptr, nullptr), nullptr); + return child_iterator::end(Child(nullptr, nullptr, nullptr)); } StringRef Archive::Symbol::getName() const {