aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/repeated_field.h
diff options
context:
space:
mode:
authorGravatar Feng Xiao <xfxyjwf@gmail.com>2015-05-31 00:15:55 -0700
committerGravatar Feng Xiao <xfxyjwf@gmail.com>2015-05-31 00:15:55 -0700
commit93d6838ab50fc004ef2a854fca59850665b5fb9d (patch)
tree745cf479276e6e85791cf851cf562164726f13ec /src/google/protobuf/repeated_field.h
parent5a9be2c6f61201117f2d5b1106ee8e44dac972f5 (diff)
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).
Diffstat (limited to 'src/google/protobuf/repeated_field.h')
-rw-r--r--src/google/protobuf/repeated_field.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h
index 5a2fb409..14f46298 100644
--- a/src/google/protobuf/repeated_field.h
+++ b/src/google/protobuf/repeated_field.h
@@ -1125,7 +1125,9 @@ template <typename Element>
inline typename RepeatedField<Element>::iterator RepeatedField<Element>::erase(
const_iterator first, const_iterator last) {
size_type first_offset = first - cbegin();
- Truncate(std::copy(last, cend(), begin() + first_offset) - cbegin());
+ if (first != last) {
+ Truncate(std::copy(last, cend(), begin() + first_offset) - cbegin());
+ }
return begin() + first_offset;
}