Skip to contentSkip to conversation

bad function ptrs - is it dangerous ?

DISCUSSION J.A. Magallon 2 participants 2 messages Oct 1, 2002

lore
Share & tools
lore
#0 lore raw

Hi al...

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 ?

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

TIA

Signature · 4 lines
J.A. Magallon <[email protected]>      \                 Software is like sex:
werewolf.able.es                         \           It's better when it's free
Mandrake Linux release 9.0 (dolphin) for i586
Linux 2.4.20-pre8-jam1 (gcc 3.2 (Mandrake Linux 9.0 3.2-1mdk))
#1 lore raw
Quoted 15 lines · J.A. Magallon

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*);

Quoted 8 lines

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