From 07f9c438f31de7a280e43c4196a32d200ad41fbe Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:10:55 +0200 Subject: Fixes for -Wsign-compare --- plugins/check_snmp.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'plugins/check_snmp.c') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 405ede3a..01bee231 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -131,7 +131,7 @@ size_t nlabels = 0; size_t labels_size = OID_COUNT_STEP; size_t nunits = 0; size_t unitv_size = OID_COUNT_STEP; -int numoids = 0; +size_t numoids = 0; int numauthpriv = 0; int numcontext = 0; int verbose = 0; @@ -187,7 +187,8 @@ static char *fix_snmp_range(char *th) int main (int argc, char **argv) { - int i, len, line, total_oids; + int len, total_oids; + size_t line; unsigned int bk_count = 0, dq_count = 0; int iresult = STATE_UNKNOWN; int result = STATE_UNKNOWN; @@ -253,7 +254,9 @@ main (int argc, char **argv) if(calculate_rate) { if (!strcmp(label, "SNMP")) label = strdup("SNMP RATE"); - i=0; + + size_t i = 0; + previous_state = np_state_read(); if(previous_state!=NULL) { /* Split colon separated values */ @@ -273,7 +276,7 @@ main (int argc, char **argv) /* Populate the thresholds */ th_warn=warning_thresholds; th_crit=critical_thresholds; - for (i=0; i 0) { printf (_("External command error: %s\n"), chld_err.line[0]); - for (i = 1; i < chld_err.lines; i++) { + for (size_t i = 1; i < chld_err.lines; i++) { printf ("%s\n", chld_err.line[i]); } } else { @@ -392,12 +395,14 @@ main (int argc, char **argv) } if (verbose) { - for (i = 0; i < chld_out.lines; i++) { + for (size_t i = 0; i < chld_out.lines; i++) { printf ("%s\n", chld_out.line[i]); } } - for (line=0, i=0; line < chld_out.lines && i < numoids ; line++, i++) { + line = 0; + total_oids = 0; + for (size_t i = 0; line < chld_out.lines && i < numoids ; line++, i++, total_oids++) { if(calculate_rate) conv = "%.10g"; else @@ -634,7 +639,6 @@ main (int argc, char **argv) strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); } } - total_oids=i; /* Save state data, as all data collected now */ if(calculate_rate) { @@ -644,7 +648,7 @@ main (int argc, char **argv) die(STATE_UNKNOWN, _("Cannot malloc")); current_length=0; - for(i=0; i Date: Thu, 19 Oct 2023 12:20:27 +0200 Subject: Fix fallout of the previous changes --- plugins/check_apt.c | 2 +- plugins/check_http.c | 2 +- plugins/check_snmp.c | 4 ++-- plugins/check_tcp.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'plugins/check_snmp.c') diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 290c88ed..5c0f6e28 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -252,7 +252,7 @@ int process_arguments (int argc, char **argv) { /* run an apt-get upgrade */ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){ - int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0; + int result=STATE_UNKNOWN, regres=0, pc=0, spc=0; struct output chld_out, chld_err; regex_t ireg, ereg, sreg; char *cmdline=NULL, rerrbuf[64]; diff --git a/plugins/check_http.c b/plugins/check_http.c index b9d8145c..110f1188 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -471,7 +471,7 @@ bool process_arguments (int argc, char **argv) free(http_method); http_method = strdup (optarg); char *tmp; - if ((tmp = strstr(http_method, ":")) > 0) { + if ((tmp = strstr(http_method, ":")) != NULL) { tmp[0] = '\0'; http_method = http_method; http_method_proxy = ++tmp; diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 01bee231..7ee9d0ca 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -263,7 +263,7 @@ main (int argc, char **argv) previous_string = strdup((char *) previous_state->data); while((ap = strsep(&previous_string, ":")) != NULL) { if(verbose>2) - printf("State for %d=%s\n", i, ap); + printf("State for %zd=%s\n", i, ap); while (i >= previous_size) { previous_size += OID_COUNT_STEP; previous_value = realloc(previous_value, previous_size * sizeof(*previous_value)); @@ -415,7 +415,7 @@ main (int argc, char **argv) break; if (verbose > 2) { - printf("Processing oid %i (line %i)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response); + printf("Processing oid %zi (line %zi)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response); } /* Clean up type array - Sol10 does not necessarily zero it out */ diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index c103612a..054f1a39 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c @@ -275,7 +275,7 @@ main (int argc, char **argv) } printf("server_expect_count: %d\n", (int)server_expect_count); for(size_t i = 0; i < server_expect_count; i++) - printf("\t%d: %s\n", i, server_expect[i]); + printf("\t%zd: %s\n", i, server_expect[i]); } /* if(len) later on, we know we have a non-NULL response */ -- cgit v1.2.3-74-g34f1