Here's some simple code from the tutorial that I understand and yet it prints incorrect output:
The stack has buffer2 (takes up 12 bytes), buffer1 (takes up 8 bytes), the sfp (4 bytes), and the ret (4 bytes) since you have to address by word. So when I point ret to buffer1 and add 12, it's actually pointing to the return address. Then I bump up the return address by 8 (two words). So it should return to the print statement and skip the x = 1. However, it does execute the x=1 statement and therefore, prints out 1.
Code:
void function(int a, int b, int c) {
char buffer1[5];
char buffer2[10];
int *ret;
ret = buffer1 + 12;
(*ret) += 8;
}
void main() {
int x;
x = 0;
function(1,2,3);
x = 1;
printf("%d\n",x);
}