Commit 7b4c18a0 authored by Peter Leschev's avatar Peter Leschev Committed by Ilya Lipnitskiy

Fixes #196

parent 7634c0e6
...@@ -258,13 +258,13 @@ get_tag_size(unsigned number) ...@@ -258,13 +258,13 @@ get_tag_size(unsigned number)
static inline size_t static inline size_t
uint32_size(uint32_t v) uint32_size(uint32_t v)
{ {
if (v < (1 << 7)) { if (v < (1UL << 7)) {
return 1; return 1;
} else if (v < (1 << 14)) { } else if (v < (1UL << 14)) {
return 2; return 2;
} else if (v < (1 << 21)) { } else if (v < (1UL << 21)) {
return 3; return 3;
} else if (v < (1 << 28)) { } else if (v < (1UL << 28)) {
return 4; return 4;
} else { } else {
return 5; return 5;
...@@ -285,13 +285,13 @@ int32_size(int32_t v) ...@@ -285,13 +285,13 @@ int32_size(int32_t v)
{ {
if (v < 0) { if (v < 0) {
return 10; return 10;
} else if (v < (1 << 7)) { } else if (v < (1UL << 7)) {
return 1; return 1;
} else if (v < (1 << 14)) { } else if (v < (1UL << 14)) {
return 2; return 2;
} else if (v < (1 << 21)) { } else if (v < (1UL << 21)) {
return 3; return 3;
} else if (v < (1 << 28)) { } else if (v < (1UL << 28)) {
return 4; return 4;
} else { } else {
return 5; return 5;
...@@ -348,15 +348,15 @@ uint64_size(uint64_t v) ...@@ -348,15 +348,15 @@ uint64_size(uint64_t v)
if (upper_v == 0) { if (upper_v == 0) {
return uint32_size((uint32_t) v); return uint32_size((uint32_t) v);
} else if (upper_v < (1 << 3)) { } else if (upper_v < (1UL << 3)) {
return 5; return 5;
} else if (upper_v < (1 << 10)) { } else if (upper_v < (1UL << 10)) {
return 6; return 6;
} else if (upper_v < (1 << 17)) { } else if (upper_v < (1UL << 17)) {
return 7; return 7;
} else if (upper_v < (1 << 24)) { } else if (upper_v < (1UL << 24)) {
return 8; return 8;
} else if (upper_v < (1U << 31)) { } else if (upper_v < (1UL << 31)) {
return 9; return 9;
} else { } else {
return 10; return 10;
......
...@@ -2149,6 +2149,18 @@ test_message_check(void) ...@@ -2149,6 +2149,18 @@ test_message_check(void)
assert(1 == protobuf_c_message_check(&m.base)); assert(1 == protobuf_c_message_check(&m.base));
} }
static void
test_large_int_packed_size(void)
{
Foo__TestMessRequiredSInt64 m = FOO__TEST_MESS_REQUIRED_SINT64__INIT;
m.test = 200;
assert(3 == foo__test_mess_required_sint64__get_packed_size(&m));
m.test = 32000;
assert(4 == foo__test_mess_required_sint64__get_packed_size(&m));
}
/* === simple testing framework === */ /* === simple testing framework === */
typedef void (*TestFunc) (void); typedef void (*TestFunc) (void);
...@@ -2284,6 +2296,8 @@ static Test tests[] = ...@@ -2284,6 +2296,8 @@ static Test tests[] =
{ "test field flags", test_field_flags }, { "test field flags", test_field_flags },
{ "test message_check()", test_message_check }, { "test message_check()", test_message_check },
{ "test large int packed size", test_large_int_packed_size },
}; };
#define n_tests (sizeof(tests)/sizeof(Test)) #define n_tests (sizeof(tests)/sizeof(Test))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment