2014-08-27 21:16:33 +00:00
|
|
|
/* ws_diag_control.h
|
|
|
|
* Turn compiler diagnostic messages on and off.
|
|
|
|
*
|
|
|
|
* From FreeRADIUS build.h.
|
|
|
|
*
|
|
|
|
* @copyright 2013 The FreeRADIUS server project
|
|
|
|
*
|
|
|
|
* That project is covered by the GPLv2, so:
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2014-08-27 21:16:33 +00:00
|
|
|
*/
|
2017-11-08 15:43:53 +00:00
|
|
|
|
2014-08-27 21:16:33 +00:00
|
|
|
#ifndef __WS_DIAG_CONTROL_H__
|
|
|
|
#define __WS_DIAG_CONTROL_H__
|
|
|
|
|
2017-10-26 21:59:40 +00:00
|
|
|
#include "ws_compiler_tests.h"
|
|
|
|
|
2014-08-27 21:16:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define XSTRINGIFY(x) #x
|
|
|
|
|
|
|
|
/*
|
2018-02-16 07:17:04 +00:00
|
|
|
* Macros for controlling warnings in various compilers.
|
2014-08-27 21:16:33 +00:00
|
|
|
*/
|
|
|
|
#define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
|
2018-02-16 07:17:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-08-27 21:16:33 +00:00
|
|
|
#define DIAG_DO_PRAGMA(x) _Pragma (#x)
|
|
|
|
|
2017-10-27 02:00:20 +00:00
|
|
|
#if defined(__clang__)
|
2017-10-26 21:59:40 +00:00
|
|
|
/*
|
2017-10-27 02:00:20 +00:00
|
|
|
* Clang, so we'd use _Pragma("clang diagnostic XXX"), if it's
|
|
|
|
* supported.
|
2017-10-26 21:59:40 +00:00
|
|
|
*/
|
2018-09-09 21:58:10 +00:00
|
|
|
#if WS_IS_AT_LEAST_CLANG_VERSION(2,8)
|
2017-10-27 02:00:20 +00:00
|
|
|
/*
|
|
|
|
* This is Clang 2.8 or later: we can use "clang diagnostic ignored -Wxxx"
|
|
|
|
* and "clang diagnostic push/pop".
|
|
|
|
*/
|
|
|
|
#define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
|
|
|
|
#define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
|
2022-10-04 15:22:24 +00:00
|
|
|
#define DIAG_WARN(x) DIAG_PRAGMA(push) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x))
|
2017-10-27 02:00:20 +00:00
|
|
|
#define DIAG_ON(x) DIAG_PRAGMA(pop)
|
2018-09-09 21:58:10 +00:00
|
|
|
#endif
|
2018-05-18 21:41:26 +00:00
|
|
|
|
|
|
|
/*
|
2018-09-11 18:53:56 +00:00
|
|
|
* Not all versions of Clang understand -Wpedantic. Clang 4.0 appears
|
|
|
|
* to be the first version to do so.
|
2018-05-18 21:41:26 +00:00
|
|
|
*/
|
|
|
|
#if WS_IS_AT_LEAST_CLANG_VERSION(4,0)
|
|
|
|
#define DIAG_OFF_PEDANTIC DIAG_OFF(pedantic)
|
|
|
|
#define DIAG_ON_PEDANTIC DIAG_ON(pedantic)
|
|
|
|
#else
|
|
|
|
#define DIAG_OFF_PEDANTIC
|
|
|
|
#define DIAG_ON_PEDANTIC
|
|
|
|
#endif
|
2021-03-27 20:18:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do any pre-5.0 versions of Clang understand -Winitializer-overrides?
|
|
|
|
*/
|
|
|
|
#if WS_IS_AT_LEAST_CLANG_VERSION(4,0)
|
|
|
|
#define DIAG_OFF_INIT_TWICE DIAG_OFF(initializer-overrides)
|
|
|
|
#define DIAG_ON_INIT_TWICE DIAG_ON(initializer-overrides)
|
|
|
|
#else
|
|
|
|
#define DIAG_OFF_INIT_TWICE
|
|
|
|
#define DIAG_ON_INIT_TWICE
|
|
|
|
#endif
|
2017-10-27 02:00:20 +00:00
|
|
|
#elif defined(__GNUC__)
|
2017-10-26 21:59:40 +00:00
|
|
|
/*
|
2017-10-27 02:00:20 +00:00
|
|
|
* GCC, or a compiler (other than Clang) that claims to be GCC.
|
|
|
|
* We assume that the compiler accepts _Pragma("GCC diagnostic xxx")
|
|
|
|
* even if it's only claiming to be GCC.
|
2017-10-26 21:59:40 +00:00
|
|
|
*/
|
2018-09-11 18:53:56 +00:00
|
|
|
#if WS_IS_AT_LEAST_GNUC_VERSION(4,8)
|
2017-10-27 02:00:20 +00:00
|
|
|
/*
|
2018-09-11 18:53:56 +00:00
|
|
|
* This is GCC 4.8 or later, or a compiler claiming to be that.
|
|
|
|
* We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
|
|
|
|
* and "GCC diagnostic push/pop" (introduced in 4.6), *and* gcc
|
|
|
|
* supports "-Wpedantic" (introduced in 4.8), allowing us to
|
|
|
|
* turn off pedantic warnings with DIAG_OFF().
|
2017-10-27 02:00:20 +00:00
|
|
|
*/
|
|
|
|
#define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
|
2018-09-11 18:53:56 +00:00
|
|
|
#define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
|
2022-10-04 15:22:24 +00:00
|
|
|
#define DIAG_WARN(x) DIAG_PRAGMA(push) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x))
|
2018-09-11 18:53:56 +00:00
|
|
|
#define DIAG_ON(x) DIAG_PRAGMA(pop)
|
2018-05-18 21:41:26 +00:00
|
|
|
|
|
|
|
/*
|
2018-09-11 18:53:56 +00:00
|
|
|
* We assume GCC 4.8 and later understand -Wpedantic.
|
2018-05-18 21:41:26 +00:00
|
|
|
*/
|
2018-09-11 18:53:56 +00:00
|
|
|
#define DIAG_OFF_PEDANTIC DIAG_OFF(pedantic)
|
|
|
|
#define DIAG_ON_PEDANTIC DIAG_ON(pedantic)
|
2021-03-27 20:18:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GCC 4.2 and later understand -Woverride-init.
|
|
|
|
*/
|
|
|
|
#define DIAG_OFF_INIT_TWICE DIAG_OFF(override-init)
|
|
|
|
#define DIAG_ON_INIT_TWICE DIAG_ON(override-init)
|
2018-09-11 18:53:56 +00:00
|
|
|
#else
|
2018-05-18 21:41:26 +00:00
|
|
|
#define DIAG_OFF_PEDANTIC
|
|
|
|
#define DIAG_ON_PEDANTIC
|
2021-03-27 20:18:34 +00:00
|
|
|
|
|
|
|
#define DIAG_OFF_INIT_TWICE
|
|
|
|
#define DIAG_ON_INIT_TWICE
|
2017-10-27 02:00:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DIAG_OFF
|
2017-10-26 21:59:40 +00:00
|
|
|
/*
|
|
|
|
* This is none of the above; we don't have any way to turn diagnostics
|
|
|
|
* on or off.
|
|
|
|
*
|
|
|
|
* XXX - you can do that in MSVC, but it's done differently; we'd
|
|
|
|
* have to have macros for *particular* diagnostics, using the
|
|
|
|
* warning flag for GCC and Clang and the error number for MSVC.
|
|
|
|
*/
|
|
|
|
#define DIAG_OFF(x)
|
2022-10-04 15:22:24 +00:00
|
|
|
#define DIAG_WARN(x)
|
2017-10-26 21:59:40 +00:00
|
|
|
#define DIAG_ON(x)
|
2018-05-18 21:41:26 +00:00
|
|
|
#define DIAG_OFF_PEDANTIC
|
|
|
|
#define DIAG_ON_PEDANTIC
|
2021-03-27 20:18:34 +00:00
|
|
|
#define DIAG_OFF_INIT_TWICE
|
|
|
|
#define DIAG_ON_INIT_TWICE
|
2015-02-14 21:36:45 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-22 02:24:56 +00:00
|
|
|
/* Use for clang specific pragmas, so we can keep -Wpragmas enabled */
|
|
|
|
#ifdef __clang__
|
|
|
|
# define DIAG_OFF_CLANG(x) DIAG_OFF(x)
|
2022-10-04 15:22:24 +00:00
|
|
|
# define DIAG_WARN_CLANG(x) DIAG_WARN(x)
|
2016-05-22 02:24:56 +00:00
|
|
|
# define DIAG_ON_CLANG(x) DIAG_ON(x)
|
|
|
|
#else
|
|
|
|
# define DIAG_OFF_CLANG(x)
|
|
|
|
# define DIAG_ON_CLANG(x)
|
|
|
|
#endif
|
|
|
|
|
2018-02-16 07:17:04 +00:00
|
|
|
/*
|
2018-02-17 19:36:52 +00:00
|
|
|
* Suppress complaints about narrowing converstions and about signed vs.
|
|
|
|
* unsigned comparison.
|
2018-02-16 07:17:04 +00:00
|
|
|
*
|
|
|
|
* 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)
|
2018-02-16 11:15:32 +00:00
|
|
|
/*
|
|
|
|
* Suppress:
|
|
|
|
*
|
|
|
|
* warning C4018: signed/unsigned mismatch
|
2018-02-17 19:36:52 +00:00
|
|
|
* warning C4244: 'initializing' : conversion from '__int64' to 'int', possible loss of data
|
2018-02-16 11:15:32 +00:00
|
|
|
* warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
|
2018-02-28 04:12:53 +00:00
|
|
|
*
|
|
|
|
* as well as Visual Studio Code Analyzer warnings:
|
|
|
|
*
|
|
|
|
* warning C6011: Dereferencing NULL pointer
|
|
|
|
* warning C6308: 'realloc' might return null pointer
|
|
|
|
* warning C6386: Buffer overrun
|
|
|
|
* warning C6387: 'XXX' could be '0'
|
|
|
|
* warning C28182: Dereferencing NULL pointer
|
2018-02-16 11:15:32 +00:00
|
|
|
*/
|
2022-11-19 22:52:09 +00:00
|
|
|
#define DIAG_OFF_FLEX() \
|
2018-02-16 07:17:04 +00:00
|
|
|
__pragma(warning(push)) \
|
2018-02-16 11:15:32 +00:00
|
|
|
__pragma(warning(disable:4018)) \
|
2018-02-17 19:36:52 +00:00
|
|
|
__pragma(warning(disable:4244)) \
|
2018-02-28 04:12:53 +00:00
|
|
|
__pragma(warning(disable:4267)) \
|
|
|
|
__pragma(warning(disable:6011)) \
|
|
|
|
__pragma(warning(disable:6308)) \
|
|
|
|
__pragma(warning(disable:6386)) \
|
|
|
|
__pragma(warning(disable:6387)) \
|
|
|
|
__pragma(warning(disable:28182))
|
2022-11-19 22:52:09 +00:00
|
|
|
#define DIAG_ON_FLEX() \
|
|
|
|
__pragma(warning(pop))
|
2018-02-16 07:17:04 +00:00
|
|
|
#else
|
2018-02-16 11:15:32 +00:00
|
|
|
/*
|
|
|
|
* Suppress:
|
|
|
|
*
|
|
|
|
* -Wsigned-compare warnings
|
|
|
|
* -Wshorten-64-to-32 warnings, if the compiler *has* -Wshorten-64-to-32
|
2018-02-22 07:03:12 +00:00
|
|
|
* -Wunreachable-code warnings
|
2022-11-17 17:36:32 +00:00
|
|
|
* The version of Flex in the macOS Intel build bots triggers documentation warnings.
|
|
|
|
* -Wdocumentation
|
2018-02-16 11:15:32 +00:00
|
|
|
*
|
|
|
|
* 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__)
|
2022-11-19 22:52:09 +00:00
|
|
|
#define DIAG_OFF_FLEX() \
|
2018-02-16 11:15:32 +00:00
|
|
|
DIAG_OFF(sign-compare) \
|
2023-01-03 12:41:29 +00:00
|
|
|
DIAG_OFF(unused-parameter) \
|
2018-02-22 07:03:12 +00:00
|
|
|
DIAG_OFF(shorten-64-to-32) \
|
2022-11-17 17:36:32 +00:00
|
|
|
DIAG_OFF(unreachable-code) \
|
|
|
|
DIAG_OFF(documentation)
|
2022-11-19 22:52:09 +00:00
|
|
|
#define DIAG_ON_FLEX() \
|
2022-11-17 17:36:32 +00:00
|
|
|
DIAG_ON(documentation) \
|
2018-09-09 23:33:15 +00:00
|
|
|
DIAG_ON(unreachable-code) \
|
2018-02-16 11:15:32 +00:00
|
|
|
DIAG_ON(shorten-64-to-32) \
|
2023-01-03 12:41:29 +00:00
|
|
|
DIAG_ON(unused-parameter) \
|
2018-02-16 11:15:32 +00:00
|
|
|
DIAG_ON(sign-compare)
|
|
|
|
#else
|
2022-11-19 22:52:09 +00:00
|
|
|
#define DIAG_OFF_FLEX() \
|
2023-01-03 12:41:29 +00:00
|
|
|
DIAG_OFF(sign-compare) \
|
|
|
|
DIAG_OFF(unused-parameter)
|
2022-11-19 22:52:09 +00:00
|
|
|
#define DIAG_ON_FLEX() \
|
2023-01-03 12:41:29 +00:00
|
|
|
DIAG_ON(unused-parameter) \
|
2018-02-16 11:15:32 +00:00
|
|
|
DIAG_ON(sign-compare)
|
|
|
|
#endif
|
2018-02-16 07:17:04 +00:00
|
|
|
#endif
|
|
|
|
|
2022-11-19 22:52:09 +00:00
|
|
|
/* Disable Lemon warnings. */
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define DIAG_OFF_LEMON()
|
|
|
|
#define DIAG_ON_LEMON()
|
|
|
|
#else
|
|
|
|
#define DIAG_OFF_LEMON() \
|
|
|
|
DIAG_OFF_CLANG(unreachable-code)
|
|
|
|
#define DIAG_ON_LEMON() \
|
|
|
|
DIAG_ON_CLANG(unreachable-code)
|
|
|
|
#endif
|
|
|
|
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
/*
|
|
|
|
* Suppress warnings about casting away constness.
|
|
|
|
* Do this only if you know that the pointer is to something that can
|
|
|
|
* be written and, in this context, should be writable.
|
|
|
|
*/
|
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
/*
|
|
|
|
* GCC or a compiler that claims to be GCC-compatible.
|
|
|
|
* We throw in Clang just in case clang-cl doesn't define
|
|
|
|
* __GNUC__; if it does, __GNUC__ should suffice.
|
|
|
|
*/
|
|
|
|
#define DIAG_OFF_CAST_AWAY_CONST DIAG_OFF(cast-qual)
|
|
|
|
#define DIAG_ON_CAST_AWAY_CONST DIAG_OFF(cast-qual)
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#define DIAG_OFF_CAST_AWAY_CONST
|
|
|
|
#define DIAG_ON_CAST_AWAY_CONST
|
|
|
|
#else
|
|
|
|
#define DIAG_OFF_CAST_AWAY_CONST
|
|
|
|
#define DIAG_ON_CAST_AWAY_CONST
|
|
|
|
#endif
|
|
|
|
|
2014-08-27 21:16:33 +00:00
|
|
|
/*
|
2017-04-05 19:15:27 +00:00
|
|
|
* For dealing with APIs which are only deprecated in macOS (like the
|
2014-08-27 21:16:33 +00:00
|
|
|
* OpenSSL and MIT/Heimdal Kerberos APIs).
|
|
|
|
*
|
|
|
|
* Dear Apple: this is a cross-platform program, and we're not
|
2017-04-05 19:15:27 +00:00
|
|
|
* going to use your Shiny New Frameworks on macOS unless there's
|
2014-08-27 21:16:33 +00:00
|
|
|
* a sufficiently clear benefit to make it worth our while to have
|
2017-04-05 19:15:27 +00:00
|
|
|
* both macOS and non-macOS versions of the code.
|
2014-08-27 21:16:33 +00:00
|
|
|
*/
|
|
|
|
#ifdef __APPLE__
|
|
|
|
# define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
|
|
|
|
# define USES_APPLE_RST DIAG_ON(deprecated-declarations)
|
|
|
|
#else
|
|
|
|
# define USES_APPLE_DEPRECATED_API
|
|
|
|
# define USES_APPLE_RST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* __WS_DIAG_CONTROL_H__ */
|