summaryrefslogtreecommitdiffstats
path: root/tests/decode_unittests/decode_unittests.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/decode_unittests/decode_unittests.c')
-rw-r--r--tests/decode_unittests/decode_unittests.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/decode_unittests/decode_unittests.c b/tests/decode_unittests/decode_unittests.c
index 47f0fbdb..a6f5c17e 100644
--- a/tests/decode_unittests/decode_unittests.c
+++ b/tests/decode_unittests/decode_unittests.c
@@ -150,9 +150,9 @@ int main()
{
pb_istream_t s;
pb_field_t f = {1, PB_LTYPE_SVARINT, 0, 0, 8, 0, 0};
- uint64_t d;
+ int64_t d;
- COMMENT("Test pb_dec_svarint using uint64_t")
+ COMMENT("Test pb_dec_svarint using int64_t")
TEST((s = S("\x01"), pb_dec_svarint(&s, &f, &d) && d == -1))
TEST((s = S("\x02"), pb_dec_svarint(&s, &f, &d) && d == 1))
TEST((s = S("\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x01"), pb_dec_svarint(&s, &f, &d) && d == INT64_MAX))
@@ -161,6 +161,50 @@ int main()
{
pb_istream_t s;
+ pb_field_t f = {1, PB_LTYPE_SVARINT, 0, 0, 4, 0, 0};
+ int32_t d;
+
+ COMMENT("Test pb_dec_svarint overflow detection using int32_t");
+ TEST((s = S("\xfe\xff\xff\xff\x0f"), pb_dec_svarint(&s, &f, &d)));
+ TEST((s = S("\xfe\xff\xff\xff\x10"), !pb_dec_svarint(&s, &f, &d)));
+ TEST((s = S("\xff\xff\xff\xff\x0f"), pb_dec_svarint(&s, &f, &d)));
+ TEST((s = S("\xff\xff\xff\xff\x10"), !pb_dec_svarint(&s, &f, &d)));
+ }
+
+ {
+ pb_istream_t s;
+ pb_field_t f = {1, PB_LTYPE_SVARINT, 0, 0, 4, 0, 0};
+ uint32_t d;
+
+ COMMENT("Test pb_dec_uvarint using uint32_t")
+ TEST((s = S("\x01"), pb_dec_uvarint(&s, &f, &d) && d == 1))
+ TEST((s = S("\x02"), pb_dec_uvarint(&s, &f, &d) && d == 2))
+ TEST((s = S("\xff\xff\xff\xff\x0f"), pb_dec_uvarint(&s, &f, &d) && d == UINT32_MAX))
+ }
+
+ {
+ pb_istream_t s;
+ pb_field_t f = {1, PB_LTYPE_SVARINT, 0, 0, 8, 0, 0};
+ uint64_t d;
+
+ COMMENT("Test pb_dec_uvarint using uint64_t")
+ TEST((s = S("\x01"), pb_dec_uvarint(&s, &f, &d) && d == 1))
+ TEST((s = S("\x02"), pb_dec_uvarint(&s, &f, &d) && d == 2))
+ TEST((s = S("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x01"), pb_dec_uvarint(&s, &f, &d) && d == UINT64_MAX))
+ }
+
+ {
+ pb_istream_t s;
+ pb_field_t f = {1, PB_LTYPE_SVARINT, 0, 0, 4, 0, 0};
+ uint32_t d;
+
+ COMMENT("Test pb_dec_uvarint overflow detection using int32_t");
+ TEST((s = S("\xff\xff\xff\xff\x0f"), pb_dec_uvarint(&s, &f, &d)));
+ TEST((s = S("\xff\xff\xff\xff\x10"), !pb_dec_uvarint(&s, &f, &d)));
+ }
+
+ {
+ pb_istream_t s;
pb_field_t f = {1, PB_LTYPE_FIXED32, 0, 0, 4, 0, 0};
float d;