blob: bd5bfc3ebf28e4604127ba2483e6ab5a8946160a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include <stdio.h>
#include <assert.h>
#include "test.h"
/* this is a well behaved program that prints out a smiley face */
int main()
{
#if defined(COVERAGE)
assert(!covsrv_init());
atexit(covsrv_destroy);
#endif
/* alloc memory for the smiley */
char *p = mallocc(2 * sizeof(char));
if (!p) {
fprintf(stderr, "oops, malloc failed :(\n");
return -1;
}
p[0] = ':';
p[1] = ')';
/* oops, forgot the terminating null, let's realloc */
char *new_p = reallocc(p, 3 * sizeof(char));
if (!new_p) {
fprintf(stderr, "oops, realloc failed :(\n");
free(p);
return -1;
}
p = new_p;
p[2] = '\0';
printf("%s\n", p);
free(p);
}
|