[PATCH] D157300: [lld-macho]Rework error-checking in peeking at first-member in archive to avoid segfault.
Shoaib Meenai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 11:10:37 PDT 2023
smeenai accepted this revision.
smeenai added a comment.
This revision is now accepted and ready to land.
LGTM with comments.
================
Comment at: lld/MachO/InputFiles.cpp:2113
// Ignore the I/O error here - will be reported later.
- if (!mbOrErr) {
- llvm::consumeError(mbOrErr.takeError());
- } else if (!err) {
- if (identify_magic(mbOrErr->getBuffer()) == file_magic::macho_object) {
- if (target->wordSize == 8)
- compatArch = compatWithTargetArch(
- this, reinterpret_cast<const LP64::mach_header *>(
- mbOrErr->getBufferStart()));
- else
- compatArch = compatWithTargetArch(
- this, reinterpret_cast<const ILP32::mach_header *>(
- mbOrErr->getBufferStart()));
-
- if (!compatArch)
- return;
+ // Also avoid calling getMemoryBUfferRef() on zero-symbol archive
+ // since that crashes.
----------------
Typo: BUffer -> Buffer
I think this would be cleaner as an early return, instead of nesting everything else inside it, since zero symbols should mean the loop below is a no-op as well.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157300/new/
https://reviews.llvm.org/D157300
More information about the llvm-commits
mailing list