unnecessary casts
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
HIPL |
New
|
Low
|
Diego Biurrun |
Bug Description
DB: There are gazillions of casts, often two in a row. Casts should be
the exception, not the norm. If a large number of casts are
required, then the code structure and design is plain wrong.
Often the results of functions returning void* are cast to some type
even though void* is compatible with any pointer (C is not C++). I
already removed such pointless casts for malloc, memcpy, memset, free
and similar.
But many instances still remain, as an example, take the function
hip_get_
cast all the time, e.g. in lib/conf/conf.c.
MK: Suggest a systematic way to find casts?
---
DB: Another example from lib/opphip/
ret = (hip_opp_socket_t *) hip_ht_
Both casts are unnecessary, this is the prototype for hip_ht_find:
void *hip_ht_find(void *head, void *data);
My personal guess is that at least two thirds of the casts in HIPL
could be avoided. Often the internal API is designed in a way that
seems to make casting back and forth a necessity. If this is the
case, then the API is badly designed.
---
I forgot the completely redundant casts: The results of functions returning
foo are cast to .. foo!
As a random example, grep for append_to_slist and witness that it returns
'SList *' but the result is cast to 'SList *'...
firewall/
connection-
Diego, can you have a quick look and asses the current situation. I guess casts should be at a level that is manageable.
Please, do _not_ start fixing.