Created
January 6, 2020 16:02
-
-
Save thrimbor/2815f00a97966b97028ac0a23b94bde3 to your computer and use it in GitHub Desktop.
alloca test for nxdk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <hal/debug.h> | |
#include <hal/video.h> | |
#include <windows.h> | |
#include <malloc.h> | |
#include <string.h> | |
// tests whether alloca overlaps other parts of the stack | |
// by writing into an alloca allocated buffer and then | |
// checking other variables on the stack. Also tests | |
// whether we can return properly afterwards | |
void testfunc () | |
{ | |
int a = 0xDEADBEEF; | |
char *buf = alloca(256); | |
int b = 0xDEADC0DE; | |
debugPrint("&a: %p\n", &a); | |
debugPrint("buf: %p\n", buf); | |
debugPrint("&b: %p\n", &b); | |
memset(buf, 0, 256); | |
debugPrint("a: %X\n", a); | |
debugPrint("b: %X\n", b); | |
} | |
int main(void) | |
{ | |
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); | |
debugPrint("calling testfunc()\n"); | |
testfunc(); | |
debugPrint("testfunc() done\n"); | |
while(1) { | |
Sleep(2000); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment