aboutsummaryrefslogtreecommitdiff
path: root/pb_encode.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2019-08-22 11:31:24 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2019-08-27 14:47:20 +0300
commite29e6f4ebadef5e1ed9be1799e2dfbb12a26af67 (patch)
tree02e218489ad326c6fec5b877a35b4d0b3102c4bf /pb_encode.c
parent0101f7cdaa7be255875de06b9313c1a6e03fcb4d (diff)
downloadnanopb-c-e29e6f4ebadef5e1ed9be1799e2dfbb12a26af67.tar.gz
Don't call stream callback with count=0 (#421)
This could happen with zero-length submessages and strings. While technically valid, it is an useless call and a rare corner case that can easily lead to bugs in the callback implementation.
Diffstat (limited to 'pb_encode.c')
-rw-r--r--pb_encode.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/pb_encode.c b/pb_encode.c
index 221c0ea..64b62b4 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -100,7 +100,7 @@ pb_ostream_t pb_ostream_from_buffer(pb_byte_t *buf, size_t bufsize)
bool checkreturn pb_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
{
- if (stream->callback != NULL)
+ if (count > 0 && stream->callback != NULL)
{
if (stream->bytes_written + count > stream->max_size)
PB_RETURN_ERROR(stream, "stream full");