1 /* { dg-additional-options "-fanalyzer-call-summaries" } */
3 typedef __SIZE_TYPE__
size_t;
4 #include "../../gcc.dg/analyzer/analyzer-decls.h"
18 /* global context variable */
20 static struct context_s
*ctx
;
24 struct screen_s
*screen_create(size_t cols
, size_t rows
);
25 void screen_destroy(struct screen_s
*scr
);
26 void resize_screen(size_t cols
, size_t rows
);
30 struct screen_s
*screen_create(size_t cols
, size_t rows
)
32 struct screen_s
*result
= NULL
;
34 result
= (struct screen_s
*) __builtin_calloc(1, sizeof(*result
));
41 /* make one allocation which will be accessed like a 2D array */
42 result
->data
= (char **) __builtin_calloc(rows
, sizeof(result
->data
) + sizeof(*result
->data
) * cols
);
44 __builtin_free(result
);
48 /* obtain pointer to start of data area */
49 char *ptr
= (char *)(result
->data
+ rows
);
51 /* setup pointers for each row of data to allow 2D array access */
52 for (size_t row
= 0; row
< rows
; row
++)
53 result
->data
[row
] = (ptr
+ row
* cols
);
54 /* array can now be accessed like data[row][col] */
59 void screen_destroy(struct screen_s
*scr
)
64 __builtin_free(scr
->data
);
73 void resize_screen(size_t cols
, size_t rows
)
75 /* create a new screen */
76 struct screen_s
*new_scr
= NULL
;
77 new_scr
= screen_create(cols
, rows
); /* { dg-bogus "leak" "PR 108045" { xfail *-*-* } } */
82 /* swap the old screen with the new one */
83 struct screen_s
*old_scr
= ctx
->scr
;
86 /* omitted: copy the old screen contents to the new screen */
88 /* free the old screen */
89 screen_destroy(old_scr
);
94 ctx
= (struct context_s
*) __builtin_calloc(1, sizeof(*ctx
));
98 ctx
->scr
= screen_create(80, 25); /* { dg-bogus "leak" "PR 108045" { xfail *-*-* } } */
99 resize_screen(100, 20);
101 /* tidy up and quit */
102 screen_destroy(ctx
->scr
);