Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions compiler/grpc_c_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ GenerateHelperFunctionDefinitions(io::Printer* printer)
" size_t size = $lcclassname$__get_packed_size"
"(($classname$ *)input);\n"
" out = gpr_malloc(sizeof(uint8_t) * size);\n"
" if (out == NULL)\n"
" return 0;\n"
" size_t len = $lcclassname$__pack(($classname$ *)input, "
"out);\n"
" grpc_slice slice = grpc_slice_new(out, len, gpr_free);\n"
Expand All @@ -194,26 +196,32 @@ GenerateHelperFunctionDefinitions(io::Printer* printer)
" grpc_byte_buffer_reader reader;\n"
" grpc_slice slice;\n"
" grpc_byte_buffer_reader_init(&reader, buffer);\n"
" char *buf = NULL;\n"
" size_t buf_len = 0;\n"
" char *buf = NULL, *tmpbuf = NULL;\n"
" size_t buf_len = 0, slice_len\n"
" while (grpc_byte_buffer_reader_next(&reader, &slice) != 0) {\n"
" slice_len = GRPC_SLICE_LENGTH(slice);\n"
" if (slice_len <= 0) {\n"
" grpc_slice_unref(slice);\n"
" break;\n"
" }\n"
" if (buf == NULL) {\n"
" buf = gpr_malloc(GRPC_SLICE_LENGTH(slice));\n"
" tmpbuf = gpr_malloc(slice_len);\n"
" } else {\n"
" buf = gpr_realloc(buf, buf_len + GRPC_SLICE_LENGTH(slice));\n"
" tmpbuf = gpr_realloc(buf, buf_len + slice_len);\n"
" }\n"
" if (buf == NULL) {\n"
" if (tmpbuf == NULL) {\n"
" gpr_free(buf);\n"
" grpc_slice_unref(slice);\n"
" break;\n"
" return NULL;\n"
" }\n"
" if (memcpy(buf + buf_len, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)) == NULL) {\n"
" buf = tmpbuf;"
" if (memcpy(buf + buf_len, slice_len, slice_len) == NULL) {\n"
" gpr_free(buf);\n"
" grpc_slice_unref(slice);\n"
" return NULL;\n"
" }\n"
" buf_len += GRPC_SLICE_LENGTH(slice);\n"
" buf_len += slice_len;\n"
" grpc_slice_unref(slice);\n"
" if (buf == NULL) break;\n"
" }\n"
" h = $lcclassname$__unpack(grpc_c_get_protobuf_c_allocator(context, &allocator), buf_len, (void *)buf);\n"
" gpr_free(buf);\n"
Expand Down