diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-02-15 23:17:04 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-02-16 10:35:10 +0000 |
commit | 8bc1c6e3e8c0a84ee656d1e1d68530fc9bf2e35d (patch) | |
tree | 92c288690894a1f68257711ee594a7da985a7aa9 | |
parent | b6bec7d1fdf537f12968276344e6191394249b8b (diff) |
Add DIAG_OFF_FLEX and DIAG_ON_FLEX for use in Flex scanners.
DIAG_OFF_FLEX turns off all warnings that we want to disable for
Flex-generated code due to some versions of Flex generating code that
triggers those warnings.
DIAG_ON_FLEX restores those warnings, so we do the checks for code that
*we* wrote.
Use them in .l files.
Change-Id: I613a20309a30cd4c61111a1edbe27a5d05fcbf59
Reviewed-on: https://code.wireshark.org/review/25815
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | epan/dfilter/scanner.l | 16 | ||||
-rw-r--r-- | epan/dtd_preparse.l | 16 | ||||
-rw-r--r-- | epan/radius_dict.l | 16 | ||||
-rw-r--r-- | epan/uat_load.l | 16 | ||||
-rw-r--r-- | plugins/epan/mate/mate_parser.l | 16 | ||||
-rw-r--r-- | text2pcap-scanner.l | 11 | ||||
-rw-r--r-- | ui/text_import_scanner.l | 9 | ||||
-rw-r--r-- | ws_diag_control.h | 30 |
8 files changed, 77 insertions, 53 deletions
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l index 5f1d29df4a..63850cd178 100644 --- a/epan/dfilter/scanner.l +++ b/epan/dfilter/scanner.l @@ -81,13 +81,10 @@ #include "grammar.h" #include "dfunctions.h" -DIAG_OFF(sign-compare) - -#ifdef _WIN32 -/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ -/* with YY_INPUT code generated by flex versions such as 2.5.35. */ -#pragma warning (disable:4018) -#endif +/* + * Disable diagnostics in the code generated by Flex. + */ +DIAG_OFF_FLEX #define LVAL df_lval #define LVAL_TYPE stnode_t* @@ -385,7 +382,10 @@ static void mark_lval_deprecated(const char *s); %% -DIAG_ON(sign-compare) +/* + * Turn diagnostics back on, so we check the code that we've written. + */ +DIAG_ON_FLEX static int simple(int token) diff --git a/epan/dtd_preparse.l b/epan/dtd_preparse.l index f18e44a870..669d147296 100644 --- a/epan/dtd_preparse.l +++ b/epan/dtd_preparse.l @@ -97,7 +97,10 @@ #include "dtd.h" #include <wsutil/file_util.h> -DIAG_OFF(sign-compare) +/* + * Disable diagnostics in the code generated by Flex. + */ +DIAG_OFF_FLEX #define ECHO g_string_append(yyextra->current,yytext); @@ -127,12 +130,6 @@ static const gchar* replace_entity(Dtd_PreParse_scanner_state_t* state, gchar* s #define YY_NO_UNISTD_H #endif -#ifdef _WIN32 -/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ -/* with YY_INPUT code generated by flex versions such as 2.5.35. */ -#pragma warning (disable:4018) -#endif - /* * Sleazy hack to suppress compiler warnings in yy_fatal_error(). */ @@ -212,7 +209,10 @@ newline \n %% -DIAG_ON(sign-compare) +/* + * Turn diagnostics back on, so we check the code that we've written. + */ +DIAG_ON_FLEX static const gchar* replace_entity(Dtd_PreParse_scanner_state_t* state, gchar* entity) { GString* replacement; diff --git a/epan/radius_dict.l b/epan/radius_dict.l index 043c91e9ad..05bfb92585 100644 --- a/epan/radius_dict.l +++ b/epan/radius_dict.l @@ -92,7 +92,10 @@ #include <epan/dissectors/packet-radius.h> #include <wsutil/file_util.h> -DIAG_OFF(sign-compare) +/* + * Disable diagnostics in the code generated by Flex. + */ +DIAG_OFF_FLEX /* * See @@ -120,12 +123,6 @@ DIAG_OFF(sign-compare) */ #define YY_USER_INIT BEGIN WS_OUT; -#ifdef _WIN32 -/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ -/* with YY_INPUT code generated by flex versions such as 2.5.35. */ -#pragma warning (disable:4018) -#endif - #define ECHO #define MAX_INCLUDE_DEPTH 10 @@ -412,7 +409,10 @@ static void add_value(Radius_scanner_state_t* state, const gchar* attrib_name, c %% -DIAG_ON(sign-compare) +/* + * Turn diagnostics back on, so we check the code that we've written. + */ +DIAG_ON_FLEX static void add_vendor(Radius_scanner_state_t* state, const gchar* name, guint32 id, guint type_octets, guint length_octets, gboolean has_flags) { radius_vendor_info_t* v; diff --git a/epan/uat_load.l b/epan/uat_load.l index 86d5101e16..d645d0b4dc 100644 --- a/epan/uat_load.l +++ b/epan/uat_load.l @@ -96,13 +96,10 @@ #include "uat-int.h" #include <wsutil/file_util.h> -DIAG_OFF(sign-compare) - -#ifdef _WIN32 -/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ -/* with YY_INPUT code generated by flex versions such as 2.5.35. */ -#pragma warning (disable:4018) -#endif +/* + * Disable diagnostics in the code generated by Flex. + */ +DIAG_OFF_FLEX typedef struct { uat_t* uat; @@ -360,7 +357,10 @@ comment #[^\n]*\n %% -DIAG_ON(sign-compare) +/* + * Turn diagnostics back on, so we check the code that we've written. + */ +DIAG_ON_FLEX gboolean uat_load(uat_t *uat, char **errx) diff --git a/plugins/epan/mate/mate_parser.l b/plugins/epan/mate/mate_parser.l index b2ff7117cc..339b0cc4a2 100644 --- a/plugins/epan/mate/mate_parser.l +++ b/plugins/epan/mate/mate_parser.l @@ -84,13 +84,10 @@ #include <wsutil/file_util.h> -DIAG_OFF(sign-compare) - -#ifdef _WIN32 -/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ -/* with YY_INPUT code generated by flex versions such as 2.5.35. */ -#pragma warning (disable:4018) -#endif +/* + * Disable diagnostics in the code generated by Flex. + */ +DIAG_OFF_FLEX void MateParseTrace(FILE*,char*); @@ -337,7 +334,10 @@ blk_cmnt_stop "*/" %% -DIAG_ON(sign-compare) +/* + * Turn diagnostics back on, so we check the code that we've written. + */ +DIAG_ON_FLEX extern gboolean mate_load_config(const gchar* filename, mate_config* mc) { FILE *in; diff --git a/text2pcap-scanner.l b/text2pcap-scanner.l index 2b9e6dbab8..b4024b162d 100644 --- a/text2pcap-scanner.l +++ b/text2pcap-scanner.l @@ -66,7 +66,10 @@ #include "text2pcap.h" -DIAG_OFF(sign-compare) +/* + * Disable diagnostics in the code generated by Flex. + */ +DIAG_OFF_FLEX /* * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h @@ -75,12 +78,6 @@ DIAG_OFF(sign-compare) #define YY_NO_UNISTD_H #endif -#ifdef _WIN32 -/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ -/* with YY_INPUT code generated by flex versions such as 2.5.35. */ -#pragma warning (disable:4018) -#endif - %} hexdigit [0-9A-Fa-f] diff --git a/ui/text_import_scanner.l b/ui/text_import_scanner.l index 04809fc459..5e7d65048e 100644 --- a/ui/text_import_scanner.l +++ b/ui/text_import_scanner.l @@ -84,17 +84,16 @@ #include "text_import_scanner.h" -DIAG_OFF(sign-compare) +/* + * Disable diagnostics in the code generated by Flex. + */ +DIAG_OFF_FLEX /* * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h */ #ifdef _WIN32 # define YY_NO_UNISTD_H - - /* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ - /* with YY_INPUT code generated by flex versions such as 2.5.35. */ -# pragma warning (disable:4018) #endif /* diff --git a/ws_diag_control.h b/ws_diag_control.h index 459a18a9af..155c143077 100644 --- a/ws_diag_control.h +++ b/ws_diag_control.h @@ -22,9 +22,16 @@ extern "C" { #define XSTRINGIFY(x) #x /* - * Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8 + * Macros for controlling warnings in various compilers. */ #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y) + +/* + * XXX - this is only for GCC or GCC-compatible compilers, and we only use + * it to have a macro that takes a warning as an argument and turns it + * off in the appropriate fashion for Clang and GCC; it should only be + * used internally in this header. + */ #define DIAG_DO_PRAGMA(x) _Pragma (#x) #if defined(__clang__) @@ -84,6 +91,27 @@ extern "C" { #endif /* + * Suppress complaints about conversion of size_t to int and about + * signed vs. unsigned comparison. + * + * XXX - this is done solely to squelch complaints from code generated + * by Flex, but newer versions of Flex might fix the code; can we + * check the version of Flex and suppress only the checks that code + * generated by that version of Flex triggers? + */ +#if defined(_MSC_VER) + #define DIAG_OFF_FLEX \ + __pragma(warning(push)) \ + __pragma(warning(disable:4018)) + #define DIAG_ON_FLEX __pragma(warning(pop)) +#else + #define DIAG_OFF_FLEX \ + DIAG_OFF(sign-compare) + #define DIAG_ON_FLEX \ + DIAG_ON(sign-compare) +#endif + +/* * For dealing with APIs which are only deprecated in macOS (like the * OpenSSL and MIT/Heimdal Kerberos APIs). * |