[PATCH] D157300: [lld-macho]Rework error-checking in peeking at first-member in archive to avoid segfault.
Vy Nguyen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 9 06:09:33 PDT 2023
oontvoo added inline 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.
----------------
smeenai wrote:
> 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.
Thanks!
Fixed typo and moved the numberOfSymbols check to beginning.
(Still need the nested if,unfortunately, because we dont want to access the `child` if there was error )
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