> On 30.04.2015 20:01, Holger Freyther wrote:
> >
> >> On 30 Apr 2015, at 19:28, Jacob Erlbeck <[email protected]> wrote:
> >> This is due to an '&' operator at the wrong place, accessing some
> >> parts in fc instead of the first element of the list.

Yikes!

I think the definition of container_of() shouldn't cast ptr:

#define container_of(ptr, type, member) ({                     \
-        const typeof( ((type *)0)->member ) *__mptr = (typeof( ((type 
*)0)->member ) *)(ptr);  \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);   \
         (type *)( (char *)__mptr - offsetof(type, member) );})

Signed-off-by: Michael McTernan <[email protected]>

Then we get one nice warning from gcc:

gprs_bssgp.c: In function 'fc_queue_timer_cfg':
gprs_bssgp.c:631:9: warning: initialization from incompatible pointer type 
[enabled by default]

Everything I've tried* still compiles and runs with this change (and generates 
no other warnings), but obviously libosmocore could be used somewhere else 
where container_of type abuse will now make warnings.  If such a case is found 
where the cast is correct and required, I'd recommend the casting be placed at 
the calls to container_of() where it is more visible and auditable.

Please try the above patch and consider applying it to libosmocore.  

Jacob, would you also like/be able to check that the above change is good with 
Coverity, incase that can dig out any other bugs?

Kind Regards,

Mike

* I build the following into my system, some of which use libosmocore:
libdbi-0.9.0
libdbi-drivers-0.9.0
libosmo-abis
libosmocore
libosmo-netif
libosmo-sccp
openbsc
openggsn
ortp-0.22.0
osmo-bts
osmo-pcu

Reply via email to