[Protobuf] Added static_cast (#35566)

Fixes https://github.com/grpc/grpc/issues/35268

Closes #35566

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35566 from veblush:proto-buffer 02635228f5
PiperOrigin-RevId: 599954076
pull/35530/head
Esun Kim 1 year ago committed by Copybara-Service
parent 6ff898a10b
commit 8144346e2c
  1. 8
      include/grpcpp/support/proto_buffer_reader.h

@ -150,7 +150,10 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream {
}
int64_t take = (std::min)(backup_count(), static_cast<int64_t>(count));
set_backup_count(backup_count() - take);
count -= take;
// This cast is safe as the size of a serialized protobuf message
// should be smaller than 2GiB.
// (https://protobuf.dev/programming-guides/encoding/#size-limit)
count -= static_cast<int>(take);
if (count == 0) {
return true;
}
@ -163,7 +166,8 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream {
set_byte_count(ByteCount() + slice_length);
if (slice_length <= static_cast<uint64_t>(count)) {
cord->Append(MakeCordFromSlice(grpc_slice_ref(*slice())));
count -= slice_length;
// This cast is safe as above.
count -= static_cast<int>(slice_length);
} else {
cord->Append(MakeCordFromSlice(grpc_slice_split_head(slice(), count)));
set_backup_count(slice_length - count);

Loading…
Cancel
Save