Use DIAG_OFF_FLEX/DIAG_ON_FLEX more consistently.

Add warning C4267 (size_t to int conversion) with MSVC to DIAG_OFF_FLEX.

Addd -Wshorten-64-to-32 with Clang and GCC to DIAG_OFF_FLEX.

Don't explicitly use #pragma to turn off warnings; use DIAG_OFF_FLEX for
all of them.

If we use DIAG_OFF_FLEX, use DIAG_ON_FLEX, even if we have no section of
entirely included code at the end.

Change-Id: Ibfd44e8954704e9a8bcb1bd8e54f31d28357fffb
Reviewed-on: https://code.wireshark.org/review/25817
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2018-02-16 03:15:32 -08:00
parent 09671923ad
commit 72b57ac4ef
9 changed files with 96 additions and 48 deletions

View File

@ -1,12 +1,6 @@
%top {
/* Include this before everything else, for various large-file definitions */
#include "config.h"
// warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4267)
#endif
}
/*
@ -106,7 +100,10 @@
#include <epan/to_str.h>
#include <wsutil/file_util.h>
DIAG_OFF(sign-compare)
/*
* Disable diagnostics in the code generated by Flex.
*/
DIAG_OFF_FLEX
typedef struct entity_t {
char* name;
@ -626,14 +623,12 @@ description_attr description=\042
<OUTSIDE>. ;
%%
DIAG_ON(sign-compare)
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX
static int debugging = 0;

View File

@ -1,12 +1,6 @@
%top {
/* Include this before everything else, for various large-file definitions */
#include "config.h"
// warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4267)
#endif
}
/*
@ -94,7 +88,10 @@
#include "dtd_grammar.h"
#include "dtd_parse.h"
DIAG_OFF(sign-compare)
/*
* Disable diagnostics in the code generated by Flex.
*/
DIAG_OFF_FLEX
struct _proto_xmlpi_attr {
const gchar* name;
@ -352,7 +349,10 @@ squoted ['][^\']*[']
%%
DIAG_ON(sign-compare)
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX
static dtd_token_data_t* new_token(gchar* text, gchar* location) {
dtd_token_data_t* t = g_new(dtd_token_data_t,1);

View File

@ -1,12 +1,6 @@
%top {
/* Include this before everything else, for various large-file definitions */
#include "config.h"
// warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4267)
#endif
}
/*

View File

@ -1,12 +1,6 @@
%top {
/* Include this before everything else, for various large-file definitions */
#include "config.h"
// warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4267)
#endif
}
/*
@ -106,7 +100,10 @@
#include "wimaxasncp_dict.h"
DIAG_OFF(sign-compare)
/*
* Disable diagnostics in the code generated by Flex.
*/
DIAG_OFF_FLEX
typedef struct entity_t {
gchar *name;
@ -514,14 +511,12 @@ since_attr since=\042
<OUTSIDE>. ;
%%
DIAG_ON(sign-compare)
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX
static int debugging = 0;

View File

@ -106,3 +106,10 @@ eol \r?\n\r?
if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
{comment} { if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
{text} { if (parse_token(T_TEXT, yytext) != EXIT_SUCCESS) return EXIT_FAILURE; }
%%
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX

View File

@ -135,3 +135,10 @@ eol \r?\n\r?
{text} { parse_token(T_TEXT, yytext); }
<<EOF>> { write_current_packet(); yyterminate(); }
%%
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX

View File

@ -65,7 +65,10 @@
#include "ascend.h"
#include "file_wrappers.h"
DIAG_OFF(sign-compare)
/*
* Disable diagnostics in the code generated by Flex.
*/
DIAG_OFF_FLEX
#define YY_INPUT(buf,result,max_size) { \
ascend_state_t *parser_state = ascendget_extra(yyscanner); \
@ -372,3 +375,10 @@ task:|task|at|time:|octets { return KEYWORD; }
<<EOF>> { yyterminate(); }
(.|\n) ;
%%
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX

View File

@ -101,7 +101,10 @@
#define YY_NO_UNISTD_H
#endif
DIAG_OFF(sign-compare)
/*
* Disable diagnostics in the code generated by Flex.
*/
DIAG_OFF_FLEX
/*
* State kept by the scanner.
@ -233,7 +236,10 @@ hdlc HDLC
%%
DIAG_ON(sign-compare)
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX
/* Fill in pkthdr */

View File

@ -100,15 +100,49 @@ extern "C" {
* generated by that version of Flex triggers?
*/
#if defined(_MSC_VER)
/*
* Suppress:
*
* warning C4018: signed/unsigned mismatch
* warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
*/
#define DIAG_OFF_FLEX \
__pragma(warning(push)) \
__pragma(warning(disable:4018))
__pragma(warning(disable:4018)) \
__pragma(warning(disable:4267))
#define DIAG_ON_FLEX __pragma(warning(pop))
#else
#define DIAG_OFF_FLEX \
DIAG_OFF(sign-compare)
#define DIAG_ON_FLEX \
DIAG_ON(sign-compare)
/*
* Suppress:
*
* -Wsigned-compare warnings
* -Wshorten-64-to-32 warnings, if the compiler *has* -Wshorten-64-to-32
*
* We use DIAG_OFF() and DIAG_ON(), so we only use features that the
* compiler supports.
*
* We disable -Wshorten-64-to-32 if we're using Clang, or if __APPLE__
* is defined; that option was originally added to an Apple version of
* GCC, and at least some versions of Clang support it - given that
* the Clang work started at Apple, it may be in all versions of Clang.
*
* (Does no version of GCC or Clang support the same generic "you're
* narrowing a value, and you didn't throw in a cast to assert that
* you know what you're doing" warning that MSVC does?)
*/
#if defined(__clang__) || defined(__APPLE__)
#define DIAG_OFF_FLEX \
DIAG_OFF(sign-compare) \
DIAG_OFF(shorten-64-to-32)
#define DIAG_ON_FLEX \
DIAG_ON(shorten-64-to-32) \
DIAG_ON(sign-compare)
#else
#define DIAG_OFF_FLEX \
DIAG_OFF(sign-compare)
#define DIAG_ON_FLEX \
DIAG_ON(sign-compare)
#endif
#endif
/*