blob: 71e5023ae0fd4138f34ee70ba5092fa1d1e71861 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* exercise a bug found in malloc-standard when alignment
2 * values are out of whack and cause a small overflow into
3 * actual user data.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <sys/types.h>
9
10#define ok(p) ((void*)p > (void*)0x1000)
11#define x \
12 do { \
13 printf("%i: phead = %p, phead->link @ %p = %p %s\n", \
14 __LINE__, phead, \
15 ok(phead) ? &phead->link : 0, \
16 ok(phead) ? phead->link : 0, \
17 ok(phead) ? phead->link == 0 ? "" : "!!!!!!!!!!!" : ""); \
18 if (phead->link != NULL) exit(1); \
19 } while (0);
20
21struct llist_s {
22 void *data;
23 struct llist_s *link;
24} *phead;
25
26int main(int argc, char *argv[])
27{
28 char *line, *reg;
29
30 setbuf(stdout, NULL);
31 setbuf(stderr, NULL);
32
33 phead = malloc(sizeof(*phead));
34 phead->link = NULL;
35
36x line = malloc(80);
37x line = realloc(line, 2);
38x reg = malloc(32);
39x free(line);
40
41x return 0;
42}