From 6946774df6d8c330f2a9487762e2691a77cb88ce Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 1 Jun 2024 22:46:46 +0200 Subject: [PATCH] Harden NUT work with strings by switching to snprintf_dynamic() instead of hushing potential flaws with macros [#2450] Found by pragmas to clean up, with :; git grep -En 'Wformat-(sec|nonlit)' Signed-off-by: Jim Klimov --- clients/upsclient.c | 54 ++--- clients/upsimage.c | 18 +- clients/upsmon.c | 17 +- drivers/apc_modbus.c | 41 +--- drivers/apcupsd-ups.c | 18 +- drivers/bcmxcp.c | 16 +- drivers/bestfortress.c | 16 +- drivers/blazer.c | 32 +-- drivers/blazer_ser.c | 2 +- drivers/blazer_usb.c | 2 +- drivers/huawei-ups2000.c | 18 +- drivers/liebert-esp2.c | 47 +---- drivers/nutdrv_qx.c | 16 +- drivers/nutdrv_qx_bestups.c | 90 ++------ drivers/nutdrv_qx_blazer-common.c | 20 +- drivers/nutdrv_qx_masterguard.c | 22 +- drivers/nutdrv_qx_mecer.c | 30 +-- drivers/nutdrv_qx_voltronic-qs-hex.c | 88 +------- drivers/nutdrv_qx_voltronic-qs.c | 16 +- drivers/nutdrv_qx_voltronic.c | 304 +++------------------------ drivers/powerp-bin.c | 18 +- drivers/powerp-txt.c | 16 +- drivers/snmp-ups.c | 228 +++++--------------- drivers/usbhid-ups.c | 16 +- 24 files changed, 179 insertions(+), 966 deletions(-) diff --git a/clients/upsclient.c b/clients/upsclient.c index 74290cd26f..cee424a61a 100644 --- a/clients/upsclient.c +++ b/clients/upsclient.c @@ -554,16 +554,6 @@ const char *upscli_strerror(UPSCONN_t *ups) char sslbuf[UPSCLI_ERRBUF_LEN]; #endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - if (!ups) { return upscli_errlist[UPSCLI_ERR_INVALIDARG].str; } @@ -582,9 +572,10 @@ const char *upscli_strerror(UPSCONN_t *ups) return upscli_errlist[ups->upserror].str; case 1: /* add message from system's strerror */ - snprintf(ups->errbuf, UPSCLI_ERRBUF_LEN, + snprintf_dynamic( + ups->errbuf, UPSCLI_ERRBUF_LEN, upscli_errlist[ups->upserror].str, - strerror(ups->syserrno)); + "%s", strerror(ups->syserrno)); return ups->errbuf; case 2: /* SSL error */ @@ -592,13 +583,15 @@ const char *upscli_strerror(UPSCONN_t *ups) err = ERR_get_error(); if (err) { ERR_error_string(err, sslbuf); - snprintf(ups->errbuf, UPSCLI_ERRBUF_LEN, + snprintf_dynamic( + ups->errbuf, UPSCLI_ERRBUF_LEN, upscli_errlist[ups->upserror].str, - sslbuf); + "%s", sslbuf); } else { - snprintf(ups->errbuf, UPSCLI_ERRBUF_LEN, + snprintf_dynamic( + ups->errbuf, UPSCLI_ERRBUF_LEN, upscli_errlist[ups->upserror].str, - "peer disconnected"); + "%s", "peer disconnected"); } #elif defined(WITH_NSS) /* WITH_OPENSSL */ if (PR_GetErrorTextLength() < UPSCLI_ERRBUF_LEN) { @@ -615,16 +608,13 @@ const char *upscli_strerror(UPSCONN_t *ups) return ups->errbuf; case 3: /* parsing (parseconf) error */ - snprintf(ups->errbuf, UPSCLI_ERRBUF_LEN, + snprintf_dynamic( + ups->errbuf, UPSCLI_ERRBUF_LEN, upscli_errlist[ups->upserror].str, - ups->pc_ctx.errmsg); + "%s", ups->pc_ctx.errmsg); return ups->errbuf; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif - /* fallthrough */ snprintf(ups->errbuf, UPSCLI_ERRBUF_LEN, "Unknown error flag %d", @@ -1316,23 +1306,9 @@ static void build_cmd(char *buf, size_t bufsize, const char *cmdname, format = " %s"; } - /* snprintfcat would tie us to common */ - - len = strlen(buf); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(buf + len, bufsize - len, format, - pconf_encode(arg[i], enc, sizeof(enc))); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintfcat_dynamic( + buf, bufsize, format, + "%s", pconf_encode(arg[i], enc, sizeof(enc))); } len = strlen(buf); diff --git a/clients/upsimage.c b/clients/upsimage.c index 276852de92..7e7deec06a 100644 --- a/clients/upsimage.c +++ b/clients/upsimage.c @@ -275,20 +275,10 @@ static void drawbar( gdImageFilledRectangle(im, 25, bar_y, width - 25, scale_height, bar_color); - /* stick the text version of the value at the bottom center */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(text, sizeof(text), format, value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + /* stick the text version of the value at the bottom center + * expected format is one of imgvar[] entries for "double value" + */ + snprintf_dynamic(text, sizeof(text), format, "%f", value); gdImageString(im, gdFontMediumBold, (width - (int)(strlen(text))*gdFontMediumBold->w)/2, height - gdFontMediumBold->h, diff --git a/clients/upsmon.c b/clients/upsmon.c index 1e64c564a7..33953de966 100644 --- a/clients/upsmon.c +++ b/clients/upsmon.c @@ -378,21 +378,12 @@ static void do_notify(const utype_t *ups, int ntype) if (notifylist[i].type == ntype) { upsdebugx(2, "%s: ntype 0x%04x (%s)", __func__, ntype, notifylist[i].name); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(msg, sizeof(msg), + + snprintf_dynamic(msg, sizeof(msg), notifylist[i].msg ? notifylist[i].msg : notifylist[i].stockmsg, + "%s", ups ? ups->sys : ""); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + notify(msg, notifylist[i].flags, notifylist[i].name, upsname); diff --git a/drivers/apc_modbus.c b/drivers/apc_modbus.c index 8aafce1479..655d6da26c 100644 --- a/drivers/apc_modbus.c +++ b/drivers/apc_modbus.c @@ -32,7 +32,7 @@ #include #define DRIVER_NAME "NUT APC Modbus driver" -#define DRIVER_VERSION "0.10" +#define DRIVER_VERSION "0.11" #if defined NUT_MODBUS_HAS_USB @@ -389,16 +389,8 @@ static int _apc_modbus_double_to_nut(const apc_modbus_value_t *value, char *outp if (value->format != NULL) format = value->format; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif - res = snprintf(output, output_len, format, double_value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + res = snprintf_dynamic(output, output_len, format, "%f", double_value); + if (res < 0 || (size_t)res >= output_len) { return 0; } @@ -432,16 +424,8 @@ static int _apc_modbus_power_to_nut(const apc_modbus_value_t *value, char *outpu if (value->format != NULL) format = value->format; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif - res = snprintf(output, output_len, format, double_value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + res = snprintf_dynamic(output, output_len, format, "%f", double_value); + if (res < 0 || (size_t)res >= output_len) { return 0; } @@ -1059,27 +1043,18 @@ static int _apc_modbus_update_value(apc_modbus_register_t *regs_info, const uint } dstate_setinfo(regs_info->nut_variable_name, "%s", nutvbuf); } else { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif assert(regs_info->value_type <= apc_modbus_value_types_max); switch (regs_info->value_type) { case APC_VT_STRING: - dstate_setinfo(regs_info->nut_variable_name, regs_info->value_format, value.data.string_value); + dstate_setinfo_dynamic(regs_info->nut_variable_name, regs_info->value_format, "%s", value.data.string_value); break; case APC_VT_INT: - dstate_setinfo(regs_info->nut_variable_name, regs_info->value_format, value.data.int_value); + dstate_setinfo_dynamic(regs_info->nut_variable_name, regs_info->value_format, "%" PRIi64, value.data.int_value); break; case APC_VT_UINT: - dstate_setinfo(regs_info->nut_variable_name, regs_info->value_format, value.data.uint_value); + dstate_setinfo_dynamic(regs_info->nut_variable_name, regs_info->value_format, "%" PRIu64, value.data.uint_value); break; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif } dstate_flags = 0; diff --git a/drivers/apcupsd-ups.c b/drivers/apcupsd-ups.c index 9f4b71bc20..303b2ac7a7 100644 --- a/drivers/apcupsd-ups.c +++ b/drivers/apcupsd-ups.c @@ -57,7 +57,7 @@ typedef struct pollfd { #include "nut_stdint.h" #define DRIVER_NAME "apcupsd network client UPS driver" -#define DRIVER_VERSION "0.72" +#define DRIVER_VERSION "0.73" #define POLL_INTERVAL_MIN 10 @@ -163,22 +163,10 @@ static void process(char *item,char *data) } else { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif /* default_value acts as a format string in this case */ - dstate_setinfo(nut_data[i].info_type, + dstate_setinfo_dynamic(nut_data[i].info_type, nut_data[i].default_value, - atof(data)*nut_data[i].info_len); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + "%f", atof(data)*nut_data[i].info_len); } break; } diff --git a/drivers/bcmxcp.c b/drivers/bcmxcp.c index 475316c217..12764c56be 100644 --- a/drivers/bcmxcp.c +++ b/drivers/bcmxcp.c @@ -118,7 +118,7 @@ TODO List: #include "bcmxcp.h" #define DRIVER_NAME "BCMXCP UPS driver" -#define DRIVER_VERSION "0.34" +#define DRIVER_VERSION "0.35" #define MAX_NUT_NAME_LENGTH 128 #define NUT_OUTLET_POSITION 7 @@ -897,19 +897,7 @@ void decode_meter_map_entry(const unsigned char *entry, const unsigned char form fValue = get_float(entry); /* Format is packed BCD */ snprintf(sFormat, 31, "%%%d.%df", ((format & 0xf0) >> 4), (format & 0x0f)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, 127, sFormat, fValue); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, 127, sFormat, "%f", fValue); } else if (format == 0xe2) { /* Seconds */ diff --git a/drivers/bestfortress.c b/drivers/bestfortress.c index 5b400c2405..e10a81c911 100644 --- a/drivers/bestfortress.c +++ b/drivers/bestfortress.c @@ -35,7 +35,7 @@ #endif #define DRIVER_NAME "Best Fortress UPS driver" -#define DRIVER_VERSION "0.09" +#define DRIVER_VERSION "0.10" /* driver description structure */ upsdrv_info_t upsdrv_info = { @@ -185,19 +185,7 @@ static inline void setinfo_float (const char *key, const char * fmt, const char strncpy (buf, s, len); buf[len] = 0; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo (key, fmt, factor * (double)(atoi (buf))); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + dstate_setinfo_dynamic (key, fmt, "%f", factor * (double)(atoi (buf))); } static int upssend(const char *fmt,...) { diff --git a/drivers/blazer.c b/drivers/blazer.c index af224fb5bb..c6512176d2 100644 --- a/drivers/blazer.c +++ b/drivers/blazer.c @@ -204,7 +204,6 @@ static int blazer_status(const char *cmd) } for (i = 0, val = strtok_r(buf+1, " ", &last); status[i].var; i++, val = strtok_r(NULL, " \r\n", &last)) { - if (!val) { upsdebugx(2, "%s: parsing failed", __func__); return -1; @@ -215,20 +214,7 @@ static int blazer_status(const char *cmd) continue; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo(status[i].var, status[i].fmt, status[i].conv(val, NULL)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif - + dstate_setinfo_dynamic(status[i].var, status[i].fmt, "%f", status[i].conv(val, NULL)); } if (!val) { @@ -344,7 +330,6 @@ static int blazer_rating(const char *cmd) } for (i = 0, val = strtok_r(buf+1, " ", &last); rating[i].var; i++, val = strtok_r(NULL, " \r\n", &last)) { - if (!val) { upsdebugx(2, "%s: parsing failed", __func__); return -1; @@ -355,20 +340,7 @@ static int blazer_rating(const char *cmd) continue; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo(rating[i].var, rating[i].fmt, rating[i].conv(val, NULL)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif - + dstate_setinfo_dynamic(rating[i].var, rating[i].fmt, "%f", rating[i].conv(val, NULL)); } return 0; diff --git a/drivers/blazer_ser.c b/drivers/blazer_ser.c index 5f830e3e6a..8bdc2c423f 100644 --- a/drivers/blazer_ser.c +++ b/drivers/blazer_ser.c @@ -31,7 +31,7 @@ #include "blazer.h" #define DRIVER_NAME "Megatec/Q1 protocol serial driver" -#define DRIVER_VERSION "1.62" +#define DRIVER_VERSION "1.63" /* driver description structure */ upsdrv_info_t upsdrv_info = { diff --git a/drivers/blazer_usb.c b/drivers/blazer_usb.c index 7cc5c8c039..a0693806c9 100644 --- a/drivers/blazer_usb.c +++ b/drivers/blazer_usb.c @@ -37,7 +37,7 @@ #endif #define DRIVER_NAME "Megatec/Q1 protocol USB driver" -#define DRIVER_VERSION "0.19" +#define DRIVER_VERSION "0.20" /* driver description structure */ upsdrv_info_t upsdrv_info = { diff --git a/drivers/huawei-ups2000.c b/drivers/huawei-ups2000.c index ce9cb2bbae..ab448b631f 100644 --- a/drivers/huawei-ups2000.c +++ b/drivers/huawei-ups2000.c @@ -51,7 +51,7 @@ #include "timehead.h" /* fallback gmtime_r() variants if needed (e.g. some WIN32) */ #define DRIVER_NAME "NUT Huawei UPS2000 (1kVA-3kVA) RS-232 Modbus driver" -#define DRIVER_VERSION "0.06" +#define DRIVER_VERSION "0.07" #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) #define MODBUS_SLAVE_ID 1 @@ -627,20 +627,8 @@ static int ups2000_update_info(void) return 1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo(ups2000_var[i].name, ups2000_var[i].fmt, - (float) val / ups2000_var[i].scaling); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + dstate_setinfo_dynamic(ups2000_var[i].name, ups2000_var[i].fmt, + "%f", (float) val / ups2000_var[i].scaling); } return 0; } diff --git a/drivers/liebert-esp2.c b/drivers/liebert-esp2.c index 10b67b789e..03136a9b6f 100644 --- a/drivers/liebert-esp2.c +++ b/drivers/liebert-esp2.c @@ -28,7 +28,7 @@ #define IsBitSet(val, bit) ((val) & (1 << (bit))) #define DRIVER_NAME "Liebert ESP-II serial UPS driver" -#define DRIVER_VERSION "0.07" +#define DRIVER_VERSION "0.08" #define UPS_SHUTDOWN_DELAY 12 /* it means UPS will be shutdown 120 sec */ #define SHUTDOWN_CMD_LEN 8 @@ -400,19 +400,8 @@ void upsdrv_updateinfo(void) intval = (unsigned char)reply[5]; intval <<= 8; intval += (unsigned char)reply[6]; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo(vartab[i].var, vartab[i].fmt, multi[vartab[i].multindex] * intval); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + + dstate_setinfo_dynamic(vartab[i].var, vartab[i].fmt, "%f", multi[vartab[i].multindex] * intval); } if (num_inphases==3){ @@ -444,19 +433,8 @@ void upsdrv_updateinfo(void) intval = (unsigned char)reply[5]; intval <<= 8; intval += (unsigned char)reply[6]; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo(cmdin_p[i].var, cmdin_p[i].fmt, multi[cmdin_p[i].multindex] * intval); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + + dstate_setinfo_dynamic(cmdin_p[i].var, cmdin_p[i].fmt, "%f", multi[cmdin_p[i].multindex] * intval); } for (i = 0; cmdout_p[i].var; i++) { @@ -468,19 +446,8 @@ void upsdrv_updateinfo(void) intval = (unsigned char)reply[5]; intval <<= 8; intval += (unsigned char)reply[6]; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo(cmdout_p[i].var, cmdout_p[i].fmt, multi[cmdout_p[i].multindex] * intval); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + + dstate_setinfo_dynamic(cmdout_p[i].var, cmdout_p[i].fmt, "%f", multi[cmdout_p[i].multindex] * intval); } status_init(); diff --git a/drivers/nutdrv_qx.c b/drivers/nutdrv_qx.c index a50728a356..713992527e 100644 --- a/drivers/nutdrv_qx.c +++ b/drivers/nutdrv_qx.c @@ -58,7 +58,7 @@ #define DRIVER_NAME "Generic Q* Serial driver" #endif /* QX_USB */ -#define DRIVER_VERSION "0.36" +#define DRIVER_VERSION "0.37" #ifdef QX_SERIAL #include "serial.h" @@ -4403,19 +4403,7 @@ int ups_infoval_set(item_t *item) return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, sizeof(value), item->dfl, strtod(value, NULL)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, sizeof(value), item->dfl, "%f", strtod(value, NULL)); } } diff --git a/drivers/nutdrv_qx_bestups.c b/drivers/nutdrv_qx_bestups.c index 94de756661..dc4ee1b919 100644 --- a/drivers/nutdrv_qx_bestups.c +++ b/drivers/nutdrv_qx_bestups.c @@ -30,7 +30,7 @@ #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_bestups.h" -#define BESTUPS_VERSION "BestUPS 0.07" +#define BESTUPS_VERSION "BestUPS 0.08" /* Support functions */ static int bestups_claim(void); @@ -375,19 +375,7 @@ static int bestups_process_setvar(item_t *item, char *value, const size_t valuel } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->command, val); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->command, "%f", val); return 0; } @@ -422,16 +410,6 @@ static int bestups_process_bbb_status_bit(item_t *item, char *value, const size_ /* Identify UPS manufacturer */ static int bestups_manufacturer(item_t *item, char *value, const size_t valuelen) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - /* Best Power devices */ if ( !strcmp(item->value, "AX1") || @@ -440,7 +418,7 @@ static int bestups_manufacturer(item_t *item, char *value, const size_t valuelen !strcmp(item->value, "PR2") || !strcmp(item->value, "PRO") ) { - snprintf(value, valuelen, item->dfl, "Best Power"); + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Best Power"); return 0; } @@ -450,16 +428,12 @@ static int bestups_manufacturer(item_t *item, char *value, const size_t valuelen !strcmp(item->value, "520") || !strcmp(item->value, "620") ) { - snprintf(value, valuelen, item->dfl, "Sola Australia"); + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Sola Australia"); return 0; } /* Unknown devices */ - snprintf(value, valuelen, item->dfl, "Unknown"); - -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Unknown"); return 0; } @@ -469,38 +443,28 @@ static int bestups_model(item_t *item, char *value, const size_t valuelen) { item_t *unskip; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - /* Best Power devices */ if (!strcmp(item->value, "AX1")) { - snprintf(value, valuelen, item->dfl, "Axxium Rackmount"); + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Axxium Rackmount"); } else if (!strcmp(item->value, "FOR")) { - snprintf(value, valuelen, item->dfl, "Fortress"); + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Fortress"); } else if (!strcmp(item->value, "FTC")) { - snprintf(value, valuelen, item->dfl, "Fortress Telecom"); + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Fortress Telecom"); } else if (!strcmp(item->value, "PR2")) { - snprintf(value, valuelen, item->dfl, "Patriot Pro II"); + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Patriot Pro II"); inverted_bbb_bit = 1; } else if (!strcmp(item->value, "PRO")) { - snprintf(value, valuelen, item->dfl, "Patriot Pro"); + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Patriot Pro"); inverted_bbb_bit = 1; /* Sola Australia devices */ @@ -550,10 +514,6 @@ static int bestups_model(item_t *item, char *value, const size_t valuelen) } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif - return 0; } @@ -570,19 +530,7 @@ static int bestups_batt_runtime(item_t *item, char *value, const size_t valuelen /* Battery runtime is reported by the UPS in minutes, NUT expects seconds */ runtime = strtod(item->value, NULL) * 60; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, runtime); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", runtime); return 0; } @@ -676,7 +624,7 @@ static int bestups_get_pins_shutdown_mode(item_t *item, char *value, const size_ static int bestups_voltage_settings(item_t *item, char *value, const size_t valuelen) { long index; - int val; + int val; const char *nominal_voltage; const struct { const int low; /* Low voltage -> input.transfer.low / input.transfer.boost.low */ @@ -771,19 +719,7 @@ static int bestups_voltage_settings(item_t *item, char *value, const size_t valu } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, val); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%d", val); return 0; } diff --git a/drivers/nutdrv_qx_blazer-common.c b/drivers/nutdrv_qx_blazer-common.c index 2ff16bc3bb..cd4ea4a0ff 100644 --- a/drivers/nutdrv_qx_blazer-common.c +++ b/drivers/nutdrv_qx_blazer-common.c @@ -242,16 +242,6 @@ int blazer_process_setvar(item_t *item, char *value, const size_t valuelen) /* Preprocess instant commands */ int blazer_process_command(item_t *item, char *value, const size_t valuelen) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - if (!strcasecmp(item->info_type, "shutdown.return")) { /* Sn: Shutdown after n minutes and then turn on when mains is back @@ -264,7 +254,7 @@ int blazer_process_command(item_t *item, char *value, const size_t valuelen) * (thus the default of ondelay=3 mins) */ long offdelay = strtol(dstate_getinfo("ups.delay.shutdown"), NULL, 10), - ondelay = strtol(dstate_getinfo("ups.delay.start"), NULL, 10) / 60; + ondelay = strtol(dstate_getinfo("ups.delay.start"), NULL, 10) / 60; char buf[SMALLBUF] = ""; if (ondelay <= 0) { @@ -303,7 +293,7 @@ int blazer_process_command(item_t *item, char *value, const size_t valuelen) } - snprintf(value, valuelen, item->command, buf); + snprintf_dynamic(value, valuelen, item->command, "%s", buf); } else if (!strcasecmp(item->info_type, "shutdown.stayoff")) { @@ -326,7 +316,7 @@ int blazer_process_command(item_t *item, char *value, const size_t valuelen) snprintf(buf, sizeof(buf), "%02ld", offdelay / 60); } - snprintf(value, valuelen, item->command, buf); + snprintf_dynamic(value, valuelen, item->command, "%s", buf); } else if (!strcasecmp(item->info_type, "test.battery.start")) { @@ -348,10 +338,6 @@ int blazer_process_command(item_t *item, char *value, const size_t valuelen) } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif - return 0; } diff --git a/drivers/nutdrv_qx_masterguard.c b/drivers/nutdrv_qx_masterguard.c index 85a0cae0f6..815035ca57 100644 --- a/drivers/nutdrv_qx_masterguard.c +++ b/drivers/nutdrv_qx_masterguard.c @@ -26,7 +26,7 @@ #include #include "nut_stdint.h" -#define MASTERGUARD_VERSION "Masterguard 0.02" +#define MASTERGUARD_VERSION "Masterguard 0.03" /* series (for un-SKIP) */ static char masterguard_my_series = '?'; @@ -600,29 +600,19 @@ static int masterguard_setvar(item_t *item, char *value, const size_t valuelen) upsdebugx(2, "setvar: unknown dfl %s", item->dfl); return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif + switch (t) { case 'd': - snprintf(value, valuelen, item->command, i); + snprintf_dynamic(value, valuelen, item->command, "%ld", i); break; case 'f': - snprintf(value, valuelen, item->command, f); + snprintf_dynamic(value, valuelen, item->command, "%f", f); break; case 's': - snprintf(value, valuelen, item->command, s); + snprintf_dynamic(value, valuelen, item->command, "%s", s); break; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + return 0; ill: upsdebugx(2, "setvar: illegal %s value %s", item->dfl, value); diff --git a/drivers/nutdrv_qx_mecer.c b/drivers/nutdrv_qx_mecer.c index e4702944ca..a4fc1415d5 100644 --- a/drivers/nutdrv_qx_mecer.c +++ b/drivers/nutdrv_qx_mecer.c @@ -25,7 +25,7 @@ #include "nutdrv_qx_mecer.h" -#define MECER_VERSION "Mecer 0.08" +#define MECER_VERSION "Mecer 0.09" /* Support functions */ static int mecer_claim(void); @@ -215,19 +215,7 @@ static int voltronic_p98_protocol(item_t *item, char *value, const size_t valuel return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, "Voltronic Power P98"); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", "Voltronic Power P98"); return 0; } @@ -274,19 +262,7 @@ static int mecer_process_test_battery(item_t *item, char *value, const size_t va } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->command, buf); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->command, "%s", buf); return 0; } diff --git a/drivers/nutdrv_qx_voltronic-qs-hex.c b/drivers/nutdrv_qx_voltronic-qs-hex.c index 9485fe0e18..9f303f46e8 100644 --- a/drivers/nutdrv_qx_voltronic-qs-hex.c +++ b/drivers/nutdrv_qx_voltronic-qs-hex.c @@ -25,7 +25,7 @@ #include "nutdrv_qx_voltronic-qs-hex.h" -#define VOLTRONIC_QS_HEX_VERSION "Voltronic-QS-Hex 0.10" +#define VOLTRONIC_QS_HEX_VERSION "Voltronic-QS-Hex 0.11" /* Support functions */ static int voltronic_qs_hex_claim(void); @@ -323,19 +323,7 @@ static int voltronic_qs_hex_protocol(item_t *item, char *value, const size_t val return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, item->value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", item->value); /* Unskip items supported only by devices that implement 'T' protocol */ @@ -368,19 +356,7 @@ static int voltronic_qs_hex_input_output_voltage(item_t *item, char *value, cons val = strtol(item->value, &str_end, 16) * strtol(str_end, NULL, 16) / 51; ret = val / 256.0; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, ret); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", ret); return 0; } @@ -393,19 +369,7 @@ static int voltronic_qs_hex_load(item_t *item, char *value, const size_t valuele return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, strtol(item->value, NULL, 16)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%ld", strtol(item->value, NULL, 16)); return 0; } @@ -427,19 +391,7 @@ static int voltronic_qs_hex_frequency(item_t *item, char *value, const size_t va ret = val2 / val1; ret = ret > 99.9 ? 99.9 : ret; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, ret); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", ret); return 0; } @@ -448,6 +400,7 @@ static int voltronic_qs_hex_frequency(item_t *item, char *value, const size_t va static int voltronic_qs_hex_battery_voltage(item_t *item, char *value, const size_t valuelen) { long val1, val2; + double val3; char *str_end; if (strspn(item->value, "0123456789ABCDEFabcdef ") != strlen(item->value)) { @@ -457,20 +410,9 @@ static int voltronic_qs_hex_battery_voltage(item_t *item, char *value, const siz val1 = strtol(item->value, &str_end, 16); val2 = strtol(str_end, NULL, 16); + val3 = (val1 * val2) / 510.0; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, (val1 * val2) / 510.0); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", val3); return 0; } @@ -538,19 +480,7 @@ static int voltronic_qs_hex_process_ratings_bits(item_t *item, char *value, cons return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, ret); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", ret); return 0; } diff --git a/drivers/nutdrv_qx_voltronic-qs.c b/drivers/nutdrv_qx_voltronic-qs.c index d0a3cb2f7e..2732f13d2c 100644 --- a/drivers/nutdrv_qx_voltronic-qs.c +++ b/drivers/nutdrv_qx_voltronic-qs.c @@ -25,7 +25,7 @@ #include "nutdrv_qx_voltronic-qs.h" -#define VOLTRONIC_QS_VERSION "Voltronic-QS 0.09" +#define VOLTRONIC_QS_VERSION "Voltronic-QS 0.10" /* Support functions */ static int voltronic_qs_claim(void); @@ -204,19 +204,7 @@ static int voltronic_qs_protocol(item_t *item, char *value, const size_t valuele if (ret == -1) { upsdebugx(2, "%s: invalid protocol [%s]", __func__, item->value); } else { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, item->value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", item->value); } return ret; diff --git a/drivers/nutdrv_qx_voltronic.c b/drivers/nutdrv_qx_voltronic.c index 23e932f5c6..1208d3ef37 100644 --- a/drivers/nutdrv_qx_voltronic.c +++ b/drivers/nutdrv_qx_voltronic.c @@ -25,7 +25,7 @@ #include "nutdrv_qx.h" #include "nutdrv_qx_voltronic.h" -#define VOLTRONIC_VERSION "Voltronic 0.08" +#define VOLTRONIC_VERSION "Voltronic 0.09" /* Support functions */ static int voltronic_claim(void); @@ -1921,19 +1921,7 @@ static int voltronic_process_setvar(item_t *item, char *value, const size_t valu } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->command, val); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->command, "%f", val); return 0; } @@ -2069,19 +2057,7 @@ static int voltronic_process_command(item_t *item, char *value, const size_t val } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->command, buf); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->command, "%s", buf); return 0; } @@ -2396,19 +2372,7 @@ static int voltronic_capability(item_t *item, char *value, const size_t valuelen if (!val) return -1; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, val); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", val); /* This item doesn't have a NUT var and we were not asked by the user to change its value */ if ((item->qxflags & QX_FLAG_NONUT) && !getval(item->info_type)) @@ -2429,27 +2393,15 @@ static int voltronic_capability(item_t *item, char *value, const size_t valuelen /* *SETVAR* Set UPS capability options */ static int voltronic_capability_set(item_t *item, char *value, const size_t valuelen) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif if (!strcasecmp(value, "yes")) { - snprintf(value, valuelen, item->command, "E"); + snprintf_dynamic(value, valuelen, item->command, "%s", "E"); return 0; } if (!strcasecmp(value, "no")) { - snprintf(value, valuelen, item->command, "D"); + snprintf_dynamic(value, valuelen, item->command, "%s", "D"); return 0; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif /* At this point value should have been already checked against enum so this shouldn't happen.. however.. */ upslogx(LOG_ERR, "%s: given value [%s] is not acceptable. Enter either 'yes' or 'no'.", item->info_type, value); @@ -2502,27 +2454,15 @@ static int voltronic_capability_set_nonut(item_t *item, char *value, const size_ return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif if (!strcasecmp(value, "disabled")) { - snprintf(value, valuelen, item->command, "D"); + snprintf_dynamic(value, valuelen, item->command, "%s", "D"); } else if (!strcasecmp(value, "enabled")) { - snprintf(value, valuelen, item->command, "E"); + snprintf_dynamic(value, valuelen, item->command, "%s", "E"); } else { /* At this point value should have been already checked against enum so this shouldn't happen.. however.. */ upslogx(LOG_ERR, "%s: [%s] is not within acceptable values [enabled/disabled]", item->info_type, value); return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif return 0; } @@ -2574,19 +2514,7 @@ static int voltronic_eco_volt(item_t *item, char *value, const size_t valuelen) return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, strtod(item->value, NULL)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", strtod(item->value, NULL)); outvoltnom = dstate_getinfo("output.voltage.nominal"); @@ -2752,19 +2680,7 @@ static int voltronic_eco_freq(item_t *item, char *value, const size_t valuelen) return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, strtod(item->value, NULL)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", strtod(item->value, NULL)); /* Unskip input.transfer.{high,low} setvar */ unskip = find_nut_info(item->info_type, QX_FLAG_SETVAR, 0); @@ -2812,19 +2728,7 @@ static int voltronic_bypass(item_t *item, char *value, const size_t valuelen) } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, val); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", val); /* No user-provided value to change.. */ if (!getval(item->info_type)) @@ -2861,19 +2765,7 @@ static int voltronic_batt_numb(item_t *item, char *value, const size_t valuelen) return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, (int)battery_number); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%d", (int)battery_number); /* No user-provided value to change.. */ if (!getval(item->info_type)) @@ -2904,19 +2796,7 @@ static int voltronic_batt_runtime(item_t *item, char *value, const size_t valuel /* Battery runtime is reported by the UPS in minutes, NUT expects seconds */ runtime = strtod(item->value, NULL) * 60; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, runtime); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", runtime); return 0; } @@ -2981,19 +2861,7 @@ static int voltronic_fault(item_t *item, char *value, const size_t valuelen) upslogx(LOG_INFO, "Checking for faults.."); if (!strcasecmp(item->value, "OK")) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, "No fault found"); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", "No fault found"); upslogx(LOG_INFO, "%s", value); item->qxflags |= QX_FLAG_SKIP; return 0; @@ -3342,19 +3210,7 @@ static int voltronic_fault(item_t *item, char *value, const size_t valuelen) } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, alarm); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", alarm); upslogx(LOG_INFO, "Fault found: %s", alarm); item->qxflags |= QX_FLAG_SKIP; @@ -3833,23 +3689,11 @@ static int voltronic_mode(item_t *item, char *value, const size_t valuelen) } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif if (alarm && !strcasecmp(item->info_type, "ups.alarm")) { - snprintf(value, valuelen, item->dfl, alarm); + snprintf_dynamic(value, valuelen, item->dfl, "%s", alarm); } else if (status && !strcasecmp(item->info_type, "ups.status")) { - snprintf(value, valuelen, item->dfl, status); + snprintf_dynamic(value, valuelen, item->dfl, "%s", status); } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif return 0; } @@ -4045,19 +3889,7 @@ static int voltronic_output_powerfactor(item_t *item, char *value, const size_t /* UPS report a value expressed in % so -> output.powerfactor*100 e.g. opf = 0,8 -> ups = 80 */ opf = strtod(item->value, NULL) * 0.01; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, opf); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", opf); return 0; } @@ -4071,19 +3903,7 @@ static int voltronic_serial_numb(item_t *item, char *value, const size_t valuele return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, item->value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", item->value); return 0; } @@ -4117,26 +3937,14 @@ static int voltronic_outlet(item_t *item, char *value, const size_t valuelen) } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif if (strstr(item->info_type, "switchable")) { - snprintf(value, valuelen, item->dfl, switchable); + snprintf_dynamic(value, valuelen, item->dfl, "%s", switchable); } else if (strstr(item->info_type, "status")) { - snprintf(value, valuelen, item->dfl, status); + snprintf_dynamic(value, valuelen, item->dfl, "%s", status); } else { /* Don't know what happened */ return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif /* Unskip outlet.n.delay.shutdown */ snprintf(buf, sizeof(buf), "outlet.%c.delay.shutdown", number); @@ -4190,19 +3998,7 @@ static int voltronic_outlet_delay(item_t *item, char *value, const size_t valuel /* UPS reports minutes, NUT expects seconds */ val = strtod(item->value, NULL) * 60; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, val); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%f", val); /* Unskip outlet.n.delay.shutdown setvar */ snprintf(buf, sizeof(buf), "outlet.%c.delay.shutdown", number); @@ -4232,19 +4028,7 @@ static int voltronic_outlet_delay_set(item_t *item, char *value, const size_t va /* From seconds to minute */ delay = delay / 60; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->command, (int)delay); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->command, "%d", (int)delay); return 0; } @@ -4268,19 +4052,7 @@ static int voltronic_p31b(item_t *item, char *value, const size_t valuelen) return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, item->info_rw[(size_t)val].value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", item->info_rw[(size_t)val].value); return 0; } @@ -4330,19 +4102,7 @@ static int voltronic_p31g(item_t *item, char *value, const size_t valuelen) return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, item->info_rw[(size_t)val].value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%s", item->info_rw[(size_t)val].value); work_range_type = val; @@ -4421,19 +4181,7 @@ static int voltronic_phase(item_t *item, char *value, const size_t valuelen) return -1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(value, valuelen, item->dfl, (int)angle); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(value, valuelen, item->dfl, "%d", (int)angle); return 0; } diff --git a/drivers/powerp-bin.c b/drivers/powerp-bin.c index 0c7da014a0..79ab63349b 100644 --- a/drivers/powerp-bin.c +++ b/drivers/powerp-bin.c @@ -35,7 +35,7 @@ #include -#define POWERPANEL_BIN_VERSION "Powerpanel-Binary 0.5" +#define POWERPANEL_BIN_VERSION "Powerpanel-Binary 0.50" typedef struct { unsigned char start; @@ -305,20 +305,8 @@ static int powpan_setvar(const char *varname, const char *val) continue; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(command, sizeof(command), vartab[i].set, - vartab[i].map[type][j].command); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(command, sizeof(command), vartab[i].set, + "%c", vartab[i].map[type][j].command); if ((powpan_command(command, 4) == 3) && (!memcmp(powpan_answer, command, 3))) { dstate_setinfo(varname, "%s", val); diff --git a/drivers/powerp-txt.c b/drivers/powerp-txt.c index 0390a7ca64..5bf80d6a9d 100644 --- a/drivers/powerp-txt.c +++ b/drivers/powerp-txt.c @@ -36,7 +36,7 @@ #include -#define POWERPANEL_TEXT_VERSION "Powerpanel-Text 0.6" +#define POWERPANEL_TEXT_VERSION "Powerpanel-Text 0.60" typedef struct { float i_volt; @@ -207,19 +207,7 @@ static int powpan_setvar(const char *varname, const char *val) return STAT_SET_HANDLED; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(command, sizeof(command), vartab[i].set, atoi(val)); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(command, sizeof(command), vartab[i].set, "%d", atoi(val)); if ((powpan_command(command) == 2) && (!strcasecmp(powpan_answer, "#0"))) { dstate_setinfo(varname, "%s", val); diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index d6e2f6a89b..216ce91011 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -174,7 +174,7 @@ static const char *mibname; static const char *mibvers; #define DRIVER_NAME "Generic SNMP UPS driver" -#define DRIVER_VERSION "1.31" +#define DRIVER_VERSION "1.32" /* driver description structure */ upsdrv_info_t upsdrv_info = { @@ -665,19 +665,7 @@ void upsdrv_initups(void) cur_info_p->OID = (char *)xmalloc(SU_INFOSIZE); snprintf((char*)cur_info_p->info_type, SU_INFOSIZE, "%s", su_info_p->info_type); /* Use the daisychain master (0) / 1rst device index */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf((char*)cur_info_p->OID, SU_INFOSIZE, su_info_p->OID, 0); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic((char*)cur_info_p->OID, SU_INFOSIZE, su_info_p->OID, "%i", 0); } else { upsdebugx(2, "Found entry, not a template %s", su_info_p->OID); @@ -1872,19 +1860,7 @@ static bool_t match_model_OID(void) cur_info_p->OID = (char *)xmalloc(SU_INFOSIZE); snprintf((char*)cur_info_p->info_type, SU_INFOSIZE, "%s", su_info_p->info_type); /* Use the daisychain master (0) / 1rst device index */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf((char*)cur_info_p->OID, SU_INFOSIZE, su_info_p->OID, 0); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic((char*)cur_info_p->OID, SU_INFOSIZE, su_info_p->OID, "%i", 0); } else { upsdebugx(2, "Found entry, not a template %s", su_info_p->OID); @@ -2396,33 +2372,21 @@ static int base_snmp_template_index(const snmp_info_t *su_info_p) { /* not initialised yet */ for (base_index = 0 ; base_index < 2 ; base_index++) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif /* Test if this template also includes daisychain, in which case * we just use the current device index */ if (is_multiple_template(su_info_p->OID) == TRUE) { if (su_info_p->flags & SU_TYPE_DAISY_1) { - snprintf(test_OID, sizeof(test_OID), su_info_p->OID, + snprintf_dynamic(test_OID, sizeof(test_OID), su_info_p->OID, "%i%i", current_device_number + device_template_offset, base_index); } else { - snprintf(test_OID, sizeof(test_OID), su_info_p->OID, + snprintf_dynamic(test_OID, sizeof(test_OID), su_info_p->OID, "%i%i", base_index, current_device_number + device_template_offset); } } else { - snprintf(test_OID, sizeof(test_OID), su_info_p->OID, base_index); + snprintf_dynamic(test_OID, sizeof(test_OID), su_info_p->OID, "%i", base_index); } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif if (nut_snmp_get(test_OID) != NULL) { if (su_info_p->flags & SU_FLAG_ZEROINVALID) { @@ -2479,19 +2443,8 @@ static int guesstimate_template_count(snmp_info_t *su_info_p) } /* Determine if OID index starts from 0 or 1? */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(test_OID, sizeof(test_OID), OID_template, base_index); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(test_OID, sizeof(test_OID), OID_template, "%i", base_index); + if (nut_snmp_get(test_OID) == NULL) { base_index++; } @@ -2506,19 +2459,7 @@ static int guesstimate_template_count(snmp_info_t *su_info_p) /* Now, actually iterate */ for (base_count = 0 ; ; base_count++) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf(test_OID, sizeof(test_OID), OID_template, base_index + base_count); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic(test_OID, sizeof(test_OID), OID_template, "%i", base_index + base_count); if (nut_snmp_get(test_OID) == NULL) break; } @@ -2604,20 +2545,8 @@ static bool_t process_template(int mode, const char* type, snmp_info_t *su_info_ /* Device 1 ("device.0", whole daisychain) needs no * special processing */ cur_nut_index = cur_template_number; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, - su_info_p->info_type, cur_nut_index); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, + su_info_p->info_type, "%i", cur_nut_index); } } else if (!strncmp(type, "outlet", 6)) /* Outlet and outlet groups templates */ @@ -2625,15 +2554,6 @@ static bool_t process_template(int mode, const char* type, snmp_info_t *su_info_ /* Get the index of the current template instance */ cur_nut_index = cur_template_number; -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif /* Special processing for daisychain */ if (daisychain_enabled == TRUE) { /* Device(s) 1-N (master + slave(s)) need to append 'device.x' */ @@ -2643,18 +2563,19 @@ static bool_t process_template(int mode, const char* type, snmp_info_t *su_info_ strcat(&tmp_buf[0], su_info_p->info_type); upsdebugx(4, "FORMATTING STRING = %s", &tmp_buf[0]); - snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, - &tmp_buf[0], current_device_number, cur_nut_index); + snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, + &tmp_buf[0], "%i%i", + current_device_number, cur_nut_index); } else { /* FIXME: daisychain-whole, what to do? */ - snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, - su_info_p->info_type, cur_nut_index); + snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, + su_info_p->info_type, "%i", cur_nut_index); } } else { - snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, - su_info_p->info_type, cur_nut_index); + snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, + su_info_p->info_type, "%i", cur_nut_index); } } else if (!strncmp(type, "ambient", 7)) @@ -2679,18 +2600,19 @@ static bool_t process_template(int mode, const char* type, snmp_info_t *su_info_ strcat(&tmp_buf[0], su_info_p->info_type); upsdebugx(4, "FORMATTING STRING = %s", &tmp_buf[0]); - snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, - &tmp_buf[0], current_device_number, cur_nut_index); + snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, + &tmp_buf[0], "%i%i", + current_device_number, cur_nut_index); } else { /* FIXME: daisychain-whole, what to do? */ - snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, - su_info_p->info_type, cur_nut_index); + snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, + su_info_p->info_type, "%i", cur_nut_index); } } else { - snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, - su_info_p->info_type, cur_nut_index); + snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, + su_info_p->info_type, "%i", cur_nut_index); } } else @@ -2700,14 +2622,14 @@ static bool_t process_template(int mode, const char* type, snmp_info_t *su_info_ if ((cur_info_p.dfl != NULL) && (strstr(su_info_p->dfl, "%i") != NULL)) { cur_info_p.dfl = (char *)xmalloc(SU_INFOSIZE); - snprintf((char *)cur_info_p.dfl, SU_INFOSIZE, su_info_p->dfl, cur_nut_index); + snprintf_dynamic((char *)cur_info_p.dfl, SU_INFOSIZE, su_info_p->dfl, "%i", cur_nut_index); } if (cur_info_p.OID != NULL) { /* Special processing for daisychain */ if (!strncmp(type, "device", 6)) { if (current_device_number > 0) { - snprintf((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, current_device_number + device_template_offset); + snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, "%i", current_device_number + device_template_offset); } /*else * FIXME: daisychain-whole, what to do? @@ -2720,26 +2642,30 @@ static bool_t process_template(int mode, const char* type, snmp_info_t *su_info_ * the formatting info for it are in 1rst or 2nd position */ if (daisychain_enabled == TRUE) { if (su_info_p->flags & SU_TYPE_DAISY_1) { - snprintf((char *)cur_info_p.OID, SU_INFOSIZE, - su_info_p->OID, current_device_number + device_template_offset, cur_template_number); + snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, + su_info_p->OID, "%i%i", + current_device_number + device_template_offset, + cur_template_number); } else if (su_info_p->flags & SU_TYPE_DAISY_2) { - snprintf((char *)cur_info_p.OID, SU_INFOSIZE, - su_info_p->OID, cur_template_number + device_template_offset, + snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, + su_info_p->OID, "%i%i", + cur_template_number + device_template_offset, current_device_number - device_template_offset); } else { /* Note: no device daisychain templating (SU_TYPE_DAISY_MASTER_ONLY)! */ - snprintf((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, cur_template_number); + snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, + su_info_p->OID, "%i", + cur_template_number); } } else { - snprintf((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, cur_template_number); + snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, + su_info_p->OID, "%i", + cur_template_number); } } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif /* add instant commands to the info database. */ if (SU_TYPE(su_info_p) == SU_TYPE_CMD) { @@ -3072,19 +2998,8 @@ static int process_phase_data(const char* type, long *nb_phases, snmp_info_t *su * formatting string) that needs to be adapted! */ if (strchr(tmp_info_p->OID, '%') != NULL) { upsdebugx(2, "Found template, need to be adapted"); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf((char*)tmpOID, SU_INFOSIZE, tmp_info_p->OID, current_device_number + device_template_offset); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic((char*)tmpOID, SU_INFOSIZE, tmp_info_p->OID, + "%i", current_device_number + device_template_offset); } else { /* Otherwise, just point at what we found */ @@ -3428,20 +3343,8 @@ bool_t su_ups_get(snmp_info_t *su_info_p) __func__, tmp_info_p->OID); /* adapt the OID */ if (su_info_p->OID != NULL) { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf((char *)tmp_info_p->OID, SU_INFOSIZE, su_info_p->OID, - current_device_number + device_template_offset); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic((char *)tmp_info_p->OID, SU_INFOSIZE, su_info_p->OID, + "%i", current_device_number + device_template_offset); upsdebugx(3, "%s: OID %s adapted into %s", __func__, su_info_p->OID, tmp_info_p->OID); @@ -3925,20 +3828,8 @@ static int su_setOID(int mode, const char *varname, const char *val) (strstr(tmp_info_p->dfl, "%i") != NULL)) { su_info_p->dfl = (char *)xmalloc(SU_INFOSIZE); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - snprintf((char *)su_info_p->dfl, SU_INFOSIZE, tmp_info_p->dfl, - item_number); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + snprintf_dynamic((char *)su_info_p->dfl, SU_INFOSIZE, tmp_info_p->dfl, + "%i", item_number); } /* adapt the OID */ if (su_info_p->OID != NULL) { @@ -3955,15 +3846,6 @@ static int su_setOID(int mode, const char *varname, const char *val) * these outlet | outlet groups also include formatting info, * so we have to check if the daisychain is enabled, and if * the formatting info for it are in 1rst or 2nd position */ -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif if (daisychain_enabled == TRUE) { /* Note: daisychain_enabled == TRUE means that we have * daisychain template. However: @@ -3978,20 +3860,22 @@ static int su_setOID(int mode, const char *varname, const char *val) daisychain_offset = 1; if (su_info_p->flags & SU_TYPE_DAISY_1) { - snprintf((char *)su_info_p->OID, SU_INFOSIZE, tmp_info_p->OID, - daisychain_device_number - daisychain_offset, item_number); + snprintf_dynamic((char *)su_info_p->OID, SU_INFOSIZE, + tmp_info_p->OID, "%i%i", + daisychain_device_number - daisychain_offset, + item_number); } else { - snprintf((char *)su_info_p->OID, SU_INFOSIZE, tmp_info_p->OID, - item_number, daisychain_device_number - daisychain_offset); + snprintf_dynamic((char *)su_info_p->OID, SU_INFOSIZE, + tmp_info_p->OID, "%i%i", + item_number, + daisychain_device_number - daisychain_offset); } } else { - snprintf((char *)su_info_p->OID, SU_INFOSIZE, tmp_info_p->OID, item_number); + snprintf_dynamic((char *)su_info_p->OID, SU_INFOSIZE, + tmp_info_p->OID, "%i", item_number); } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif } /* else, don't return STAT_SET_INVALID for mode==SU_MODE_SETVAR since we * can be setting a server side variable! */ diff --git a/drivers/usbhid-ups.c b/drivers/usbhid-ups.c index 0b312c92e5..35661359a9 100644 --- a/drivers/usbhid-ups.c +++ b/drivers/usbhid-ups.c @@ -29,7 +29,7 @@ */ #define DRIVER_NAME "Generic HID driver" -#define DRIVER_VERSION "0.54" +#define DRIVER_VERSION "0.55" #define HU_VAR_WAITBEFORERECONNECT "waitbeforereconnect" @@ -2303,19 +2303,7 @@ static int ups_infoval_set(hid_info_t *item, double value) dstate_setinfo(item->info_type, "%s", nutvalue); } else { -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY -#pragma GCC diagnostic ignored "-Wformat-security" -#endif - dstate_setinfo(item->info_type, item->dfl, value); -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL -#pragma GCC diagnostic pop -#endif + dstate_setinfo_dynamic(item->info_type, item->dfl, "%f", value); } return 1;