From 93d6838ab50fc004ef2a854fca59850665b5fb9d Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Sun, 31 May 2015 00:15:55 -0700 Subject: [PATCH] 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). --- src/google/protobuf/repeated_field.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 5a2fb409df..14f46298d4 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -1125,7 +1125,9 @@ template inline typename RepeatedField::iterator RepeatedField::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; }