Ilya Lipnitskiy 733ae77e23
protobuf-c.c: fix packed repeated bool parsing
From https://developers.google.com/protocol-buffers/docs/proto3#updating:
  int32, uint32, int64, uint64, and bool are all compatible – this means
  you can change a field from one of these types to another without
  breaking forwards- or backwards-compatibility. If a number is parsed
  from the wire which doesn't fit in the corresponding type, you will
  get the same effect as if you had cast the number to that type in C++
  (e.g. if a 64-bit number is read as an int32, it will be truncated to
  32 bits).

Until this fix, protobuf-c did not conform to the rule above when it
came to deserializing non-boolean packed repeated data into a
protobuf_c_boolean array. Fully scan the varint and use parse_boolean to
truncate the resulting value.

Fixes #440
2021-03-28 12:27:51 -07:00
..
2019-05-17 13:29:06 -07:00
2019-05-16 12:30:08 -07:00
2020-05-13 13:20:48 -07:00
2017-04-09 10:54:58 +02:00
2017-04-09 10:54:58 +02:00

There are two tests.

"test-generated-code" is a simple test that can easily be adapted.
"test-generated-code2" is a comprehensive test.

--

If you have a quick problem, hack at "test-generated-code";
but i don't want that file to be too hard to navigate,
so you must eventually add a test to "test-generated-code2".

I appreciate additional test cases!
Please submit them as issues in the tracking system, or email me.

--

Here are the files involved in each test:

test.proto                      Protobuf declarations for the simple test.
test.pb-c.c                     Protobuf-C generated code based on test.proto
test.pb-c.h                     Protobuf-C generated code based on test.proto

test-full.proto                 Protobuf declarations for the exhaustive test.
test-full.pb-c.c                Protobuf-C generated code based on test-full.proto
test-full.pb-c.h                Protobuf-C generated code based on test-full.proto
test-full.pb.cc                 Protobuf (C++) generated code based on test-full.proto
test-full.pb.h                  Protobuf (C++) generated code based on test-full.proto

generated-code/
   test-generated-code.c        Actual test code.
   test-generated-code          Test executable.

generated-code2/
   cxx-generate-packed-data.cc  C++ code to generated data to compare with C.
   cxx-generate-packed-data     Program whichs generates data (using C++ api)
   test-full-cxx-output.inc     Output of cxx-generate-packed-data.
   test-generated-code2.c       Actual test code.
   test-generated-code2         Test executable.