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/hlua_fcn.c b/src/hlua_fcn.c
index 2ee3393..b9ce84c 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -321,7 +321,7 @@
static struct hlua_concat *hlua_check_concat(lua_State *L, int ud)
{
- return (struct hlua_concat *)(hlua_checkudata(L, ud, class_concat_ref));
+ return (hlua_checkudata(L, ud, class_concat_ref));
}
static int hlua_concat_add(lua_State *L)
@@ -390,7 +390,7 @@
struct hlua_concat *b;
lua_newtable(L);
- b = (struct hlua_concat *)lua_newuserdata(L, sizeof(*b));
+ b = lua_newuserdata(L, sizeof(*b));
b->size = HLUA_CONCAT_BLOCSZ;
b->len = 0;
lua_rawseti(L, -2, 0);
@@ -451,7 +451,7 @@
static struct listener *hlua_check_listener(lua_State *L, int ud)
{
- return (struct listener *)(hlua_checkudata(L, ud, class_listener_ref));
+ return hlua_checkudata(L, ud, class_listener_ref);
}
int hlua_listener_get_stats(lua_State *L)
@@ -493,7 +493,7 @@
static struct server *hlua_check_server(lua_State *L, int ud)
{
- return (struct server *)(hlua_checkudata(L, ud, class_server_ref));
+ return hlua_checkudata(L, ud, class_server_ref);
}
int hlua_server_get_stats(lua_State *L)
@@ -801,7 +801,7 @@
static struct proxy *hlua_check_proxy(lua_State *L, int ud)
{
- return (struct proxy *)(hlua_checkudata(L, ud, class_proxy_ref));
+ return hlua_checkudata(L, ud, class_proxy_ref);
}
int hlua_proxy_pause(lua_State *L)