1 /* { dg-additional-options "-fno-analyzer-call-summaries" } */
2 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
4 typedef __SIZE_TYPE__
size_t;
5 #include "../../gcc.dg/analyzer/analyzer-decls.h"
19 /* global context variable */
21 static struct context_s
*ctx
;
25 struct screen_s
*screen_create(size_t cols
, size_t rows
);
26 void screen_destroy(struct screen_s
*scr
);
27 void resize_screen(size_t cols
, size_t rows
);
31 struct screen_s
*screen_create(size_t cols
, size_t rows
)
33 struct screen_s
*result
= NULL
;
35 result
= (struct screen_s
*) __builtin_calloc(1, sizeof(*result
));
42 /* make one allocation which will be accessed like a 2D array */
43 result
->data
= (char **) __builtin_calloc(rows
, sizeof(result
->data
) + sizeof(*result
->data
) * cols
);
45 __builtin_free(result
);
49 /* obtain pointer to start of data area */
50 char *ptr
= (char *)(result
->data
+ rows
);
52 /* setup pointers for each row of data to allow 2D array access */
53 for (size_t row
= 0; row
< rows
; row
++)
54 result
->data
[row
] = (ptr
+ row
* cols
);
55 /* array can now be accessed like data[row][col] */
60 void screen_destroy(struct screen_s
*scr
)
65 __builtin_free(scr
->data
);
71 __builtin_free(scr
); /* { dg-bogus "leak" } */
74 void resize_screen(size_t cols
, size_t rows
)
76 /* create a new screen */
77 struct screen_s
*new_scr
= NULL
;
78 new_scr
= screen_create(cols
, rows
); /* { dg-bogus "leak" } */
83 /* swap the old screen with the new one */
84 struct screen_s
*old_scr
= ctx
->scr
;
87 /* omitted: copy the old screen contents to the new screen */
89 /* free the old screen */
90 screen_destroy(old_scr
);
95 ctx
= (struct context_s
*) __builtin_calloc(1, sizeof(*ctx
));
99 ctx
->scr
= screen_create(80, 25); /* { dg-bogus "leak" } */
100 resize_screen(100, 20);
102 /* tidy up and quit */
103 screen_destroy(ctx
->scr
);