source/myhtml/utils/mcsimple.c

filter: Statementstmt 59.2% 32 / 54 Branchbran 41.6% 10 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 53.8% 42 / 78 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« source/myhtml/utils/mcobject_async.c ↑ Summary source/myhtml/utils/mcsync.c »
1 //
2 // mcsimple.c
3 // osx
4 //
5 // Created by Alexander Borisov on 23.03.16.
6 // Copyright © 2016 Alexander Borisov. All rights reserved.
7 //
8  
9 #include "mcsimple.h"
10  
11 1 mcsimple_t * mcsimple_create(void)
12 {
13 1 return mycalloc(1, sizeof(mcsimple_t));
14 }
15  
16 1 void mcsimple_init(mcsimple_t *mcsimple, size_t pos_size, size_t list_size, size_t struct_size)
17 {
18 1 mcsimple->struct_size = struct_size;
19
20 1 mcsimple->list_pos_length_used = 0;
21 1 mcsimple->list_pos_length = 0;
22 1 mcsimple->list_pos_size = pos_size;
23 1 mcsimple->list = (uint8_t**)mycalloc(pos_size, sizeof(uint8_t*));
24
25 1 ▶ if(mcsimple->list == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(mcsimple->list == NULL) { 0 1 1
26 0 return;
27 }
28
29 1 mcsimple->list_size = list_size * struct_size;
30
31 1 ▶ if((mcsimple_init_list_entries(mcsimple, mcsimple->list_pos_length) == NULL)) {
Branch: 1 branch
BranchTrueFalseTotal
if((mcsimple_init_list_entries(mcsimple, mcsimple->list_pos_length) == NULL)) { 0 1 1
32 0 return;
33 }
34 }
35  
36 2 void mcsimple_clean(mcsimple_t *mcsimple)
37 {
38 2 mcsimple->list_length = 0;
39 2 mcsimple->list_pos_length = 0;
40 2 }
41  
42 1 mcsimple_t * mcsimple_destroy(mcsimple_t *mcsimple, bool destroy_self)
43 {
44 1 ▶ if(mcsimple == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(mcsimple == NULL) 0 1 1
45 0 return NULL;
46
47 1 ▶ if(mcsimple->list) {
Branch: 1 branch
BranchTrueFalseTotal
if(mcsimple->list) { 1 0 1
48 2 ▶ for(size_t i = 0; i < mcsimple->list_pos_length_used; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(size_t i = 0; i < mcsimple->list_pos_length_used; i++) { 1 1 2
49 1 ▶ if(mcsimple->list[i])
Branch: 1 branch
BranchTrueFalseTotal
if(mcsimple->list[i]) 1 0 1
50 1 free(mcsimple->list[i]);
51 }
52
53 1 free(mcsimple->list);
54 }
55
56 1 ▶ if(destroy_self) {
Branch: 1 branch
BranchTrueFalseTotal
if(destroy_self) { 1 0 1
57 1 free(mcsimple);
58 1 return NULL;
59 }
60
61 0 return mcsimple;
62 }
63  
64 1 uint8_t * mcsimple_init_list_entries(mcsimple_t *mcsimple, size_t pos)
65 {
66 1 ▶ if(mcsimple->list_pos_length >= mcsimple->list_pos_size)
Branch: 1 branch
BranchTrueFalseTotal
if(mcsimple->list_pos_length >= mcsimple->list_pos_size) 0 1 1
67 {
68 0 size_t new_size = mcsimple->list_pos_size + 128;
69 0 uint8_t **list = (uint8_t**)myrealloc(mcsimple->list, mcsimple->list_pos_size * sizeof(uint8_t*));
70
71 0 ▶ if(list) {
Branch: 1 branch
BranchTrueFalseTotal
if(list) { 0 0 0
72 0 mcsimple->list = list;
73 0 memset(&mcsimple->list[pos], 0, (new_size - mcsimple->list_pos_size) * sizeof(uint8_t*));
74
75 0 mcsimple->list_pos_size = new_size;
76 }
77 else
78 0 return NULL;
79 }
80
81 1 mcsimple->list_length = 0;
82
83 1 ▶ if(mcsimple->list[pos] == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(mcsimple->list[pos] == NULL) { 1 0 1
84 1 mcsimple->list_pos_length_used++;
85 1 mcsimple->list[pos] = (uint8_t*)mymalloc(mcsimple->list_size * sizeof(uint8_t));
86 }
87
88 1 return mcsimple->list[pos];
89 }
90  
91 0 void * mcsimple_malloc(mcsimple_t *mcsimple)
92 {
93 0 ▶ if(mcsimple->list_length >= mcsimple->list_size)
Branch: 1 branch
BranchTrueFalseTotal
if(mcsimple->list_length >= mcsimple->list_size) 0 0 0
94 {
95 0 mcsimple->list_pos_length++;
96 0 ▶ if((mcsimple_init_list_entries(mcsimple, mcsimple->list_pos_length) == NULL)) {
Branch: 1 branch
BranchTrueFalseTotal
if((mcsimple_init_list_entries(mcsimple, mcsimple->list_pos_length) == NULL)) { 0 0 0
97 0 return NULL;
98 }
99 }
100
101 0 size_t current = mcsimple->list_length;
102 0 mcsimple->list_length += mcsimple->struct_size;
103
104 0 return &mcsimple->list[mcsimple->list_pos_length][current];
105 }
106  
107 0 void * mcsimple_get_by_absolute_position(mcsimple_t *mcsimple, size_t pos)
108 {
109 0 pos *= mcsimple->struct_size;
110 0 return &mcsimple->list[ (pos / mcsimple->list_size) ][ (pos % mcsimple->list_size) ];
111 }
112  
113  
« source/myhtml/utils/mcobject_async.c ↑ Summary source/myhtml/utils/mcsync.c »