-
Notifications
You must be signed in to change notification settings - Fork 0
/
buggy.c
65 lines (54 loc) · 1.14 KB
/
buggy.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct {
size_t len;
uint8_t *raw;
} data_t;
volatile int fate;
void data_free(data_t* data) {
if (data->raw != NULL) {
free(data->raw);
}
free(data);
data = NULL;
}
data_t* data_read() {
data_t* data = malloc(sizeof(data_t));
if (NULL == data) return NULL;
data->len = 0;
//data->raw = NULL;
if (fate <= 0) {
data_free(data);
return NULL;
}
data->len = fate;
data->raw = malloc(fate);
return data;
}
int main(int argc, char** argv) {
data_t *data = data_read();
if ( data != NULL ) {
printf("1. data_read succeeded: data len = %lu\n", data->len);
data_free(data);
} else {
printf("1. data_read falied with fate = %d\n", fate);
}
fate = 256;
data = data_read();
if ( data != NULL ) {
printf("2. data_read succeeded: data len = %lu\n", data->len);
data_free(data);
} else {
printf("2. data_read falied with fate = %d\n", fate);
}
fate = 0;
data = data_read();
if ( data != NULL ) {
printf("3. data_read succeeded: data len = %lu\n", data->len);
data_free(data);
} else {
printf("3. data_read falied with fate = %d\n", fate);
}
return 0;
}