DRD: Eliminate a temporary variable
[valgrind.git] / exp-sgcheck / tests / stackerr.c
blob36b8e67259aa75f333039dccdd56d0c0bf889ac0
2 /* Check basic stack overflow detection.
4 It's difficult to get consistent behaviour across all platforms.
5 For example, x86 w/ gcc-4.3.1 gives
7 Expected: stack array "a" in frame 2 back from here
8 Actual: stack array "beforea" in frame 2 back from here
10 whereas amd64 w/ gcc-4.3.1 gives
12 Expected: stack array "a" in frame 2 back from here
13 Actual: unknown
15 This happens because on x86 the arrays are placed on the
16 stack without holes in between, but not so for amd64. I don't
17 know why.
21 #include <stdio.h>
23 __attribute__((noinline)) void foo ( long* sa, int n )
25 int i;
26 for (i = 0; i < n; i++)
27 sa[i] = 0;
30 __attribute__((noinline)) void bar ( long* sa, int n )
32 foo(sa, n);
35 int main ( void )
37 int i;
38 long beforea[3];
39 long a[7];
40 long aftera[3];
41 bar(a, 7+1); /* generates error */
42 bar(a, 7+0); /* generates no error */
43 for (i = 0; i < 7+1; i++) {
44 a[i] = 0;
46 {char beforebuf[8];
47 char buf[8];
48 char afterbuf[8];
49 sprintf(buf, "%d", 123456789);
50 return 1 & ((a[4] + beforea[1] + aftera[1] + beforebuf[1]
51 + buf[2] + afterbuf[3]) / 100000) ;