Commit Graph

10 Commits

Author SHA1 Message Date
João Valverde 79c3a77752 Add macros to control lemon diagnostics
Rename flex macros using parenthesis (mostly a style issue):

DIAG_OFF_FLEX -> DIAG_OFF_FLEX()
DIAG_ON_FLEX  -> DIAG_ON_FLEX()

Use the same kind of construct with lemon generated code using
DIAG_OFF_LEMON() and DIAG_ON_LEMON(). Use %include and %code
directives to enforce the desired order with generated code
in the middle in between pragmas.

Fix a clang-specific pragma to use DIAG_OFF_CLANG().

DIAG_OFF(unreachable-code) -> DIAG_OFF_CLANG(unreachable-code).

Apparently GCC is ignoring the -Wunreachable flag, that's why
it did not trigger an unknown pragma warning. From [1}:

  The -Wunreachable-code has been removed, because it was unstable: it
  relied on the optimizer, and so different versions of gcc would warn
  about different code.  The compiler still accepts and ignores the
  command line option so that existing Makefiles are not broken.  In some
  future release the option will be removed entirely. - Ian

[1] https://gcc.gnu.org/legacy-ml/gcc-help/2011-05/msg00360.html
2022-11-20 10:11:27 +00:00
João Valverde 09718fb9b3 CMake: Move clang warnings
Move clang warnings to normal set. Let the CMake compatibility
check control the warning.

Fix or work-around -Wunreachable warnings in the code.
2022-11-17 01:35:16 +00:00
João Valverde c5a19582e4 epan: Convert to use stdio.h from GLib
Replace:
    g_snprintf() -> snprintf()
    g_vsnprintf() -> vsnprintf()
    g_strdup_printf() -> ws_strdup_printf()
    g_strdup_vprintf() -> ws_strdup_vprintf()

This is more portable, user-friendly and faster on platforms
where GLib does not like the native I/O.

Adjust the format string to use macros from intypes.h.
2021-12-19 19:29:53 +00:00
Gerald Combs c92637bcd8 Add missing prototypes to lemon-generated code.
Add static prototypes for the parser interface functions. Fixes
-Wmissing-prototypes found by clang.
2021-04-16 18:38:26 +00:00
Tomasz Moń 4c16875759 protobuf: Fix leaking nodes and strings
Closes #17305
2021-04-02 07:25:31 +00:00
Tomasz Moń 5bbfee2ed8 protobuf: fix leaking tokens
Move scanner destroy call to pbl_clear_state() so it is freed if
parsing fails.

This eliminates most of leaked memory reported in #17305.
2021-03-27 17:23:07 +00:00
Tomasz Moń 525006f97b protobuf: free memory used by scanner after parsing
Closes #17305
2021-03-26 15:47:28 +01:00
Huang Qiangxiong cd2d35c1d2 Protobuf: fix bugs that parsing complex syntax .proto files
Some .proto files contain complex syntax that does not be described in protobuf official site
(https://developers.google.com/protocol-buffers/docs/reference/proto3-spec).

1. Update 'epan/protobuf_lang_parser.lemon' to:
1) Support complex option names format (EBNF):
    optionName = ( ident | "(" fullIdent ")" ) { "." ( ident | "(" fullIdent ")" ) }
for example, "option (complex_opt2).(grault) = 654;".
2) Make enum body support 'reserved' section (EBNF):
    enumBody = "{" { reserved | option | enumField | emptyStatement } "}"
3) Allow the value of field or enumValue option to be "{ ... }" other than constant:
    enumValueOption = optionName  "=" ( constant | customOptionValue ) ";"
    fieldOption = optionName  "=" ( constant | customOptionValue ) ";"
4) Allow 'group' section missing 'label' (for example, in 'oneof' section).
5) Make 'oneof' section support 'option' and 'group' sections (BNF):
    oneof = "oneof" oneofName "{" { oneofField | option | group | emptyStatement } "}"
6) Ignore unused 'extend' section.
7) Fix the bug of one string being splitted into multi-lines.

2. Update 'epan/protobuf_lang_tree.c' to:
8) Fix the bug of parsing repeated option.

3. Update 'test/suite_dissection.py' to add test case for parsing complex syntax .proto files:
  test/protobuf_lang_files/complex_proto_files/unittest_custom_options.proto
  test/protobuf_lang_files/complex_proto_files/complex_syntax.proto
and dependency files:
  test/protobuf_lang_files/well_know_types/google/protobuf/any.proto
  test/protobuf_lang_files/well_know_types/google/protobuf/descriptor.proto

Refer to issue #17046
2020-12-27 11:32:10 +00:00
Guy Harris bb494c11de Fix various spelling errors.
Found by lintian and by looking for the misspelled words that lintian
found.

(Does not fix spelling errors in .asn1 files.)
2020-12-09 05:52:50 +00:00
Huang Qiangxiong 7906a2f6a8 Protobuf: rewrite parser of *.proto file from Bison to Lemon
In order to avoid Bison's compatibility problem (like
https://code.wireshark.org/review/#/c/33771/),
the *.proto file parser is rewritten with lemon. (rename
protobuf_lang.y.in to protobuf_lang_parser.lemon)
Also improved the mechanism of recording line number of
message, field, and enum names.
2020-11-18 08:57:01 +00:00