| Index: third_party/protobuf/src/google/protobuf/arena.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/arena.cc b/third_party/protobuf/src/google/protobuf/arena.cc
|
| index 613e5897144151967594abc84da94bc610cb0ce2..aa4e587c746740e28cecae86e4aa240d3d29d81a 100755
|
| --- a/third_party/protobuf/src/google/protobuf/arena.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/arena.cc
|
| @@ -30,6 +30,9 @@
|
|
|
| #include <google/protobuf/arena.h>
|
|
|
| +#include <algorithm>
|
| +#include <limits>
|
| +
|
|
|
| #ifdef ADDRESS_SANITIZER
|
| #include <sanitizer/asan_interface.h>
|
| @@ -125,20 +128,14 @@ Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n,
|
| } else {
|
| size = start_block_size;
|
| }
|
| - if (n > size - kHeaderSize) {
|
| - // TODO(sanjay): Check if n + kHeaderSize would overflow
|
| - size = kHeaderSize + n;
|
| - }
|
| + // Verify that n + kHeaderSize won't overflow.
|
| + GOOGLE_CHECK_LE(n, std::numeric_limits<size_t>::max() - kHeaderSize);
|
| + size = std::max(size, kHeaderSize + n);
|
|
|
| Block* b = reinterpret_cast<Block*>(options_.block_alloc(size));
|
| b->pos = kHeaderSize + n;
|
| b->size = size;
|
| - if (b->avail() == 0) {
|
| - // Do not attempt to reuse this block.
|
| - b->owner = NULL;
|
| - } else {
|
| - b->owner = me;
|
| - }
|
| + b->owner = me;
|
| #ifdef ADDRESS_SANITIZER
|
| // Poison the rest of the block for ASAN. It was unpoisoned by the underlying
|
| // malloc but it's not yet usable until we return it as part of an allocation.
|
| @@ -223,9 +220,7 @@ void* Arena::SlowAlloc(size_t n) {
|
| }
|
| b = NewBlock(me, b, n, options_.start_block_size, options_.max_block_size);
|
| AddBlock(b);
|
| - if (b->owner == me) { // If this block can be reused (see NewBlock()).
|
| - SetThreadCacheBlock(b);
|
| - }
|
| + SetThreadCacheBlock(b);
|
| return reinterpret_cast<char*>(b) + kHeaderSize;
|
| }
|
|
|
|
|