From: Jeremy Sowden <jeremy@azazel.net>
To: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: [ulogd2 PATCH 11/26] Replace malloc+memset with calloc
Date: Sat, 30 Oct 2021 17:44:17 +0100 [thread overview]
Message-ID: <20211030164432.1140896-12-jeremy@azazel.net> (raw)
In-Reply-To: <20211030164432.1140896-1-jeremy@azazel.net>
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
output/dbi/ulogd_output_DBI.c | 6 +-----
output/ipfix/ipfix.c | 4 +---
output/mysql/ulogd_output_MYSQL.c | 6 +-----
output/pgsql/ulogd_output_PGSQL.c | 6 +-----
src/ulogd.c | 3 +--
5 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/output/dbi/ulogd_output_DBI.c b/output/dbi/ulogd_output_DBI.c
index d2a968293314..23cc9c8fb492 100644
--- a/output/dbi/ulogd_output_DBI.c
+++ b/output/dbi/ulogd_output_DBI.c
@@ -129,8 +129,7 @@ static int get_columns_dbi(struct ulogd_pluginstance *upi)
upi->input.num_keys = dbi_result_get_numfields(pi->result);
ulogd_log(ULOGD_DEBUG, "%u fields in table\n", upi->input.num_keys);
- upi->input.keys = malloc(sizeof(struct ulogd_key) *
- upi->input.num_keys);
+ upi->input.keys = calloc(upi->input.num_keys, sizeof(*upi->input.keys));
if (!upi->input.keys) {
upi->input.num_keys = 0;
ulogd_log(ULOGD_ERROR, "ENOMEM\n");
@@ -138,9 +137,6 @@ static int get_columns_dbi(struct ulogd_pluginstance *upi)
return -ENOMEM;
}
- memset(upi->input.keys, 0, sizeof(struct ulogd_key) *
- upi->input.num_keys);
-
for (ui=1; ui<=upi->input.num_keys; ui++) {
char buf[ULOGD_MAX_KEYLEN+1];
char *underscore;
diff --git a/output/ipfix/ipfix.c b/output/ipfix/ipfix.c
index 4bb432a73d14..b2719fd1d8a3 100644
--- a/output/ipfix/ipfix.c
+++ b/output/ipfix/ipfix.c
@@ -85,8 +85,7 @@ struct ipfix_msg *ipfix_msg_alloc(size_t len, uint32_t oid, int tid)
(len < IPFIX_HDRLEN + IPFIX_SET_HDRLEN))
return NULL;
- msg = malloc(sizeof(struct ipfix_msg) + len);
- memset(msg, 0, sizeof(struct ipfix_msg));
+ msg = calloc(1, sizeof(struct ipfix_msg) + len);
msg->tid = tid;
msg->end = msg->data + len;
msg->tail = msg->data + IPFIX_HDRLEN;
@@ -95,7 +94,6 @@ struct ipfix_msg *ipfix_msg_alloc(size_t len, uint32_t oid, int tid)
/* Initialize message header */
hdr = ipfix_msg_hdr(msg);
- memset(hdr, 0, IPFIX_HDRLEN);
hdr->version = htons(IPFIX_VERSION);
hdr->oid = htonl(oid);
diff --git a/output/mysql/ulogd_output_MYSQL.c b/output/mysql/ulogd_output_MYSQL.c
index 643320ce724c..66151feb4939 100644
--- a/output/mysql/ulogd_output_MYSQL.c
+++ b/output/mysql/ulogd_output_MYSQL.c
@@ -127,16 +127,12 @@ static int get_columns_mysql(struct ulogd_pluginstance *upi)
upi->input.num_keys = mysql_num_fields(result);
ulogd_log(ULOGD_DEBUG, "%u fields in table\n", upi->input.num_keys);
- upi->input.keys = malloc(sizeof(struct ulogd_key) *
- upi->input.num_keys);
+ upi->input.keys = calloc(upi->input.num_keys, sizeof(*upi->input.keys));
if (!upi->input.keys) {
upi->input.num_keys = 0;
ulogd_log(ULOGD_ERROR, "ENOMEM\n");
return -ENOMEM;
}
-
- memset(upi->input.keys, 0, sizeof(struct ulogd_key) *
- upi->input.num_keys);
for (i = 0; (field = mysql_fetch_field(result)); i++) {
char buf[ULOGD_MAX_KEYLEN+1];
diff --git a/output/pgsql/ulogd_output_PGSQL.c b/output/pgsql/ulogd_output_PGSQL.c
index fda289eca776..f5a2823a7e1d 100644
--- a/output/pgsql/ulogd_output_PGSQL.c
+++ b/output/pgsql/ulogd_output_PGSQL.c
@@ -181,8 +181,7 @@ static int get_columns_pgsql(struct ulogd_pluginstance *upi)
upi->input.num_keys = PQntuples(pi->pgres);
ulogd_log(ULOGD_DEBUG, "%u fields in table\n", upi->input.num_keys);
- upi->input.keys = malloc(sizeof(struct ulogd_key) *
- upi->input.num_keys);
+ upi->input.keys = calloc(upi->input.num_keys, sizeof(*upi->input.keys));
if (!upi->input.keys) {
upi->input.num_keys = 0;
ulogd_log(ULOGD_ERROR, "ENOMEM\n");
@@ -190,9 +189,6 @@ static int get_columns_pgsql(struct ulogd_pluginstance *upi)
return -ENOMEM;
}
- memset(upi->input.keys, 0, sizeof(struct ulogd_key) *
- upi->input.num_keys);
-
for (i = 0; i < PQntuples(pi->pgres); i++) {
char buf[ULOGD_MAX_KEYLEN+1];
char *underscore;
diff --git a/src/ulogd.c b/src/ulogd.c
index 97da4fc0018f..b02f2602a895 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -661,12 +661,11 @@ pluginstance_alloc_init(struct ulogd_plugin *pl, char *pi_id,
}
size += pl->input.num_keys * sizeof(struct ulogd_key);
size += pl->output.num_keys * sizeof(struct ulogd_key);
- pi = malloc(size);
+ pi = calloc(1, size);
if (!pi)
return NULL;
/* initialize */
- memset(pi, 0, size);
INIT_LLIST_HEAD(&pi->list);
INIT_LLIST_HEAD(&pi->plist);
pi->plugin = pl;
--
2.33.0
next prev parent reply other threads:[~2021-10-30 17:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-30 16:44 [ulogd2 PATCH 00/26] Compiler Warning Fixes Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 01/26] include: add format attribute to __ulogd_log declaration Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 02/26] ulog: remove empty log-line Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 03/26] ulog: fix order of log arguments Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 04/26] ulog: correct log specifiers Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 05/26] output: IPFIX: correct format-specifiers Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 06/26] jhash: add "fall through" comments to switch cases Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 07/26] db: add missing `break` to switch-case Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 08/26] filter: HWHDR: replace `switch` with `if` Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 09/26] filter: HWHDR: re-order KEY_RAW_MAC checks Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 10/26] filter: HWHDR: remove zero-initialization of MAC type Jeremy Sowden
2021-10-30 16:44 ` Jeremy Sowden [this message]
2021-10-30 16:44 ` [ulogd2 PATCH 12/26] filter: PWSNIFF: replace malloc+strncpy with strndup Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 13/26] input: UNIXSOCK: stat socket-path first before creating the socket Jeremy Sowden
2021-10-30 17:33 ` Jan Engelhardt
2021-11-06 13:51 ` Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 14/26] input: UNIXSOCK: fix possible truncation of socket path Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 15/26] input: UNIXSOCK: prevent unaligned pointer access Jeremy Sowden
2021-10-30 17:42 ` Jan Engelhardt
2021-11-06 14:13 ` Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 16/26] output: DBI: fix deprecation warnings Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 17/26] output: DBI: fix string truncation warnings Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 18/26] output: MYSQL: Fix string truncation warning Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 19/26] output: PGSQL: " Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 20/26] output: SQLITE3: Fix string truncation warnings and possible buffer overruns Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 21/26] output: SQLITE3: catch errors creating SQL statement Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 22/26] util: db: fix possible string truncation Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 23/26] output: JSON: fix output of GMT offset Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 24/26] output: JSON: fix printf truncation warnings Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 25/26] output: JSON: optimize appending of newline to output Jeremy Sowden
2021-10-30 16:44 ` [ulogd2 PATCH 26/26] output: JSON: fix possible truncation of socket path Jeremy Sowden
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211030164432.1140896-12-jeremy@azazel.net \
--to=jeremy@azazel.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).