[PATCH] [lld] findAbsoluteAtom asserts the atom is really existing

Davide Italiano davide at freebsd.org
Tue Feb 10 21:45:38 PST 2015


Hi rafael, shankarke, ruiu,

While working on the crash triggered by the testcase reported by Rafael in "[lld] r227711 - [test] Add test for section groups and deadstrip", I stumbled upon this.
It looks like findAbsoluteAtom() does not check if the atom is actually found, neither do some of its consumers, and this might cause a NULL pointer derefence. I think it's legit to ask to the consumers to be sure about what they're looking for, so I propose to add an assert to absoluteAtom(). An alternative is that of pushing the check in the consumers of findAbsoluteAtom() but I'm more in favour of this centralized approach, unless there are some cases in which is actually possible for some consumer to specify an element that might not belong to the underlying vector of Atoms.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7549

Files:
  DefaultLayout.h

Index: DefaultLayout.h
===================================================================
--- DefaultLayout.h
+++ DefaultLayout.h
@@ -205,8 +205,10 @@

   /// \brief find a absolute atom given a name
   AbsoluteAtomIterT findAbsoluteAtom(StringRef name) {
-    return std::find_if(_absoluteAtoms.begin(), _absoluteAtoms.end(),
+    auto ret = std::find_if(_absoluteAtoms.begin(), _absoluteAtoms.end(),
                         FindByName(name));
+    assert (ret != _absoluteAtoms.end());
+    return ret;
   }

   // Output sections with the same name into a OutputSection

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7549.19728.patch
Type: text/x-patch
Size: 575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150211/1fb264f5/attachment.bin>


More information about the llvm-commits mailing list