Skip to contentSkip to conversation

src: reverse calloc() invocation

PATCH New Pablo Neira Ayuso 1 participant 1 message Sep 29, 2023 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 src: reverse calloc() invocation

Swap object size and number of elements, so number of elements is the first argument, then object size is the second argument.

---
 src/conntrack/api.c    | 6 +++---
 src/conntrack/labels.c | 2 +-
 src/conntrack/stack.c  | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
src/conntrack/api.c +3 -3
index d27bad2703d3..cd8bea8d2bb3 100644
@@ -307,7 +307,7 @@ int nfct_callback_register2(struct nfct_handle *h,
 
 	assert(h != NULL);
 
-	container = calloc(sizeof(struct __data_container), 1);
+	container = calloc(1, sizeof(struct __data_container));
 	if (container == NULL)
 		return -1;
 
@@ -1361,7 +1361,7 @@ void nfct_copy_attr(struct nf_conntrack *ct1,
  */
 struct nfct_filter *nfct_filter_create(void)
 {
-	return calloc(sizeof(struct nfct_filter), 1);
+	return calloc(1, sizeof(struct nfct_filter));
 }
 
 /**
@@ -1500,7 +1500,7 @@ int nfct_filter_detach(int fd)
  */
 struct nfct_filter_dump *nfct_filter_dump_create(void)
 {
-	return calloc(sizeof(struct nfct_filter_dump), 1);
+	return calloc(1, sizeof(struct nfct_filter_dump));
 }
 
 /**
src/conntrack/labels.c +1 -1
index ef85b6e26cb3..5f5019474ca1 100644
@@ -268,7 +268,7 @@ struct nfct_labelmap *__labelmap_new(const char *name)
 
 	if (added) {
 		map->namecount = maxbit + 1;
-		map->bit_to_name = calloc(sizeof(char *), map->namecount);
+		map->bit_to_name = calloc(map->namecount, sizeof(char *));
 		if (!map->bit_to_name)
 			goto err;
 		make_name_table(map);
src/conntrack/stack.c +2 -2
index ac3f437375d5..66ccf1f9a03d 100644
@@ -25,11 +25,11 @@ struct stack *stack_create(size_t elem_size, int max_elems)
 {
 	struct stack *s;
 
-	s = calloc(sizeof(struct stack), 1);
+	s = calloc(1, sizeof(struct stack));
 	if (s == NULL)
 		return NULL;
 
-	s->data = calloc(elem_size * max_elems, 1);
+	s->data = calloc(max_elems, elem_size);
 	if (s->data == NULL) {
 		free(s);
 		return NULL;
Signature · 1 line
2.30.2