Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: third_party/protobuf/src/google/protobuf/arena.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Update to new HEAD (b7632464b4) + restore GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
}

Powered by Google App Engine
This is Rietveld 408576698