Skip to content

Instantly share code, notes, and snippets.

@euank
Last active August 29, 2015 13:57
Show Gist options
  • Save euank/cae2773776741ff46049 to your computer and use it in GitHub Desktop.
Save euank/cae2773776741ff46049 to your computer and use it in GitHub Desktop.
Just demonstrating c behavior that allows a non-returning function to still accidentally return the right value.
#include <stdlib.h>
#include <stdio.h>
int *getOne() {
register int eax asm("eax");
printf("eax is %x before malloc\n", eax);
int *one = malloc(sizeof(int));
printf("eax is %x after malloc\n", eax);
*one = 1;
}
int main() {
register int eax asm("eax");
printf("eax is %x before call\n", eax);
int *test = getOne();
printf("eax is %x after call\n", eax);
printf("The address of test is %x\n", test);
printf("%d\n", *test);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment