[PATCH] Reorder calloc arguments

Tobias Stoeckmann tobias at stoeckmann.org
Wed Aug 14 03:06:31 AEST 2024


Reordering calloc arguments silences gcc compiler warnings of
latest versions. Spotted with OpenSSH-portable on a Linux system.

Okay?

Index: cipher.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/cipher.c,v
diff -u -p -u -p -r1.121 cipher.c
--- cipher.c	17 May 2024 02:39:11 -0000	1.121
+++ cipher.c	13 Aug 2024 16:46:00 -0000
@@ -249,7 +249,7 @@ cipher_init(struct sshcipher_ctx **ccp,
 #endif

 	*ccp = NULL;
-	if ((cc = calloc(sizeof(*cc), 1)) == NULL)
+	if ((cc = calloc(1, sizeof(*cc))) == NULL)
 		return SSH_ERR_ALLOC_FAIL;

 	cc->plaintext = (cipher->flags & CFLAG_NONE) != 0;
Index: sshbuf.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sshbuf.c,v
diff -u -p -u -p -r1.19 sshbuf.c
--- sshbuf.c	2 Dec 2022 04:40:27 -0000	1.19
+++ sshbuf.c	13 Aug 2024 16:46:00 -0000
@@ -91,7 +91,7 @@ sshbuf_new(void)
 {
 	struct sshbuf *ret;

-	if ((ret = calloc(sizeof(*ret), 1)) == NULL)
+	if ((ret = calloc(1, sizeof(*ret))) == NULL)
 		return NULL;
 	ret->alloc = SSHBUF_SIZE_INIT;
 	ret->max_size = SSHBUF_SIZE_MAX;
@@ -111,7 +111,7 @@ sshbuf_from(const void *blob, size_t len
 	struct sshbuf *ret;

 	if (blob == NULL || len > SSHBUF_SIZE_MAX ||
-	    (ret = calloc(sizeof(*ret), 1)) == NULL)
+	    (ret = calloc(1, sizeof(*ret))) == NULL)
 		return NULL;
 	ret->alloc = ret->size = ret->max_size = len;
 	ret->readonly = 1;


More information about the openssh-unix-dev mailing list