[lld] r262022 - Fix unsafe dereference.
    Rui Ueyama via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri Feb 26 07:13:24 PST 2016
    
    
  
Author: ruiu
Date: Fri Feb 26 09:13:24 2016
New Revision: 262022
URL: http://llvm.org/viewvc/llvm-project?rev=262022&view=rev
Log:
Fix unsafe dereference.
Bound may point to one element beyond the end of the
vector, so *Bound is not safe.
Modified:
    lld/trunk/ELF/ICF.cpp
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=262022&r1=262021&r2=262022&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Fri Feb 26 09:13:24 2016
@@ -201,12 +201,12 @@ void ICF<ELFT>::segregate(InputSection<E
 template <class ELFT>
 void ICF<ELFT>::forEachGroup(std::vector<InputSection<ELFT> *> &V,
                              Comparator Eq) {
-  for (auto I = V.begin(), E = V.end(); I != E;) {
+  for (InputSection<ELFT> **I = V.data(), **E = I + V.size(); I != E;) {
     InputSection<ELFT> *Head = *I;
     auto Bound = std::find_if(I + 1, E, [&](InputSection<ELFT> *S) {
       return S->GroupId != Head->GroupId;
     });
-    segregate(&*I, &*Bound, Eq);
+    segregate(I, Bound, Eq);
     I = Bound;
   }
 }
    
    
More information about the llvm-commits
mailing list