Commit b081e78b by Corentin Wallez

Compiler: avoid an undefined behavior when using erase-remove

Using that idiom on an empty vector results in an undefined behavior that I have seen cause a vector to get length -1 with clang 3.6 on Linux. BUG= Change-Id: I3bb8d8884efa29a17672b458263067644dbf0fec Reviewed-on: https://chromium-review.googlesource.com/286740Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent a455824c
......@@ -649,7 +649,11 @@ bool TCompiler::pruneUnusedFunctions(TIntermNode *root)
UnusedPredicate isUnused(&mCallDag, &functionMetadata);
TIntermSequence *sequence = rootNode->getSequence();
sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), sequence->end());
if (!sequence->empty())
{
sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), sequence->end());
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment