From 3ddd63afb7d962171cad2da7428135d4bcb8c871 Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Thu, 15 Dec 2016 12:40:05 -0500 Subject: [PATCH] Only write if > 0 bytes --- protobuf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/protobuf.c b/protobuf.c index d42d370..b2012ba 100644 --- a/protobuf.c +++ b/protobuf.c @@ -22,8 +22,10 @@ int protobuf_encode_length_delimited(int field_number, enum WireType field_type, varint_encode(incoming_length, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_processed); *bytes_written += bytes_processed; // field value - memcpy(&buffer[*bytes_written], incoming, incoming_length); - *bytes_written += incoming_length; + if (incoming_length > 0) { + memcpy(&buffer[*bytes_written], incoming, incoming_length); + *bytes_written += incoming_length; + } return 1; }