[Cocci] sizeof() type
Derek M Jones
derek at knosof.co.uk
Wed Nov 10 17:14:47 CET 2010
Julia,
> It also occurred to me that in eg sizeof(*x), where x has type int *, the
> reference to *x is not really a reference to an integer value, and the
> reference to x is not really a reference to an integer pointer value.
> Thus there is no longer any type inference for the argument to sizeof. If
> this seems like a bad decision, please let me know and I will change it
> back.
The following code is probably wrong:
char * ptr;
x=malloc(10*sizeof(ptr));
The intended argument to sizeof was probably *ptr
Being able to match a pointer argument to sizeof is
a useful thing to be able to do.
Another example is:
struct X x1, x2;
struct Y y;
memcpy(&x1, &x2, sizeof(struct Y));
where the argument to sizeof has a type that is probably wrong.
--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:derek at knosof.co.uk
Source code analysis http://www.knosof.co.uk
More information about the Cocci
mailing list