diff options
author | Maksim Salau <maksim.salau@gmail.com> | 2019-07-11 12:03:58 +0300 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2019-07-11 17:44:50 +0000 |
commit | bd4e293b7b6f08efe13e24f766d078954e5c66c9 (patch) | |
tree | 75bd347dc7dac5fed034d83a8fe0dee0c131b06e /wiretap/candump_scanner.l | |
parent | c9a29e38c7a63498ab97c7305b4f45066a933370 (diff) |
wiretap: candump: Reset error info and fix scanner warnings
candump_open() may be called with non-empty error code and string.
The error code is not reset upon success in run_candump_parser() which may
mislead the caller function thus affecting opening the file.
yy_fatal_error(), yy_alloc(), yy_realloc() and yy_free() make no use
of the yyscanner argument, which results in warnings on OSX.
In order to get rid of those warning we provide our own
implementations of memory allocation functions and hack
YY_EXIT_FAILURE macro in order to pretend using the argument.
Change-Id: I672d374b26970b2699b9d789b6118e97ba660bdf
Reviewed-on: https://code.wireshark.org/review/33892
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'wiretap/candump_scanner.l')
-rw-r--r-- | wiretap/candump_scanner.l | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/wiretap/candump_scanner.l b/wiretap/candump_scanner.l index 59b2188e29..98b98ee791 100644 --- a/wiretap/candump_scanner.l +++ b/wiretap/candump_scanner.l @@ -24,6 +24,19 @@ %option noyy_scan_bytes %option noyy_scan_string +/* + * We have to override the memory allocators so that we don't get + * "unused argument" warnings from the yyscanner argument (which + * we don't use, as we have a global memory allocator). + * + * We provide, as macros, our own versions of the routines generated by Flex, + * which just call malloc()/realloc()/free() (as the Flex versions do), + * discarding the extra argument. + */ +%option noyyalloc +%option noyyrealloc +%option noyyfree + %{ #include <ws_diag_control.h> @@ -52,6 +65,18 @@ static int candump_yyinput(void *buf, unsigned int max_size, #define YY_INPUT(buf, result, max_size) \ do { (result) = candump_yyinput((buf), (max_size), yyextra); } while (0) +/* + * Sleazy hack to suppress compiler warnings in yy_fatal_error(). + */ +#define YY_EXIT_FAILURE ((void)yyscanner, 2) + +/* + * Macros for the allocators, to discard the extra argument. + */ +#define candump_alloc(size, yyscanner) (void *)malloc(size) +#define candump_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size)) +#define candump_free(ptr, yyscanner) free((char *)(ptr)) + DIAG_OFF_FLEX %} |