Fix bug with decoding empty message types. Add test for the same.
Note: the bug only applies to empty message types. Empty messages of non-empty message types are not affected. Update issue 65 Status: FixedInGit
This commit is contained in:
@@ -571,7 +571,7 @@ bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[
|
|||||||
} while (pb_field_next(&iter));
|
} while (pb_field_next(&iter));
|
||||||
|
|
||||||
/* Fixup if last field was also required. */
|
/* Fixup if last field was also required. */
|
||||||
if (PB_HTYPE(last_type) == PB_HTYPE_REQUIRED)
|
if (PB_HTYPE(last_type) == PB_HTYPE_REQUIRED && iter.current->tag)
|
||||||
req_field_count++;
|
req_field_count++;
|
||||||
|
|
||||||
/* Check the whole bytes */
|
/* Check the whole bytes */
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ message SubMessage {
|
|||||||
optional fixed32 substuff3 = 3 [default = 3];
|
optional fixed32 substuff3 = 3 [default = 3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message EmptyMessage {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
enum MyEnum {
|
enum MyEnum {
|
||||||
Zero = 0;
|
Zero = 0;
|
||||||
First = 1;
|
First = 1;
|
||||||
@@ -34,6 +38,7 @@ message AllTypes {
|
|||||||
required bytes req_bytes = 15 [(nanopb).max_size = 16];
|
required bytes req_bytes = 15 [(nanopb).max_size = 16];
|
||||||
required SubMessage req_submsg = 16;
|
required SubMessage req_submsg = 16;
|
||||||
required MyEnum req_enum = 17;
|
required MyEnum req_enum = 17;
|
||||||
|
required EmptyMessage req_emptymsg = 18;
|
||||||
|
|
||||||
|
|
||||||
repeated int32 rep_int32 = 21 [(nanopb).max_count = 5];
|
repeated int32 rep_int32 = 21 [(nanopb).max_count = 5];
|
||||||
@@ -56,6 +61,7 @@ message AllTypes {
|
|||||||
repeated bytes rep_bytes = 35 [(nanopb).max_size = 16, (nanopb).max_count = 5];
|
repeated bytes rep_bytes = 35 [(nanopb).max_size = 16, (nanopb).max_count = 5];
|
||||||
repeated SubMessage rep_submsg = 36 [(nanopb).max_count = 5];
|
repeated SubMessage rep_submsg = 36 [(nanopb).max_count = 5];
|
||||||
repeated MyEnum rep_enum = 37 [(nanopb).max_count = 5];
|
repeated MyEnum rep_enum = 37 [(nanopb).max_count = 5];
|
||||||
|
repeated EmptyMessage rep_emptymsg = 38 [(nanopb).max_count = 5];
|
||||||
|
|
||||||
optional int32 opt_int32 = 41 [default = 4041];
|
optional int32 opt_int32 = 41 [default = 4041];
|
||||||
optional int64 opt_int64 = 42 [default = 4042];
|
optional int64 opt_int64 = 42 [default = 4042];
|
||||||
@@ -77,6 +83,7 @@ message AllTypes {
|
|||||||
optional bytes opt_bytes = 55 [(nanopb).max_size = 16, default = "4055"];
|
optional bytes opt_bytes = 55 [(nanopb).max_size = 16, default = "4055"];
|
||||||
optional SubMessage opt_submsg = 56;
|
optional SubMessage opt_submsg = 56;
|
||||||
optional MyEnum opt_enum = 57 [default = Second];
|
optional MyEnum opt_enum = 57 [default = Second];
|
||||||
|
optional EmptyMessage opt_emptymsg = 58;
|
||||||
|
|
||||||
// Just to make sure that the size of the fields has been calculated
|
// Just to make sure that the size of the fields has been calculated
|
||||||
// properly, i.e. otherwise a bug in last field might not be detected.
|
// properly, i.e. otherwise a bug in last field might not be detected.
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ bool check_alltypes(pb_istream_t *stream, int mode)
|
|||||||
TEST(alltypes.rep_submsg[4].substuff3 == 2016 && alltypes.rep_submsg[0].substuff3 == 3);
|
TEST(alltypes.rep_submsg[4].substuff3 == 2016 && alltypes.rep_submsg[0].substuff3 == 3);
|
||||||
|
|
||||||
TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero);
|
TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero);
|
||||||
|
TEST(alltypes.rep_emptymsg_count == 5);
|
||||||
|
|
||||||
if (mode == 0)
|
if (mode == 0)
|
||||||
{
|
{
|
||||||
@@ -120,6 +121,7 @@ bool check_alltypes(pb_istream_t *stream, int mode)
|
|||||||
TEST(alltypes.opt_submsg.substuff3 == 3);
|
TEST(alltypes.opt_submsg.substuff3 == 3);
|
||||||
TEST(alltypes.has_opt_enum == false);
|
TEST(alltypes.has_opt_enum == false);
|
||||||
TEST(alltypes.opt_enum == MyEnum_Second);
|
TEST(alltypes.opt_enum == MyEnum_Second);
|
||||||
|
TEST(alltypes.has_opt_emptymsg == false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -164,6 +166,7 @@ bool check_alltypes(pb_istream_t *stream, int mode)
|
|||||||
TEST(alltypes.opt_submsg.substuff3 == 3);
|
TEST(alltypes.opt_submsg.substuff3 == 3);
|
||||||
TEST(alltypes.has_opt_enum == true);
|
TEST(alltypes.has_opt_enum == true);
|
||||||
TEST(alltypes.opt_enum == MyEnum_Truth);
|
TEST(alltypes.opt_enum == MyEnum_Truth);
|
||||||
|
TEST(alltypes.has_opt_emptymsg == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(alltypes.end == 1099);
|
TEST(alltypes.end == 1099);
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ int main(int argc, char **argv)
|
|||||||
alltypes.rep_submsg[4].substuff3 = 2016;
|
alltypes.rep_submsg[4].substuff3 = 2016;
|
||||||
|
|
||||||
alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth;
|
alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth;
|
||||||
|
alltypes.rep_emptymsg_count = 5;
|
||||||
|
|
||||||
if (mode != 0)
|
if (mode != 0)
|
||||||
{
|
{
|
||||||
@@ -107,6 +108,7 @@ int main(int argc, char **argv)
|
|||||||
alltypes.opt_submsg.substuff2 = 3056;
|
alltypes.opt_submsg.substuff2 = 3056;
|
||||||
alltypes.has_opt_enum = true;
|
alltypes.has_opt_enum = true;
|
||||||
alltypes.opt_enum = MyEnum_Truth;
|
alltypes.opt_enum = MyEnum_Truth;
|
||||||
|
alltypes.has_opt_emptymsg = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
alltypes.end = 1099;
|
alltypes.end = 1099;
|
||||||
|
|||||||
Reference in New Issue
Block a user