Re: bad function ptrs - is it dangerous ?

From: Burton Samograd (kruhft@kruhft.dyndns.org)
Date: Tue Oct 01 2002 - 18:56:59 EST


On Wed, Oct 02, 2002 at 12:51:25AM +0200, J.A. Magallon wrote:
> I have a little question. Let's suppose you have this:
>
> 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).
>
> ??
>
> In C calling convention, the callee kills the stack so nothing should
> happen... or it should ?
>

I think that under most calling conventions return values are put into
registers, so this shouldn't do anything other than keep the compiler from
reallocating the designated return register for a while.

Or, after a second or two of more thought, it might cause the function to trash
whatever value is contained in the return register, which the compiler thought
was safe from harm. It all depends on the calling convention and whether the
caller assumes that the callee can destroy any registers or if the callee has to
save and restore the registers it uses.

burton



-
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:30 EST