aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2019-04-03 01:17:26 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-04-03 01:17:26 +0000
commit1ed3d35baf98269b76a2fa372dfdbb87499eb85f (patch)
tree319a18bcee1689daad880e62848e306a0051eb34
parent7a5fd27c550c1be8b4385f71e40b010e8b51e46a (diff)
parentf2e5ea768b095644932c010824a435379975a6ca (diff)
downloadprotobuf-oreo-mr1-iot-release.tar.gz
-rw-r--r--src/google/protobuf/io/coded_stream.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h
index c81a33ac6..7b742a18e 100644
--- a/src/google/protobuf/io/coded_stream.h
+++ b/src/google/protobuf/io/coded_stream.h
@@ -985,7 +985,11 @@ inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
}
// Slow path
last_tag_ = ReadTagFallback(first_byte_or_zero);
- return std::make_pair(last_tag_, static_cast<uint32>(last_tag_ - 1) < cutoff);
+ // If last_tag_ == 0 we want to return { 0, false } so the following overflow is intended.
+ // We use __builtin_add_overflow to appease the sub-overflow UB sanitizer.
+ uint32_t last_tag_minus_one;
+ __builtin_add_overflow(last_tag_, -1, &last_tag_minus_one);
+ return std::make_pair(last_tag_, last_tag_minus_one < cutoff);
}
inline bool CodedInputStream::LastTagWas(uint32 expected) {