[master] 6f0d0e3 Put the calloc(3) arguments in the right order

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Sep 11 22:34:04 UTC 2017


commit 6f0d0e3582dbd49635609357e548cc78ef6e498c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Sep 12 00:21:03 2017 +0200

    Put the calloc(3) arguments in the right order
    
    This is mostly a mechanical patch.

diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 8da85ae..79d5e41 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -150,7 +150,7 @@ vca_tcp_opt_init(void)
 	for (n = 0; n < n_tcp_opts; n++) {
 		to = &tcp_opts[n];
 		if (to->ptr == NULL)
-			to->ptr = calloc(to->sz, 1);
+			to->ptr = calloc(1, to->sz);
 		AN(to->ptr);
 		if (!strcmp(to->strname, "SO_LINGER")) {
 			assert(to->sz == sizeof linger);
@@ -212,7 +212,7 @@ vca_tcp_opt_test(int sock)
 	for (n = 0; n < n_tcp_opts; n++) {
 		to = &tcp_opts[n];
 		to->need = 1;
-		ptr = calloc(to->sz, 1);
+		ptr = calloc(1, to->sz);
 		AN(ptr);
 		l = to->sz;
 		i = getsockopt(sock, to->level, to->optname, ptr, &l);
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index 0e05bcc..160d1da 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -78,7 +78,7 @@ mpl_alloc(const struct mempool *mpl)
 
 	CHECK_OBJ_NOTNULL(mpl, MEMPOOL_MAGIC);
 	tsz = *mpl->cur_size;
-	mi = calloc(tsz, 1);
+	mi = calloc(1, tsz);
 	AN(mi);
 	mi->magic = MEMITEM_MAGIC;
 	mi->size = tsz;
diff --git a/bin/varnishd/hash/hash_classic.c b/bin/varnishd/hash/hash_classic.c
index e89e411..87db657 100644
--- a/bin/varnishd/hash/hash_classic.c
+++ b/bin/varnishd/hash/hash_classic.c
@@ -93,7 +93,7 @@ hcl_start(void)
 	unsigned u;
 
 	lck_hcl = Lck_CreateClass("hcl");
-	hcl_head = calloc(sizeof *hcl_head, hcl_nhash);
+	hcl_head = calloc(hcl_nhash, sizeof *hcl_head);
 	XXXAN(hcl_head);
 
 	for (u = 0; u < hcl_nhash; u++) {
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index 1a51afe..417c97e 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -596,8 +596,8 @@ main(int argc, char **argv)
 
 	hist_range = hist_high - hist_low;
 	hist_buckets = hist_range * HIST_RES;
-	bucket_hit = calloc(sizeof *bucket_hit, hist_buckets);
-	bucket_miss = calloc(sizeof *bucket_miss, hist_buckets);
+	bucket_hit = calloc(hist_buckets, sizeof *bucket_hit);
+	bucket_miss = calloc(hist_buckets, sizeof *bucket_miss);
 
 	if (timebend > 0)
 		t0 = VTIM_mono();
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 7645faa..c65139b 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -745,7 +745,7 @@ cmd_http_gunzip(CMD_ARGS)
 	vz.avail_in = hp->bodyl;
 
 	l = hp->bodyl * 10;
-	p = calloc(l, 1);
+	p = calloc(1, l);
 	AN(p);
 
 	vz.next_out = TRUST_ME(p);
@@ -790,7 +790,7 @@ gzip_body(const struct http *hp, const char *txt, char **body, int *bodylen)
 	memset(&vz, 0, sizeof vz);
 
 	l = strlen(txt);
-	*body = calloc(l + OVERHEAD, 1);
+	*body = calloc(1, l + OVERHEAD);
 	AN(*body);
 
 	vz.next_in = TRUST_ME(txt);
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 07386ed..39600ce 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -158,7 +158,7 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 				VRB_INSERT(t_order, &h_order, tp);
 			} else {
 				ntop++;
-				tp = calloc(sizeof *tp, 1);
+				tp = calloc(1, sizeof *tp);
 				assert(tp != NULL);
 				tp->hash = u;
 				tp->count = 1.0;
diff --git a/doc/sphinx/reference/vmod.rst b/doc/sphinx/reference/vmod.rst
index 910d613..3b63f56 100644
--- a/doc/sphinx/reference/vmod.rst
+++ b/doc/sphinx/reference/vmod.rst
@@ -386,7 +386,7 @@ In the common case where a private data structure is allocated with
 malloc would look like this::
 
 	if (priv->priv == NULL) {
-		priv->priv = calloc(sizeof(struct myfoo), 1);
+		priv->priv = calloc(1, sizeof(struct myfoo));
 		AN(priv->priv);
 		priv->free = free;	/* free(3) */
 		mystate = priv->priv;
diff --git a/include/miniobj.h b/include/miniobj.h
index 13aa3a6..b714c70 100644
--- a/include/miniobj.h
+++ b/include/miniobj.h
@@ -19,7 +19,7 @@
 
 #define ALLOC_OBJ(to, type_magic)					\
 	do {								\
-		(to) = calloc(sizeof *(to), 1);				\
+		(to) = calloc(1, sizeof *(to));				\
 		if ((to) != NULL)					\
 			(to)->magic = (type_magic);			\
 	} while (0)
diff --git a/include/vbm.h b/include/vbm.h
index f56447d..9dcc3d0 100644
--- a/include/vbm.h
+++ b/include/vbm.h
@@ -121,7 +121,7 @@ vbit_new(unsigned initial)
 {
 	struct vbitmap *vb;
 
-	vb = calloc(sizeof *vb, 1);
+	vb = calloc(1, sizeof *vb);
 	assert(vb != NULL);
 	vb->flags |= VBITMAP_FL_MALLOC;
 	if (initial == 0)
diff --git a/lib/libvarnish/binary_heap.c b/lib/libvarnish/binary_heap.c
index e3bd2eb..9799276 100644
--- a/lib/libvarnish/binary_heap.c
+++ b/lib/libvarnish/binary_heap.c
@@ -207,7 +207,7 @@ binheap_new(void *priv, binheap_cmp_t *cmp_f, binheap_update_t *update_f)
 	struct binheap *bh;
 	unsigned u;
 
-	bh = calloc(sizeof *bh, 1);
+	bh = calloc(1, sizeof *bh);
 	if (bh == NULL)
 		return (bh);
 	bh->priv = priv;
@@ -224,7 +224,7 @@ binheap_new(void *priv, binheap_cmp_t *cmp_f, binheap_update_t *update_f)
 	bh->update = update_f;
 	bh->next = ROOT_IDX;
 	bh->rows = 16;		/* A tiny-ish number */
-	bh->array = calloc(sizeof *bh->array, bh->rows);
+	bh->array = calloc(bh->rows, sizeof *bh->array);
 	assert(bh->array != NULL);
 	binheap_addrow(bh);
 	A(bh, ROOT_IDX) = NULL;
diff --git a/lib/libvarnish/vav.c b/lib/libvarnish/vav.c
index 51a7ef6..4c4a779 100644
--- a/lib/libvarnish/vav.c
+++ b/lib/libvarnish/vav.c
@@ -112,7 +112,7 @@ VAV_BackSlashDecode(const char *s, const char *e)
 	if (e == NULL)
 		e = strchr(s, '\0');
 	assert(e != NULL);
-	p = calloc((e - s) + 1L, 1);
+	p = calloc(1, (e - s) + 1L);
 	if (p == NULL)
 		return (p);
 	for (r = p, q = s; q < e; ) {
@@ -142,7 +142,7 @@ VAV_Parse(const char *s, int *argc, int flag)
 	assert(s != NULL);
 	nargv = 1;
 	largv = 16;
-	argv = calloc(sizeof *argv, largv);
+	argv = calloc(largv, sizeof *argv);
 	if (argv == NULL)
 		return (NULL);
 
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index 7c8011f..88f7057 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -156,7 +156,7 @@ vev_get_sig(int sig)
 	if (sig < vev_nsig)
 		return (0);
 
-	os = calloc(sizeof *os, (sig + 1L));
+	os = calloc((sig + 1L), sizeof *os);
 	if (os == NULL)
 		return (ENOMEM);
 
@@ -192,7 +192,7 @@ vev_new_base(void)
 {
 	struct vev_base *evb;
 
-	evb = calloc(sizeof *evb, 1);
+	evb = calloc(1, sizeof *evb);
 	if (evb == NULL)
 		return (evb);
 	evb->lpfd = BINHEAP_NOIDX + 1;
@@ -230,7 +230,7 @@ vev_new(void)
 {
 	struct vev *e;
 
-	e = calloc(sizeof *e, 1);
+	e = calloc(1, sizeof *e);
 	if (e != NULL) {
 		e->fd = -1;
 	}
diff --git a/lib/libvarnish/vfil.c b/lib/libvarnish/vfil.c
index 6df5af6..64f3c56 100644
--- a/lib/libvarnish/vfil.c
+++ b/lib/libvarnish/vfil.c
@@ -275,7 +275,7 @@ VFIL_allocate(int fd, off_t size, int insist)
 		bufsiz = 64 * 1024;
 	else
 		bufsiz = size;
-	buf = calloc(bufsiz, 1);
+	buf = calloc(1, bufsiz);
 	AN(buf);
 	assert(lseek(fd, 0, SEEK_SET) == 0);
 	for (l = 0; l < size; l += l2) {
diff --git a/lib/libvarnishapi/vxp.c b/lib/libvarnishapi/vxp.c
index ae86282..039fafe 100644
--- a/lib/libvarnishapi/vxp.c
+++ b/lib/libvarnishapi/vxp.c
@@ -143,7 +143,7 @@ vxp_DoFree(struct vxp *vxp, void *p)
 {
 	struct membit *mb;
 
-	mb = calloc(sizeof *mb, 1);
+	mb = calloc(1, sizeof *mb);
 	AN(mb);
 	mb->ptr = p;
 	VTAILQ_INSERT_TAIL(&vxp->membits, mb, list);
@@ -154,7 +154,7 @@ vxp_Alloc(struct vxp *vxp, unsigned len)
 {
 	void *p;
 
-	p = calloc(len, 1);
+	p = calloc(1, len);
 	AN(p);
 	vxp_DoFree(vxp, p);
 	return (p);
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index a8d0352..468a4c5 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -77,7 +77,7 @@ TlAlloc(struct vcc *tl, unsigned len)
 	void *p;
 
 	(void)tl;
-	p = calloc(len, 1);
+	p = calloc(1, len);
 	assert(p != NULL);
 	return (p);
 }
@@ -418,7 +418,7 @@ vcc_new_source(const char *b, const char *e, const char *name)
 
 	if (e == NULL)
 		e = strchr(b, '\0');
-	sp = calloc(sizeof *sp, 1);
+	sp = calloc(1, sizeof *sp);
 	assert(sp != NULL);
 	sp->name = strdup(name);
 	AN(sp->name);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 5aa28a7..52159cb 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -608,7 +608,7 @@ vcc_func(struct vcc *tl, struct expr **e, const char *spec,
 	AN(rfmt);
 	VTAILQ_INIT(&head);
 	while (*p != '\0') {
-		fa = calloc(sizeof *fa, 1);
+		fa = calloc(1, sizeof *fa);
 		AN(fa);
 		VTAILQ_INSERT_TAIL(&head, fa, list);
 		if (!memcmp(p, "PRIV_", 5)) {


More information about the varnish-commit mailing list