Fix unsafe dereference.

Bound may point to one element beyond the end of the
vector, so *Bound is not safe.

llvm-svn: 262022
This commit is contained in:
Rui Ueyama 2016-02-26 15:13:24 +00:00
parent 7f6e9d53a3
commit eec23eb319
1 changed files with 2 additions and 2 deletions

View File

@ -201,12 +201,12 @@ void ICF<ELFT>::segregate(InputSection<ELFT> **Begin, InputSection<ELFT> **End,
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;
}
}