Rework bytes size check (#547)
The previous check was prone to giving warnings on various platforms.
Also there is no real need to check for other than PB_ATYPE_STATIC, as
anyone passing a pointer variable is responsible for having correctly
allocated the array.
diff --git a/pb_encode.c b/pb_encode.c
index aee120b..54cd5ba 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -842,8 +842,8 @@
return pb_encode_string(stream, NULL, 0);
}
- if ((size_t)bytes->size > ((size_t)-1) - offsetof(pb_bytes_array_t, bytes) ||
- (PB_ATYPE(field->type) == PB_ATYPE_STATIC && PB_BYTES_ARRAY_T_ALLOCSIZE(bytes->size) > field->data_size))
+ if (PB_ATYPE(field->type) == PB_ATYPE_STATIC &&
+ bytes->size > field->data_size - offsetof(pb_bytes_array_t, bytes))
{
PB_RETURN_ERROR(stream, "bytes size exceeded");
}