[monitoring-plugins] Fix argument order of calloc on several occasions

Lorenz Kästle git at monitoring-plugins.org
Sat Nov 9 11:40:12 CET 2024


 Module: monitoring-plugins
 Branch: master
 Commit: 6eb5be9e30b23035632b674f6b46c18313cde63b
 Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
   Date: Sat Nov  9 10:49:21 2024 +0100
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=6eb5be9

Fix argument order of calloc on several occasions

---

 lib/utils_cmd.c     | 2 +-
 plugins/check_tcp.c | 2 +-
 plugins/runcmd.c    | 2 +-
 plugins/utils.c     | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index 416cf82..18350ac 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -290,7 +290,7 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) {
 	/* each arg must be whitespace-separated, so args can be a maximum
 	 * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */
 	argc = (cmdlen >> 1) + 2;
-	argv = calloc(sizeof(char *), argc);
+	argv = calloc((size_t)argc, sizeof(char *));
 
 	if (argv == NULL) {
 		printf("%s\n", _("Could not malloc argv array in popen()"));
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index c13ac76..49ad096 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -119,7 +119,7 @@ int main(int argc, char **argv) {
 
 	/* set up a reasonable buffer at first (will be realloc()'ed if
 	 * user specifies other options) */
-	server_expect = calloc(sizeof(char *), 2);
+	server_expect = calloc(2, sizeof(char *));
 
 	/* determine defaults for this service's protocol */
 	if (!strncmp(SERVICE, "UDP", 3)) {
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 2e53dc0..7484314 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -130,7 +130,7 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) {
 	/* each arg must be whitespace-separated, so args can be a maximum
 	 * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */
 	argc = (cmdlen >> 1) + 2;
-	argv = calloc(sizeof(char *), argc);
+	argv = calloc(argc, sizeof(char *));
 
 	if (argv == NULL) {
 		printf("%s\n", _("Could not malloc argv array in popen()"));
diff --git a/plugins/utils.c b/plugins/utils.c
index f11db73..6d366e3 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -185,7 +185,7 @@ bool is_percentage_expression(const char str[]) {
 		return false;
 	}
 
-	char *foo = calloc(sizeof(char), len + 1);
+	char *foo = calloc(len + 1, sizeof(char));
 
 	if (!foo) {
 		die(STATE_UNKNOWN, _("calloc failed \n"));



More information about the Commits mailing list