From a00c412e7ba1474b32f478daf039d2bdf71f072a Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:59:23 +0100 Subject: Fixes for -Wnonnull-compare diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 8b8e570..34fb390 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -118,10 +118,6 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) int i = 0; - /* if no command was passed, return with no error */ - if (argv == NULL) - return -1; - if (!_cmd_pids) CMD_INIT; diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 1bd2ca1..ff1987f 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c @@ -114,10 +114,6 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) env[0] = strdup("LC_ALL=C"); env[1] = '\0'; - /* if no command was passed, return with no error */ - if (cmdstring == NULL) - return -1; - /* make copy of command string so strtok() doesn't silently modify it */ /* (the calling program may want to access it later) */ cmdlen = strlen(cmdstring); -- cgit v0.10-9-g596f From 6d341c40ab4d84d5eabfd672de1ffa3c7ecd07be Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:04:25 +0100 Subject: Fixes for Waddress * check_snmp: Fix string comparison diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index c425df3..425bb7b 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -422,7 +422,8 @@ main (int argc, char **argv) } else if (strstr (response, "INTEGER: ")) { show = multiply (strstr (response, "INTEGER: ") + 9); - if (fmtstr != "") { + + if (strcmp(fmtstr, "") != 0) { conv = fmtstr; } } @@ -596,8 +597,9 @@ main (int argc, char **argv) len = sizeof(perfstr)-strlen(perfstr)-1; strncat(perfstr, show, len>ptr-show ? ptr-show : len); - if (type) + if (strcmp(type, "") != 0) { strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); + } if (warning_thresholds) { strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); @@ -1185,7 +1187,7 @@ multiply (char *str) if(verbose>2) printf(" multiply extracted double: %f\n", val); val *= multiplier; - if (fmtstr != "") { + if (strcmp(fmtstr, "") != 0) { conv = fmtstr; } if (val == (int)val) { -- cgit v0.10-9-g596f From 068c124f361d4c615aed79f6fe607f39040b2e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Tue, 11 Jul 2023 16:39:29 +0200 Subject: Detect if fmtstr was set in edge cases diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 425bb7b..135bbc7 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -158,6 +158,7 @@ int perf_labels = 1; char* ip_version = ""; double multiplier = 1.0; char *fmtstr = ""; +bool fmtstr_set = false; char buffer[DEFAULT_BUFFER_SIZE]; static char *fix_snmp_range(char *th) @@ -423,7 +424,7 @@ main (int argc, char **argv) else if (strstr (response, "INTEGER: ")) { show = multiply (strstr (response, "INTEGER: ") + 9); - if (strcmp(fmtstr, "") != 0) { + if (fmtstr_set) { conv = fmtstr; } } @@ -973,6 +974,7 @@ process_arguments (int argc, char **argv) case 'f': if (multiplier != 1.0) { fmtstr=optarg; + fmtstr_set = true; } break; } @@ -1187,7 +1189,7 @@ multiply (char *str) if(verbose>2) printf(" multiply extracted double: %f\n", val); val *= multiplier; - if (strcmp(fmtstr, "") != 0) { + if (fmtstr_set) { conv = fmtstr; } if (val == (int)val) { -- cgit v0.10-9-g596f