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/51d.c b/src/51d.c
index f6e4979..3aa5b86 100644
--- a/src/51d.c
+++ b/src/51d.c
@@ -54,7 +54,7 @@
}
while (*(args[cur_arg])) {
- name = calloc(1, sizeof(struct _51d_property_names));
+ name = calloc(1, sizeof(*name));
name->name = strdup(args[cur_arg]);
LIST_ADDQ(&global._51degrees.property_names, &name->list);
++cur_arg;
@@ -158,7 +158,7 @@
*/
static void _51d_insert_cache_entry(struct sample *smp, struct lru64 *lru, void* domain)
{
- struct chunk *cache_entry = _51d_malloc(sizeof(struct chunk));
+ struct chunk *cache_entry = _51d_malloc(sizeof(*cache_entry));
if (!cache_entry)
return;