58 Commits

Author SHA1 Message Date
Robert Edmonds
a255fb20ae test-generated-code2: Ignore -Wdeclaration-after-statement
This file uses declarations after statements and fixing it would make
the code less readable, so silence this particular diagnostic in this
particular file.
2023-07-09 00:00:12 -04:00
Robert Edmonds
20d45b1179 t/: Add syntax = "proto2"; where necessary to silence protoc
Since we now require protobuf >= 3.0.0, we don't have to support older
protobuf versions that don't recognize the `syntax` syntax, so we can
put `syntax = "proto2";` on these proto files to silence the protoc
compiler's diagnostic "No syntax specified for the proto file".
2023-07-08 23:19:16 -04:00
Robert Edmonds
de5ea41b4f t/: Use "int main(void)" for the main C signature
This commit updates a few tests where we aren't using the correct C
signature for main() or are not using any of its parameters (in the
case of t/version/version.c.)
2023-07-08 20:52:09 -04:00
Robert Edmonds
7c6b54b162
Merge pull request #467 from protobuf-c/issue-440
protobuf-c.c: fix packed repeated bool parsing
2021-04-06 20:18:34 -04:00
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
Ilya Lipnitskiy
7df109917a
protoc-c: add c_package option
This option allows to override the top-level 'package' setting, or even
remove the package prefix altogether (if set to "").

Fixes #322
2021-03-21 21:11:51 -07:00
Ilya Lipnitskiy
f486c8ed66
protoc-c: add use_oneof_field_name option
Allows for generic oneof offset lookups based on the name of the oneof,
instead of having to know the field name. All oneof fields should have
the same offset, since they are members of a union.

Fixes #204
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
dfb6e300fa
protoc-c: add const_strings option
Keep default as false to preserve backwards compatibility.

Fixes #239
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
cebe3d03f9
protoc-c: add string as bytes option
Allows treating proto strings as ProtobufCBinaryData to work around
limitations such as NULL characters in strings, which are allowed in
protobuf, but not allowed in 'char *' types.

Fixes #203
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
baa860ff97
protoc-c: add options for function generation
Add options controller helper function generation. Preserve existing
behavior of not generating pack/unpack functions for sub-messages if
option is not explicitly set.

Fixes #240
Fixes #442
2021-03-21 21:11:49 -07:00
Ilya Lipnitskiy
883b1acc1b
protoc-c: add no_generate option
Allows suppression of .pb-c.{c,h} file generation on a .proto file
basis.

protobuf-c.proto: Use the new option in itself, because the options are
never used by protobuf-c runtime, only by the protoc-gen-c compiler.

