C
c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
/* Demonstrate what happens when going out
of bounds on the stack. Variables in
other parts of the program are affected.
*/
void a(x,y,z)
unsigned long x,y,z;
{
unsigned long* f;
f = &x;
// clobber the stack to change main()'s variables
f[8] = x; // i
f[7] = y; // j
f[6] = z; // k
}
int main() {
unsigned long i=0, j=0, k=0;
puts("Local variables initial values:");
printf("i, j, k = %ld, %ld, %ld\n", i, j, k);
a(10,20,30);
puts("\nAfter calling a(10,20,30):");
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run