[PATCH] D157027: [lld-macho][nfc]Add bounds check before attempting to dereferencing iterators.

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 10:16:22 PDT 2023


oontvoo added inline comments.


================
Comment at: lld/MachO/Arch/ARM64.cpp:608
         [](uint64_t off, const Section *sec) { return off < sec->addr; }));
+    if (secIt < obj.sections.begin() || secIt > obj.sections.end() ||
+        secIt == obj.sections.end())
----------------
MaskRay wrote:
> `secIt >= obj.sections.end()` should be impossible.
> 
> It's better to check whether the `upper_bound` result is out-of-bounds before invoking `std::prev`.
turnt out we can simply check whether sections or subsections are empty to avoid getting an out-of-bound iter.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157027/new/

https://reviews.llvm.org/D157027



More information about the llvm-commits mailing list