1 /* Reproduce a GNU malloc bug. */
6 #define size_t unsigned int
8 /* Defined as global variables to avoid warnings about unused variables. */
11 char *fill_info_table1
;
15 main (int argc
, char *argv
[])
18 size_t over_top_size
= 0x3000;
20 size_t over_top_dup_size
= 0x7000;
24 /* Here's what memory is supposed to look like (hex):
26 3000 original_info_table, later fill_info_table1
33 /* mem: original_info_table */
34 dummy0
= malloc (0x3fa000);
35 /* mem: original_info_table, dummy0 */
36 dummy1
= malloc (0x3fa000);
37 /* mem: free, dummy0, dummy1, info_table_2 */
38 fill_info_table1
= malloc (0x3000);
39 /* mem: fill_info_table1, dummy0, dummy1, info_table_2 */
43 /* mem: fill_info_table1, dummy0, dummy1, info_table_2, freexx */
45 /* This is what loses; info_table_2 and freexx get combined unbeknownst
46 to mmalloc, and mmalloc puts over_top in a section of memory which
47 is on the free list as part of another block (where info_table_2 had
49 over_top
= malloc (over_top_size
);
50 over_top_dup
= malloc (over_top_dup_size
);
51 memset (over_top
, 0, over_top_size
);
52 memset (over_top_dup
, 1, over_top_dup_size
);
54 for (i
= 0; i
< over_top_size
; ++i
)
57 printf ("FAIL: malloc expands info table\n");
61 for (i
= 0; i
< over_top_dup_size
; ++i
)
62 if (over_top_dup
[i
] != 1)
64 printf ("FAIL: malloc expands info table\n");
68 printf ("PASS: malloc expands info table\n");