summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-01-12 19:08:05 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-01-12 19:08:05 +0200
commit113bd7ee878ac2284c8c049fdb8dc2d2bd19f016 (patch)
treef38c617e54d763cee506c3314168bfb96a958f22 /tests
parent0f6b615ae3395734ee9a1b35185540acad18c452 (diff)
Fixed issue 1 reported by Erik Rosen:
The size of non-callback bytes-fields was miscalculated, which caused all following fields in a message to contain garbage. Previous commit contains a testcase for this. This fix changes the generated message description. If your protocol uses bytes-fields, you should regenerate *.pb.c.
Diffstat (limited to 'tests')
-rw-r--r--tests/decode_unittests.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/decode_unittests.c b/tests/decode_unittests.c
index ab12ac33..6ba6d4f2 100644
--- a/tests/decode_unittests.c
+++ b/tests/decode_unittests.c
@@ -167,14 +167,22 @@ int main()
{
pb_istream_t s;
struct { size_t size; uint8_t bytes[5]; } d;
- pb_field_t f = {1, PB_LTYPE_BYTES, 0, 0, 5, 0, 0};
+ pb_field_t f = {1, PB_LTYPE_BYTES, 0, 0, sizeof(d), 0, 0};
COMMENT("Test pb_dec_bytes")
TEST((s = S("\x00"), pb_dec_bytes(&s, &f, &d) && d.size == 0))
TEST((s = S("\x01\xFF"), pb_dec_bytes(&s, &f, &d) && d.size == 1 && d.bytes[0] == 0xFF))
- TEST((s = S("\x06xxxxxx"), !pb_dec_bytes(&s, &f, &d)))
TEST((s = S("\x05xxxxx"), pb_dec_bytes(&s, &f, &d) && d.size == 5))
TEST((s = S("\x05xxxx"), !pb_dec_bytes(&s, &f, &d)))
+
+ /* Note: the size limit on bytes-fields is not strictly obeyed, as
+ * the compiler may add some padding to the struct. Using this padding
+ * is not a very good thing to do, but it is difficult to avoid when
+ * we use only a single uint8_t to store the size of the field.
+ * Therefore this tests against a 10-byte string, while otherwise even
+ * 6 bytes should error out.
+ */
+ TEST((s = S("\x10xxxxxxxxxx"), !pb_dec_bytes(&s, &f, &d)))
}
{