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/server.c b/src/server.c
index 0405da2..d511a2a 100644
--- a/src/server.c
+++ b/src/server.c
@@ -874,7 +874,7 @@
struct protocol *proto;
struct dns_resolution *curr_resolution;
- if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) {
+ if ((newsrv = calloc(1, sizeof(struct server))) == NULL) {
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
@@ -2667,7 +2667,7 @@
serverip = NULL; /* current server IP address */
/* shortcut to the server whose name is being resolved */
- s = (struct server *)resolution->requester;
+ s = resolution->requester;
/* initializing server IP pointer */
server_sin_family = s->addr.ss_family;
@@ -2775,7 +2775,7 @@
int res_preferred_afinet, res_preferred_afinet6;
/* shortcut to the server whose name is being resolved */
- s = (struct server *)resolution->requester;
+ s = resolution->requester;
resolvers = resolution->resolvers;
/* can be ignored if this is not the last response */