Call copy() only if there is something to copy.

RepeatedField::begin()/end() will return NULL when the content is empty.
Passing these NULL values to std::copy() will result in runtime complains
from some compilers (e.g., vs2010).
pull/444/head
Feng Xiao 10 years ago
parent 5a9be2c6f6
commit 93d6838ab5
  1. 2
      src/google/protobuf/repeated_field.h

@ -1125,7 +1125,9 @@ template <typename Element>
inline typename RepeatedField<Element>::iterator RepeatedField<Element>::erase( inline typename RepeatedField<Element>::iterator RepeatedField<Element>::erase(
const_iterator first, const_iterator last) { const_iterator first, const_iterator last) {
size_type first_offset = first - cbegin(); size_type first_offset = first - cbegin();
if (first != last) {
Truncate(std::copy(last, cend(), begin() + first_offset) - cbegin()); Truncate(std::copy(last, cend(), begin() + first_offset) - cbegin());
}
return begin() + first_offset; return begin() + first_offset;
} }

Loading…
Cancel
Save