File: test_recalloc.c

package info (click to toggle)
mle 1.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,108 kB
  • sloc: ansic: 13,335; sh: 728; php: 228; makefile: 83
file content (33 lines) | stat: -rw-r--r-- 633 bytes parent folder | download | duplicates (4)
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
#include "test.h"

typedef struct {
    int a;
    int b;
} thing_t;

char *str = "";

void test(buffer_t *buf, mark_t *cur) {
    int i;
    int is_all_zero;
    thing_t *things;
    int nsize = 1024;

    things = calloc(1, sizeof(thing_t));
    things->a = 1;
    things->b = 2;

    things = recalloc(things, 1, nsize, sizeof(thing_t));
    ASSERT("preserve_a", 1, things->a);
    ASSERT("preserve_b", 2, things->b);

    is_all_zero = 1;
    for (i = 1; i < nsize; i++) {
        if (things[i].a != 0 || things[i].b != 0) {
            is_all_zero = 0;
            break;
        }
    }
    ASSERT("zerod", 1, is_all_zero);

}