1
2/* A simple test to demonstrate heap, stack, and global overrun
3   detection. */
4
5#include <stdio.h>
6#include <stdlib.h>
7
8short ga[100];
9
10__attribute__((noinline))
11int addup_wrongly ( short* arr )
12{
13   int sum = 0, i;
14   for (i = 0; i <= 100; i++)
15      sum += (int)arr[i];
16   return sum;
17}
18
19__attribute__((noinline))
20int do_other_stuff ( void )
21{
22   short la[100];
23   return 123 + addup_wrongly(la);
24}
25
26__attribute__((noinline))
27int do_stupid_malloc_stuff ( void )
28{
29   int sum = 0;
30   unsigned char* duh = malloc(100 * sizeof(char));
31   sum += duh[-1];
32   free(duh);
33   sum += duh[50];
34   return sum;
35}
36
37int main ( void )
38{
39   long s = addup_wrongly(ga);
40   s += do_other_stuff();
41   s += do_stupid_malloc_stuff();
42   if (s == 123456789) {
43      fprintf(stdout, "well, i never!\n");
44   } else {
45      fprintf(stdout, "boringly as expected\n");
46   }
47   return 0;
48}
49