From 5a9be2c6f61201117f2d5b1106ee8e44dac972f5 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Sun, 31 May 2015 00:14:23 -0700 Subject: Fix MapAllocator::destroy() bug. destroy() should always call the destructor because the caller may rely on the destructor to do clean-ups. --- src/google/protobuf/map.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index c16fbed2..96d2f201 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -176,14 +176,12 @@ class Map { template void destroy(NodeType* p) { - if (arena_ == NULL) p->~NodeType(); + p->~NodeType(); } #else void construct(pointer p, const_reference t) { new (p) value_type(t); } - void destroy(pointer p) { - if (arena_ == NULL) p->~value_type(); - } + void destroy(pointer p) { p->~value_type(); } #endif template @@ -201,10 +199,10 @@ class Map { return arena_ != other.arena_; } - // To support Visual Studio 2008 - size_type max_size() const { - return std::numeric_limits::max(); - } + // To support Visual Studio 2008 + size_type max_size() const { + return std::numeric_limits::max(); + } private: Arena* arena_; -- cgit v1.2.3 From 93d6838ab50fc004ef2a854fca59850665b5fb9d Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Sun, 31 May 2015 00:15:55 -0700 Subject: 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(-) (limited to 'src') 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 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; } -- cgit v1.2.3