diff options
author | 2018-02-12 19:22:31 -0800 | |
---|---|---|
committer | 2018-02-13 09:27:35 -0800 | |
commit | ac86f043735ea75a5ad79283ef50042d7448f04f (patch) | |
tree | 36662eebf21edb8ca8161b10f45101d026fc95a9 /include/grpc++/impl/codegen/proto_utils.h | |
parent | bc43b0e683678d47e14e1ecd9a2aba0ab7abc7cd (diff) | |
parent | 1b05b412688b7ae825eab8f91af042a24d4e18f4 (diff) |
Merge branch 'master' of https://github.com/grpc/grpc into channel-tracing
Diffstat (limited to 'include/grpc++/impl/codegen/proto_utils.h')
-rw-r--r-- | include/grpc++/impl/codegen/proto_utils.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/include/grpc++/impl/codegen/proto_utils.h b/include/grpc++/impl/codegen/proto_utils.h index b7636034d4..209250bba2 100644 --- a/include/grpc++/impl/codegen/proto_utils.h +++ b/include/grpc++/impl/codegen/proto_utils.h @@ -59,18 +59,22 @@ class GrpcBufferWriter : public ::grpc::protobuf::io::ZeroCopyOutputStream { bool Next(void** data, int* size) override { // Protobuf should not ask for more memory than total_size_. GPR_CODEGEN_ASSERT(byte_count_ < total_size_); + size_t remain = total_size_ - byte_count_; if (have_backup_) { slice_ = backup_slice_; have_backup_ = false; + if (GRPC_SLICE_LENGTH(slice_) > remain) { + GRPC_SLICE_SET_LENGTH(slice_, remain); + } } else { // When less than a whole block is needed, only allocate that much. // But make sure the allocated slice is not inlined. - size_t remain = total_size_ - byte_count_ > block_size_ - ? block_size_ - : total_size_ - byte_count_; + size_t allocate_length = + remain > static_cast<size_t>(block_size_) ? block_size_ : remain; slice_ = g_core_codegen_interface->grpc_slice_malloc( - remain > GRPC_SLICE_INLINED_SIZE ? remain - : GRPC_SLICE_INLINED_SIZE + 1); + allocate_length > GRPC_SLICE_INLINED_SIZE + ? allocate_length + : GRPC_SLICE_INLINED_SIZE + 1); } *data = GRPC_SLICE_START_PTR(slice_); // On win x64, int is only 32bit |