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/haproxy.c b/src/haproxy.c
index b10f4e8..51af55a 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -711,7 +711,7 @@
/* now that's a cfgfile list */
argv++; argc--;
while (argc > 0) {
- wl = (struct wordlist *)calloc(1, sizeof(*wl));
+ wl = calloc(1, sizeof(*wl));
if (!wl) {
Alert("Cannot load configuration file %s : out of memory.\n", *argv);
exit(1);
@@ -734,7 +734,7 @@
case 'N' : cfg_maxpconn = atol(*argv); break;
case 'L' : strncpy(localpeer, *argv, sizeof(localpeer) - 1); break;
case 'f' :
- wl = (struct wordlist *)calloc(1, sizeof(*wl));
+ wl = calloc(1, sizeof(*wl));
if (!wl) {
Alert("Cannot load configuration file %s : out of memory.\n", *argv);
exit(1);
@@ -1101,14 +1101,12 @@
if (global.nbproc < 1)
global.nbproc = 1;
- swap_buffer = (char *)calloc(1, global.tune.bufsize);
- get_http_auth_buff = (char *)calloc(1, global.tune.bufsize);
+ swap_buffer = calloc(1, global.tune.bufsize);
+ get_http_auth_buff = calloc(1, global.tune.bufsize);
static_table_key = calloc(1, sizeof(*static_table_key));
- fdinfo = (struct fdinfo *)calloc(1,
- sizeof(struct fdinfo) * (global.maxsock));
- fdtab = (struct fdtab *)calloc(1,
- sizeof(struct fdtab) * (global.maxsock));
+ fdinfo = calloc(1, sizeof(struct fdinfo) * (global.maxsock));
+ fdtab = calloc(1, sizeof(struct fdtab) * (global.maxsock));
/*
* Note: we could register external pollers here.
* Built-in pollers have been registered before main().