diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-03-05 22:14:27 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-03-10 20:20:58 (GMT) |
commit | 3ff95f3b0b1eed95aa6e4d6baa59c68a047072ea (patch) | |
tree | 805e8e39cee6ad7163b77e969f0afa4449621a27 /Source | |
parent | 1a8e4c86921e8b018be950924dc54c532134feb5 (diff) | |
download | CMake-3ff95f3b0b1eed95aa6e4d6baa59c68a047072ea.zip CMake-3ff95f3b0b1eed95aa6e4d6baa59c68a047072ea.tar.gz CMake-3ff95f3b0b1eed95aa6e4d6baa59c68a047072ea.tar.bz2 |
cmAlgorithms: Add early return in cmRemoveIndices.
Avoid derefencing the iterator and segfaulting if the range
is empty.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAlgorithms.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index b9d7e78..be57da3 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -237,6 +237,11 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem) { typename InputRange::const_iterator remIt = rem.begin(); typename InputRange::const_iterator remEnd = rem.end(); + const typename Range::iterator rangeEnd = r.end(); + if (remIt == remEnd) + { + return rangeEnd; + } typename Range::iterator writer = r.begin(); std::advance(writer, *remIt); @@ -244,7 +249,6 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem) typename InputRange::value_type prevRem = *remIt; ++remIt; size_t count = 1; - const typename Range::iterator rangeEnd = r.end(); for ( ; writer != rangeEnd && remIt != remEnd; ++count, ++remIt) { std::advance(pivot, *remIt - prevRem); |