CLEANUP: uniformize last argument of malloc/calloc
Instead of repeating the type of the LHS argument (sizeof(struct ...))
in calls to malloc/calloc, we directly use the pointer
name (sizeof(*...)). The following Coccinelle patch was used:
@@
type T;
T *x;
@@
x = malloc(
- sizeof(T)
+ sizeof(*x)
)
@@
type T;
T *x;
@@
x = calloc(1,
- sizeof(T)
+ sizeof(*x)
)
When the LHS is not just a variable name, no change is made. Moreover,
the following patch was used to ensure that "1" is consistently used as
a first argument of calloc, not the last one:
@@
@@
calloc(
+ 1,
...
- ,1
)
diff --git a/src/compression.c b/src/compression.c
index 7b5a939..8d09585 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -109,7 +109,7 @@
{
struct comp_type *comp_type;
- comp_type = calloc(1, sizeof(struct comp_type));
+ comp_type = calloc(1, sizeof(*comp_type));
comp_type->name_len = strlen(type);
comp_type->name = strdup(type);
comp_type->next = comp->types;
@@ -127,7 +127,7 @@
for (i = 0; comp_algos[i].cfg_name; i++) {
if (!strcmp(algo, comp_algos[i].cfg_name)) {
- comp_algo = calloc(1, sizeof(struct comp_algo));
+ comp_algo = calloc(1, sizeof(*comp_algo));
memmove(comp_algo, &comp_algos[i], sizeof(struct comp_algo));
comp_algo->next = comp->algos;
comp->algos = comp_algo;