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