Переглянути джерело

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).
Feng Xiao 10 роки тому
батько
коміт
93d6838ab5
1 змінених файлів з 3 додано та 1 видалено
  1. 3 1
      src/google/protobuf/repeated_field.h

+ 3 - 1
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;
 }