Skip to content

Commit 8af5e4a

Browse files
author
Lorenz Kästle
committed
Fix off-by-one error
1 parent 79b3023 commit 8af5e4a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

snmp_bulkget.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,15 @@ int create_request(netsnmp_session *snmp_session, struct OIDStruct **OIDpp, char
415415
struct OIDStruct *OIDp;
416416

417417
/* store all the parsed OIDs in a structure for easy comparison */
418-
int last_index = 0;
418+
size_t number_of_oids = 0;
419419
for (int i = 0; oid_list[i]; i++) {
420-
last_index = i;
420+
number_of_oids = i + 1;
421421
}
422-
OIDp = (struct OIDStruct *)calloc(last_index, sizeof(*OIDp));
422+
OIDp = (struct OIDStruct *)calloc(number_of_oids, sizeof(*OIDp));
423423

424424
/* here we are retrieving single values, not walking the table */
425425
pdu = snmp_pdu_create(SNMP_MSG_GET);
426426

427-
last_index = 0;
428427
for (int i = 0; oid_list[i]; i++) {
429428
#ifdef DEBUG2
430429
fprintf(stderr, "%d: adding %s\n", i, oid_list[i]);
@@ -434,7 +433,7 @@ int create_request(netsnmp_session *snmp_session, struct OIDStruct **OIDpp, char
434433
OIDp[i].name[OIDp[i].name_len++] = index;
435434
snmp_add_null_var(pdu, OIDp[i].name, OIDp[i].name_len);
436435
}
437-
pdu->non_repeaters = last_index;
436+
pdu->non_repeaters = number_of_oids;
438437
pdu->max_repetitions = 0;
439438

440439
*OIDpp = OIDp;

0 commit comments

Comments
 (0)