From: Florian Forster Date: Thu, 18 Jun 2015 13:27:54 +0000 (+0200) Subject: Fix "Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131)" warnings. X-Git-Tag: collectd-5.5.1~98^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4b396ba5395402488a8fddacd361836a6b5afdd5;p=collectd.git Fix "Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131)" warnings. --- diff --git a/src/snmp.c b/src/snmp.c index 3dd08e4a..4dd1d10c 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1241,6 +1241,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) data->type, ds->ds_num, data->values_len); return (-1); } + assert (data->values_len > 0); /* We need a copy of all the OIDs, because GETNEXT will destroy them. */ memcpy (oid_list, data->values, data->values_len * sizeof (oid_t)); diff --git a/src/utils_db_query.c b/src/utils_db_query.c index ab4299b3..e8d7b3aa 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -192,8 +192,9 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ assert (r != NULL); assert (r_area->ds != NULL); assert (((size_t) r_area->ds->ds_num) == r->values_num); + assert (r->values_num > 0); - vl.values = (value_t *) calloc (r_area->ds->ds_num, sizeof (value_t)); + vl.values = (value_t *) calloc (r->values_num, sizeof (value_t)); if (vl.values == NULL) { ERROR ("db query utils: malloc failed.");