From eec23eb319daa851d362fed24649ffa2717e1e52 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 26 Feb 2016 15:13:24 +0000 Subject: [PATCH] Fix unsafe dereference. Bound may point to one element beyond the end of the vector, so *Bound is not safe. llvm-svn: 262022 --- lld/ELF/ICF.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 960d928b510a..f41698e17a02 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -201,12 +201,12 @@ void ICF::segregate(InputSection **Begin, InputSection **End, template void ICF::forEachGroup(std::vector *> &V, Comparator Eq) { - for (auto I = V.begin(), E = V.end(); I != E;) { + for (InputSection **I = V.data(), **E = I + V.size(); I != E;) { InputSection *Head = *I; auto Bound = std::find_if(I + 1, E, [&](InputSection *S) { return S->GroupId != Head->GroupId; }); - segregate(&*I, &*Bound, Eq); + segregate(I, Bound, Eq); I = Bound; } }