diff --git a/common/common-nut_version.c b/common/common-nut_version.c index a30b31ee31..dba80aef98 100644 --- a/common/common-nut_version.c +++ b/common/common-nut_version.c @@ -128,16 +128,7 @@ const char *describe_NUT_VERSION_once(void) memset(buf, 0, sizeof(buf)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* NOTE: Some compilers deduce that macro-based decisions about * NUT_VERSION_IS_RELEASE make one of codepaths unreachable in * a particular build. So we pragmatically handwave this away. @@ -186,12 +177,7 @@ const char *describe_NUT_VERSION_once(void) printed = UPS_VERSION; } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" return printed; } diff --git a/common/common.c b/common/common.c index c950d7766f..91e2300183 100644 --- a/common/common.c +++ b/common/common.c @@ -586,16 +586,7 @@ uint64_t upsnotify_extend_timeout_usec_default = 600 * 1000000, pid_t get_max_pid_t(void) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" if (sizeof(pid_t) == sizeof(short)) return (pid_t)SHRT_MAX; if (sizeof(pid_t) == sizeof(int)) return (pid_t)INT_MAX; if (sizeof(pid_t) == sizeof(long)) return (pid_t)LONG_MAX; @@ -605,12 +596,7 @@ pid_t get_max_pid_t(void) # endif #endif abort(); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" } void check_perms(const char *fn) @@ -2881,16 +2867,7 @@ char *xbasename_no_ext(const char *file) #endif /* Some compilers detect that conditions are not changing at run-time: */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" if (!exeext) { #ifdef EXEEXT @@ -2927,12 +2904,7 @@ char *xbasename_no_ext(const char *file) if (!bn) { bn = xstrdup(cs); } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" return bn; } diff --git a/docs/developers.txt b/docs/developers.txt index c97f7a48c9..7fc465985c 100644 --- a/docs/developers.txt +++ b/docs/developers.txt @@ -1083,6 +1083,13 @@ end a quiesced block of source code, e.g.: } ---- +The `nut-pragmas-unreachable-code.h` and +`nut-pragmas-unreachable-code-end.h` pair suppresses `-Wunreachable-code` +using the existing aggregate GCC capability guard and Clang pragmas. +These private headers can be included repeatedly. Keep the pair +at the original diagnostic boundaries; regions with different guards or +additional warnings need their own pragmas. + Switch case fall-through ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index 6cf0b061dd..76d6fdfc2b 100644 --- a/drivers/bcmxcp_usb.c +++ b/drivers/bcmxcp_usb.c @@ -170,24 +170,10 @@ ssize_t get_answer(unsigned char *data, unsigned char command) gettimeofday(&start_time, NULL); memset(&buf, 0x0, PW_CMD_BUFSIZE); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Stay ahead of possible redefinitions... */ assert (XCP_USB_TIMEOUT < INT_MAX); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" while ( (!endblock) && ((XCP_USB_TIMEOUT - elapsed_time) > 0) ) { diff --git a/drivers/bestfcom.c b/drivers/bestfcom.c index 231b427c47..4b662d3c33 100644 --- a/drivers/bestfcom.c +++ b/drivers/bestfcom.c @@ -258,28 +258,14 @@ void upsdrv_updateinfo(void) if (! fc.valid) { upsdebugx(1, "upsupdate run before ups_ident() read ups config"); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* NOTE: This assert() always fails because of "0": * error: will never be executed [-Werror,-Wunreachable-code] * ((0) ? (void) (0) : __assert_fail ("0", "bestfcom.c", 254, __PRETTY_FUNCTION__)); * ^ */ assert(0); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" } if (execute("f\r", fstring, sizeof(fstring)) >= 80) { diff --git a/drivers/bestuferrups.c b/drivers/bestuferrups.c index a9bcc6339c..6f6e410a5f 100644 --- a/drivers/bestuferrups.c +++ b/drivers/bestuferrups.c @@ -233,28 +233,14 @@ void upsdrv_updateinfo(void) if (! fc.valid) { fprintf(stderr, "upsupdate run before ups_ident() read ups config\n"); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* NOTE: This assert() always fails because of "0": * error: will never be executed [-Werror,-Wunreachable-code] * ((0) ? (void) (0) : __assert_fail ("0", "bestuferrups.c", 138, __PRETTY_FUNCTION__)); * ^ */ assert(0); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" } if (execute("f\r", fstring, sizeof(fstring)) > 0) { diff --git a/drivers/genericups.c b/drivers/genericups.c index 98661eeccd..6759313b7a 100644 --- a/drivers/genericups.c +++ b/drivers/genericups.c @@ -394,24 +394,10 @@ void upsdrv_shutdown(void) sdtime); if (sdtime > 0) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Different platforms, different sizes, none fits all... */ if (sizeof(long) > sizeof(unsigned int) && sdtime < (long)UINT_MAX) { -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" sleep((unsigned int)sdtime); } else { sleep(UINT_MAX); diff --git a/drivers/nut-libfreeipmi.c b/drivers/nut-libfreeipmi.c index fc63a40ade..98caf9ae2d 100644 --- a/drivers/nut-libfreeipmi.c +++ b/drivers/nut-libfreeipmi.c @@ -528,16 +528,7 @@ static int libfreeipmi_get_board_info (const void *areabuf, /* Without a standard TIME_MAX, signedness may suffer; * but we can at least check the number should fit */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Stay ahead of possible redefinitions... */ if (sizeof(mfg_date_time) > sizeof(timetmp)) { @@ -550,12 +541,7 @@ static int libfreeipmi_get_board_info (const void *areabuf, * should expose that so we look for a fix - so do not just blindly * move the closing pragmas to end of method ;) */ -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" timetmp = (time_t)mfg_date_time; localtime_r (&timetmp, &mfg_date_time_tm); diff --git a/include/Makefile.am b/include/Makefile.am index 4a4da44b98..5c7318cf33 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,6 +16,8 @@ dist_noinst_HEADERS = \ nut_bool.h nut_float.h nut_stdint.h nut_platform.h \ nut-pragmas-covered-switch-default.h \ nut-pragmas-covered-switch-default-end.h \ + nut-pragmas-unreachable-code.h \ + nut-pragmas-unreachable-code-end.h \ strcasestr-static.h wincompat.h # Optionally deliverable as part of NUT public API: diff --git a/include/nut-pragmas-unreachable-code-end.h b/include/nut-pragmas-unreachable-code-end.h new file mode 100644 index 0000000000..d6fd707c27 --- /dev/null +++ b/include/nut-pragmas-unreachable-code-end.h @@ -0,0 +1,28 @@ +/* nut-pragmas-unreachable-code-end.h - restore diagnostic warnings + + Copyright (C) 2020-2026 Jim Klimov + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* This file is intentionally repeat-includable so one translation unit can + * bracket several unreachable code regions. */ + +#ifdef __clang__ +# pragma clang diagnostic pop +#endif +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +# pragma GCC diagnostic pop +#endif diff --git a/include/nut-pragmas-unreachable-code.h b/include/nut-pragmas-unreachable-code.h new file mode 100644 index 0000000000..e9857d4f50 --- /dev/null +++ b/include/nut-pragmas-unreachable-code.h @@ -0,0 +1,32 @@ +/* nut-pragmas-unreachable-code.h - quiesce unreachable code warnings + + Copyright (C) 2020-2026 Jim Klimov + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* This file is intentionally repeat-includable so one translation unit can + * bracket several unreachable code regions. */ + +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +# pragma GCC diagnostic push +#endif +#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +# pragma GCC diagnostic ignored "-Wunreachable-code" +#endif +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunreachable-code" +#endif diff --git a/server/netget.c b/server/netget.c index de22d96ace..aebe1249da 100644 --- a/server/netget.c +++ b/server/netget.c @@ -185,16 +185,7 @@ static void get_type(nut_ctype_t *client, const char *upsname, const char *var) static void get_var_server(nut_ctype_t *client, const char *upsname, const char *var) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" int pkgurlHasNutOrg = PACKAGE_URL ? (strstr(PACKAGE_URL, "networkupstools.org") != NULL) : 0; if (!strcasecmp(var, "server.info")) { @@ -212,12 +203,7 @@ static void get_var_server(nut_ctype_t *client, const char *upsname, const char ); return; } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" if (!strcasecmp(var, "server.version")) { sendback(client, "VAR %s server.version \"%s\"\n", diff --git a/server/netmisc.c b/server/netmisc.c index fbf8e0eb31..35a96c287a 100644 --- a/server/netmisc.c +++ b/server/netmisc.c @@ -39,16 +39,7 @@ void net_ver(nut_ctype_t *client, size_t numarg, const char **arg) return; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" if (PACKAGE_URL && strstr(PACKAGE_URL, "networkupstools.org")) { pkgurlHasNutOrg = 1; } else { @@ -65,12 +56,7 @@ void net_ver(nut_ctype_t *client, size_t numarg, const char **arg) (PACKAGE_URL && !pkgurlHasNutOrg) ? " or " : "", pkgurlHasNutOrg ? "" : "https://www.networkupstools.org/" ); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" } void net_netver(nut_ctype_t *client, size_t numarg, const char **arg) diff --git a/server/netssl.c b/server/netssl.c index d8a6d263e2..be917e3328 100644 --- a/server/netssl.c +++ b/server/netssl.c @@ -1237,16 +1237,7 @@ void ssl_init(void) /* Pragmas due to macro'd definition details of sk_SSL_CIPHER* etc. * upsetting some compilers (e.g. older clang in C99 mode) */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" SSL *tmp_ssl = SSL_new(ssl_ctx); STACK_OF(SSL_CIPHER) *ciphers = SSL_get_ciphers(tmp_ssl); int ii; @@ -1257,12 +1248,7 @@ void ssl_init(void) } SSL_free(tmp_ssl); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" } # ifdef WITH_CLIENT_CERTIFICATE_VALIDATION diff --git a/tools/nut-scanner/nut-scanner.c b/tools/nut-scanner/nut-scanner.c index 6389cafe3b..6806a92deb 100644 --- a/tools/nut-scanner/nut-scanner.c +++ b/tools/nut-scanner/nut-scanner.c @@ -1683,24 +1683,10 @@ int main(int argc, char *argv[]) sem_close(current_sem); } # endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Different platforms, different sizes, none fits all... */ if (SIZE_MAX > UINT_MAX && max_threads > UINT_MAX) { -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" fprintf(stderr, "\n\n" "WARNING: Limiting max_threads to range acceptable for " REPORT_SEM_INIT_METHOD "()\n\n"); diff --git a/tools/nut-scanner/nutscan-init.c b/tools/nut-scanner/nutscan-init.c index 3714df3031..462851676e 100644 --- a/tools/nut-scanner/nutscan-init.c +++ b/tools/nut-scanner/nutscan-init.c @@ -252,24 +252,10 @@ void nutscan_init(void) * after parsing command-line arguments. It calls nutscan_init() before * parsing CLI, to know about available libs and to set defaults below. */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Different platforms, different sizes, none fits all... */ if (SIZE_MAX > UINT_MAX && max_threads > UINT_MAX) { -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" upsdebugx(1, "WARNING: %s: Limiting max_threads to range acceptable for " REPORT_SEM_INIT_METHOD "()", __func__); diff --git a/tools/nut-scanner/scan_ipmi.c b/tools/nut-scanner/scan_ipmi.c index f554c9c657..33c8ee7bda 100644 --- a/tools/nut-scanner/scan_ipmi.c +++ b/tools/nut-scanner/scan_ipmi.c @@ -813,24 +813,10 @@ nutscan_device_t * nutscan_scan_ip_range_ipmi(nutscan_ip_range_list_t * irl, nut # if (defined HAVE_SEMAPHORE_UNNAMED) || (defined HAVE_SEMAPHORE_NAMED) if (max_threads_scantype > 0) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Different platforms, different sizes, none fits all... */ if (SIZE_MAX > UINT_MAX && max_threads_scantype > UINT_MAX) { -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" upsdebugx(1, "WARNING: %s: Limiting max_threads_scantype to range acceptable for " REPORT_SEM_INIT_METHOD "()", __func__); diff --git a/tools/nut-scanner/scan_nut.c b/tools/nut-scanner/scan_nut.c index 2ebef69445..8859fcf100 100644 --- a/tools/nut-scanner/scan_nut.c +++ b/tools/nut-scanner/scan_nut.c @@ -708,24 +708,10 @@ nutscan_device_t * nutscan_scan_ip_range_nut_authconf(nutscan_ip_range_list_t * # if (defined HAVE_SEMAPHORE_UNNAMED) || (defined HAVE_SEMAPHORE_NAMED) if (max_threads_scantype > 0) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Different platforms, different sizes, none fits all... */ if (SIZE_MAX > UINT_MAX && max_threads_scantype > UINT_MAX) { -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" upsdebugx(1, "WARNING: %s: Limiting max_threads_scantype to range acceptable for " REPORT_SEM_INIT_METHOD "()", __func__); diff --git a/tools/nut-scanner/scan_snmp.c b/tools/nut-scanner/scan_snmp.c index c890322f64..17082010fd 100644 --- a/tools/nut-scanner/scan_snmp.c +++ b/tools/nut-scanner/scan_snmp.c @@ -1152,24 +1152,10 @@ nutscan_device_t * nutscan_scan_ip_range_snmp( # if (defined HAVE_SEMAPHORE_UNNAMED) || (defined HAVE_SEMAPHORE_NAMED) if (max_threads_scantype > 0) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Different platforms, different sizes, none fits all... */ if (SIZE_MAX > UINT_MAX && max_threads_scantype > UINT_MAX) { -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" upsdebugx(1, "WARNING: %s: Limiting max_threads_scantype to range acceptable for " REPORT_SEM_INIT_METHOD "()", __func__); diff --git a/tools/nut-scanner/scan_xml_http.c b/tools/nut-scanner/scan_xml_http.c index 92d197d434..ed67945cc0 100644 --- a/tools/nut-scanner/scan_xml_http.c +++ b/tools/nut-scanner/scan_xml_http.c @@ -553,24 +553,10 @@ nutscan_device_t * nutscan_scan_ip_range_xml_http(nutscan_ip_range_list_t * irl, # if (defined HAVE_SEMAPHORE_UNNAMED) || (defined HAVE_SEMAPHORE_NAMED) if (max_threads_scantype > 0) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif +#include "nut-pragmas-unreachable-code.h" /* Different platforms, different sizes, none fits all... */ if (SIZE_MAX > UINT_MAX && max_threads_scantype > UINT_MAX) { -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif +#include "nut-pragmas-unreachable-code-end.h" upsdebugx(1, "WARNING: %s: Limiting max_threads_scantype to range acceptable for " REPORT_SEM_INIT_METHOD "()", __func__);