CLEANUP: remove unneeded casts
In C89, "void *" is automatically promoted to any pointer type. Casting
the result of malloc/calloc to the type of the LHS variable is therefore
unneeded.
Most of this patch was built using this Coccinelle patch:
@@
type T;
@@
- (T *)
(\(lua_touserdata\|malloc\|calloc\|SSL_get_app_data\|hlua_checkudata\|lua_newuserdata\)(...))
@@
type T;
T *x;
void *data;
@@
x =
- (T *)
data
@@
type T;
T *x;
T *data;
@@
x =
- (T *)
data
Unfortunately, either Coccinelle or I is too limited to detect situation
where a complex RHS expression is of type "void *" and therefore casting
is not needed. Those cases were manually examined and corrected.
diff --git a/src/acl.c b/src/acl.c
index 033cfc9..0b88284 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -353,7 +353,7 @@
cur_type = smp_expr_output_type(smp);
}
- expr = (struct acl_expr *)calloc(1, sizeof(*expr));
+ expr = calloc(1, sizeof(*expr));
if (!expr) {
memprintf(err, "out of memory when parsing ACL expression");
goto out_return;
@@ -749,7 +749,7 @@
memprintf(err, "out of memory when parsing ACL");
goto out_free_acl_expr;
}
- cur_acl = (struct acl *)calloc(1, sizeof(*cur_acl));
+ cur_acl = calloc(1, sizeof(*cur_acl));
if (cur_acl == NULL) {
memprintf(err, "out of memory when parsing ACL");
goto out_free_name;
@@ -846,7 +846,7 @@
goto out_free_acl_expr;
}
- cur_acl = (struct acl *)calloc(1, sizeof(*cur_acl));
+ cur_acl = calloc(1, sizeof(*cur_acl));
if (cur_acl == NULL) {
memprintf(err, "out of memory when building default ACL '%s'", acl_name);
goto out_free_name;
@@ -907,7 +907,7 @@
struct acl_cond *cond;
unsigned int suite_val;
- cond = (struct acl_cond *)calloc(1, sizeof(*cond));
+ cond = calloc(1, sizeof(*cond));
if (cond == NULL) {
memprintf(err, "out of memory when parsing condition");
goto out_return;
@@ -995,7 +995,7 @@
}
}
- cur_term = (struct acl_term *)calloc(1, sizeof(*cur_term));
+ cur_term = calloc(1, sizeof(*cur_term));
if (cur_term == NULL) {
memprintf(err, "out of memory when parsing condition");
goto out_free_suite;
@@ -1017,7 +1017,7 @@
suite_val &= cur_acl->val;
if (!cur_suite) {
- cur_suite = (struct acl_term_suite *)calloc(1, sizeof(*cur_suite));
+ cur_suite = calloc(1, sizeof(*cur_suite));
if (cur_suite == NULL) {
memprintf(err, "out of memory when parsing condition");
goto out_free_term;