2 * Test that allocating a variable length array in a loop
3 * does not use up a linear amount of memory
10 #define LOOP_COUNT 1000
11 #define ARRAY_SIZE 100
13 /* Overwrite a VLA. This will overwrite the return address if SP is incorrect */
14 void smash(char *p
, int n
) {
20 char *array_ptrs
[LOOP_COUNT
];
22 for (i
= 0; i
< LOOP_COUNT
; ++i
) {
28 return (array_ptrs
[0]-array_ptrs
[LOOP_COUNT
-1] < n
) ? 0 : 1;
31 /* ensure goto does not circumvent array free */
33 char *array_ptrs
[LOOP_COUNT
];
49 return (array_ptrs
[0] - array_ptrs
[LOOP_COUNT
-1] < n
) ? 0 : 1;
60 return (test
-test2
>= n
) ? 0 : 1;
64 if (!testname || (strcmp(#t, testname) == 0)) { \
65 fputs(#t "... ", stdout); \
67 if (t(ARRAY_SIZE) == 0) { \
68 fputs("success\n", stdout); \
70 fputs("failure\n", stdout); \
71 retval = EXIT_FAILURE; \
75 int main(int argc
, char **argv
) {
76 const char *testname
= NULL
;
77 int retval
= EXIT_SUCCESS
;