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/sample.c b/src/sample.c
index fc42610..8a2fa4f 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -855,7 +855,7 @@
}
prev_type = fetch->out_type;
- expr = calloc(1, sizeof(struct sample_expr));
+ expr = calloc(1, sizeof(*expr));
if (!expr)
goto out_error;
@@ -958,7 +958,7 @@
}
prev_type = conv->out_type;
- conv_expr = calloc(1, sizeof(struct sample_conv_expr));
+ conv_expr = calloc(1, sizeof(*conv_expr));
if (!conv_expr)
goto out_error;