t/test-full.proto: import protobuf-c.proto to test that
protobuf-c.pb-c.h dependency does not get included in test-full.pb-c.h.
2021-03-21 21:11:49 -07:00
Ilya Lipnitskiy
4c86c6b333 Add test for #389 2020-05-13 13:20:48 -07:00
Ilya Lipnitskiy
93afe2d52d c_message.cc: Resolve name conflict (Fixes #389) 2020-05-12 12:21:48 -07:00
Adam Cozzette
5ee9afdc15 Fixed some test assertions in test-generated-code2.c
I fixed a couple test assertions here that seemed to be accidentally
using assignment (=) instead of equality (==).
2019-08-27 11:07:26 -07:00
Robert Edmonds
a6556fb372
Merge pull request #358 from ugurkoltuk-adyen/ugurkoltuk-adyen/message_check_fix
Fix a SEGV on on protobuf_c_message_check on messages with 'oneof's inside
2019-05-18 17:52:13 -04:00
Robert Edmonds
ffe38d4df5
Merge branch 'next' into ilya/issue330 2019-05-18 17:02:29 -04:00
Ilya Lipnitskiy
6aa7dc7a10 Add test case for #330 2019-05-17 13:29:06 -07:00
Adam Cozzette
d58d7ca271 Fixed out-of-bounds read
The scan_length_prefixed_data() function returns the number of bytes
taken up by a varint length delimiter, plus the actual value of that
delimiter. Since it returns a uint32_t, a delimiter of 2^32 - 1 (or
close to that) could cause the return value to overflow and result in an
incorrect value.

At first I tried to fix it by making scan_length_prefixed_data() use a
size_t for its result, but I realized this would have no effect on
32-bit systems. To fix the problem for 32-bit, I changed the function to
return early if the length is 2 GiB or more (protobuf messages are not
allowed to be that large). I kept the size_t change anyway, since the
result will ultimately be stored in a size_t (ScannedMember.len) and we
might as well stay consistent with that.

Signed-off-by: Adam Cozzette <acozzette@google.com>
2019-05-16 12:30:08 -07:00
Hayri Ugur Koltuk
ad6952d9f2 Add test case for protobuf_c_check SEGV on unpopulated oneof member
Signed-off-by: Hayri Ugur Koltuk <ugur.koltuk@adyen.com>
2019-04-16 09:30:08 +02:00
Robert Edmonds
7456d16212 t/generated-code2/cxx-generate-packed-data.cc: Fix build failure on newer protobuf
google::protobuf::Message::Reflection has been removed in newer versions
of protobuf. The replacement is google::protobuf::Reflection.

protobuf in commit 779f61c6a3ce02a119e28e802f229e61b69b9046 ("Integrate
recent changes from google3.", from August 2008) changed the following
in message.h:

    @@ -336,7 +337,8 @@ class LIBPROTOBUF_EXPORT Message {

       // Introspection ---------------------------------------------------

    -  class Reflection;  // Defined below.
    +  // Typedef for backwards-compatibility.
    +  typedef google::protobuf::Reflection Reflection;

The "typedef for backwards-compatibility" apparently lasted ten years
until protobuf commit 6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3
("Down-integrate from google3.", from August 2018) which finally removed
the typedef:

    @@ -327,8 +344,6 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {

       // Introspection ---------------------------------------------------

    -  // Typedef for backwards-compatibility.
    -  typedef google::protobuf::Reflection Reflection;

This commit updates the only use of this typedef (in the test suite) to
directly refer to the replacement, google::protobuf::Reflection. This
fixes the build failure in the test suite.
2019-04-10 20:47:48 -04:00
Paolo Borelli
2a46af4278 proto3: make strings default to "" instead of NULL
The spec talks about "empty string" and other languages like C#
return a zero length string and not null.
This is useful because when moving from proto2's "required string"
to a proto3's plain string we will be guaranteed that we
never get a null pointer.
The tradeoff is adding a special case to the library but avoiding
a lot of null checks in the calling code.
The current code is already special casing "" in pack_string.
2017-06-12 09:32:39 +02:00
Paolo Borelli
13b6e1fd00 Improve proto3 unit test
Make sure we actually include the proto3 generated header and
test nested submessages
2017-04-09 10:54:58 +02:00
Robert Edmonds
c48d932003 Merge pull request #228 from pbor/wip/proto3
proto3 support
2017-02-25 14:20:04 -08:00
Robert Edmonds
1442642234 t/issue251/: Add test case for #251 2017-02-25 15:52:39 -05:00
Robert Edmonds
956ea86712 GenerateStructDefinition(): Append oneof name when forcing enums to be int size
This commit fixes a problem identified in #251. When generating the
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE directive at the end of the enum
values generated for a oneof, we inadvertently only included the
protobuf class name in the call to the directive. This breaks if there
is more than one oneof per protobuf class, which causes duplicate enum
names to be generated.

This issue is fixed by also appending the oneof's name to the protobuf
class name when generating the PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE
directive, which should cause unique enum names to be generated.

This changes the enum name that is generated, but these names are
implementation details since they are sentinel values that only exist to
force the compiler to size the enum type correctly.

(The test case for #220 is updated since that test relies on the
oneof implementation details in the code generator.)
2017-02-25 15:52:39 -05:00
Robert Edmonds
424c498728 Merge pull request #255 from ewxrjk/free-null
Document and extend the effect of passing NULL to ..._free_unpacked functions
2017-02-25 12:49:38 -08:00
Richard Kettlewell
c23065e4b1 Allowing <type>__free_unpacked(NULL, ...)
This makes __free_unpacked() consistent with free(), and simplifies
callers by allowing them to indiscriminately free message objects
without regard to whether they have been allocated or not.
2017-02-25 19:59:17 +00:00
Robert Edmonds
d89895de3c t/issue220/: Add test case for #220 2017-02-25 14:49:09 -05:00
Paolo Borelli
2f22519f58 Add basic proto3 test
Same code of the proto2 test but with the corresponding proto3 file
2016-10-30 10:06:52 +01:00
Ilya Lipnitskiy
2ea8fc7087 test-generated-code2.c: Add default value test 2016-04-22 11:35:14 -07:00
Ilya Lipnitskiy
a8d746a27c t: Add coverage
Remove a redundant test and add two large number test cases.
2015-12-12 22:06:41 -08:00
Peter Leschev
7b4c18a082 Fixes #196 2015-12-12 20:36:35 -08:00
Ilya Lipnitskiy
7634c0e6e6 protobuf-c.c: Pack negative enum values correctly
Fix a few casts where ints were cast to uints unnecessarily

Fixes #199. Previously, enums were treated as uint32's, but they need to
be treated as int32's instead.

t: Add a few test cases with negative enum values
2015-12-12 20:36:35 -08:00
Ilya Lipnitskiy
8debedbc3c test-generated-code2.c: Don't call memcmp with a NULL pointer 2015-12-12 17:43:01 -08:00
Ilya Lipnitskiy
0e2d3c09e2 Rename LITE_RUNTIME to CODE_SIZE 2015-10-30 15:54:00 -07:00
Ilya Lipnitskiy
be99a7ac31 t: Add tests for the LITE_RUNTIME optimization option 2015-03-15 20:01:03 -07:00
Ilya Lipnitskiy
617fa7ef6f test-generated-code2.c: Cosmetic change 2015-02-14 17:28:36 -08:00
Oleg Efimov
5238d655b9 protobuf-c.c: Better input checks in protobuf_c_message_free_unpacked
Check for NULL pointer for repeated fields passed to protobuf_c_message_free_unpacked

Closes #177
2015-01-18 22:09:15 +03:00
Oleg Efimov
24182d859f protobuf-c.c: Better input checks in protobuf_c_message_free_unpacked
Check for NULL message pointer passed to protobuf_c_message_free_unpacked

Closes #177
2015-01-18 22:09:15 +03:00
Oleg Efimov
f49fabead4 t: fix compile warnings about pointers of different types assignments
warning: assigning to 'uint8_t *' (aka 'unsigned char *')
from 'char *' converts between pointers to integer types
with different sign [-Wpointer-sign]
2015-01-06 22:48:00 +03:00
Ilya Lipnitskiy
6090d9a924 t: Add tests for oneoffs
Add test cases for parsing multiple fields of the same oneof from the wire
Add more tests for submessage merging, including oneofs
2014-11-19 23:07:23 -08:00
Robert Edmonds
c4a0e69337 t/test-full.proto: add 'allow_alias' option to TestEnumDupValues
protobuf 2.5.0 started warning that we would need to enable the
'allow_alias' option on this enum due to the duplicate enum values, and
protobuf 2.6.0 turned this into an error. Turn this option on, now that
protobuf 2.5.0 is more common (e.g., it's now in Ubuntu 14.04 LTS). This
will break with older protobuf versions, so we now require >= 2.5.0.

We should now see diagnostics like these disappear from the build log:

    [libprotobuf ERROR google/protobuf/descriptor.cc:4153] "foo.VALUE_B" uses the same enum value as "foo.VALUE_A". If this is intended, set 'option allow_alias = true;' to the enum definition.

Based on a patch from Ilya Lipnitskiy.
2014-09-05 15:38:26 -04:00
Andrei Nigmatulin
6136f54b22 added check for PROTOBUF_C_TYPE_BYTES fields, including repeated
added check that repeated fields vectors are not NULL
fixed repeated field quantity type: it's "size_t", not "unsigned"
cleaner code, no cast porn
all covered with tests
2014-06-30 19:28:04 +01:00
Ilya Lipnitskiy
a2100d1f39 protobuf-c.c: Fix repeated field concatenation order in merge_messages (fixes #147) 2014-06-27 17:32:32 -04:00
Robert Edmonds
626b138fa6 t/: add new test program 'version' 2014-04-03 17:09:39 -04:00
Robert Edmonds
3fccff9381 t/: add test case test_field_flags 2014-04-03 12:09:54 -04:00
Robert Edmonds
ec961cb007 t/: rename the required fields bitmap test case 2014-03-31 16:14:33 -04:00
Andrei Nigmatulin
cfb919f100 added unit test for required_fields_bitmap hashing issue 2014-03-31 16:10:41 -04:00
Oleg Efimov
9c7f8ce798 t/: add test case for Issue #129 from Oleg Efimov 2014-03-24 18:07:04 -04:00
Robert Edmonds
8cd5f6764b protobuf-c: remove tmp_alloc and max_alloca fields of ProtobufCAllocator
i'm confused as to why these fields exist, since the typical
implementation of a "temporary alloc" would be something like alloca(),
and alloca() is usually just inlined code that adjusts the stack
pointer, which is not a function whose address could be taken.

this breaks the API/ABI and will require a note in the ChangeLog.

possibly we could revisit the idea of "temporary allocations" by using
C99 variable length arrays. this would have the advantage of being
standardized, unlike alloca().
2014-01-13 15:35:42 -05:00