diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2019-04-03 01:17:26 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-04-03 01:17:26 +0000 |
commit | 1ed3d35baf98269b76a2fa372dfdbb87499eb85f (patch) | |
tree | 319a18bcee1689daad880e62848e306a0051eb34 | |
parent | 7a5fd27c550c1be8b4385f71e40b010e8b51e46a (diff) | |
parent | f2e5ea768b095644932c010824a435379975a6ca (diff) | |
download | protobuf-oreo-mr1-iot-release.tar.gz |
Merge "Annotate intended unsigned overflow"android-q-preview-6android-q-preview-5android-q-preview-4android-q-preview-2.5android-o-mr1-iot-release-1.0.12oreo-mr1-iot-release
-rw-r--r-- | src/google/protobuf/io/coded_stream.h | 6 |
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) { |