Re: bad function ptrs - is it dangerous ?

From: Mikael Pettersson (mikpe@csd.uu.se)
Date: Wed Oct 02 2002 - 03:06:00 EST


On Wed, 2 Oct 2002 00:51:25 +0200, J.A. Magallon wrote:
>int (*pf)(data *);
>int f(data*);
>
>so you can:
>
>pf = f;
>pf(data).
>
>Fine. But what happens if:
>
>void (*pf)(data *);
>int f(data*);
>
>pf = f; // gcc happily swallows, gcc-3.2 gives a warning.
>pf(data).

Undefined Behaviour. I can easily imagine cases where, depending
on the calling convention and the actual return type, things could
go very very wrong. Consider struct returns...

This case, returning an int to a caller expecting void, is likely
to work on most normal machines -- the int would go into a GP result
register, and the GP result register is typically always part of the
caller-save set. The code is still utter crap, however.

>The (in)famous graphics driver all you know is doing this with the
>copy_info op for gart...

<censored>

/Mikael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Oct 07 2002 - 22:00:33 EST