Skip to main content
gamedev.net
🔒 Locked

C Question

Started by smc Mar 4, 2008 at 10:27 PM 2 replies 750+ views
Original Post
smc
smc
I am assuming the lack of type safety in C is the reason why I can do this?

char tst = {
    'a','b'
} ;

int main (int argc, const char * argv[]) {
    void (*fp)() ;
    fp = tst ;
}

In theory I can then load any array with binary code and execute it. I was reading how the windows kernel (use to or still does) overwrite function pointers in order to redirect execution flow to another function. This is quite interesting.
∫Mc
xor
xor
Type safety wouldn't prevent that from happening.
The general solution for that problem/feature found in some security solutions is to prevent stack and heap execution.
deathkrush
deathkrush
That's not a bug, it's a feature! Insomniac (developer of Ratchet and Clank, Resistance...) uses this extensively in SPU shaders. Because of limited memory in PS3 SPEs (256K) they swap the code around like that with char arrays.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Way Walker
Way Walker
EDIT: Never mind, I'm dumb... warnings aren't errors... I just usually treat them that way...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.