OpenCoverage

bitmap.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/bitmap.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11struct bitmap {-
12 u_int *d;-
13 size_t len;-
14 size_t top;-
15};-
16-
17struct bitmap *-
18bitmap_new(void)-
19{-
20 struct bitmap *ret;-
21-
22 if ((
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
ret = calloc(1, sizeof(*ret))) ==
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
0-1
23 ((void *)0)
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
0-1
24 )-
25 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
26 ((void *)0)
never executed: return ((void *)0) ;
0
27 ;
never executed: return ((void *)0) ;
0
28 if ((
(ret->d = call...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
ret->d = calloc(1, (sizeof(u_int)))) ==
(ret->d = call...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
0-1
29 ((void *)0)
(ret->d = call...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
0-1
30 ) {-
31 free(ret);-
32 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
33 ((void *)0)
never executed: return ((void *)0) ;
0
34 ;
never executed: return ((void *)0) ;
0
35 }-
36 ret->len = 1;-
37 ret->top = 0;-
38 return
executed 1 time by 1 test: return ret;
Executed by:
  • test_bitmap
ret;
executed 1 time by 1 test: return ret;
Executed by:
  • test_bitmap
1
39}-
40-
41void-
42bitmap_free(struct bitmap *b)-
43{-
44 if (b !=
b != ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
FALSEnever evaluated
0-1
45 ((void *)0)
b != ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
FALSEnever evaluated
0-1
46 && b->d !=
b->d != ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
FALSEnever evaluated
0-1
47 ((void *)0)
b->d != ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
FALSEnever evaluated
0-1
48 ) {-
49 bitmap_zero(b);-
50 free(b->d);-
51 b->d = -
52 ((void *)0)-
53 ;-
54 }
executed 1 time by 1 test: end of block
Executed by:
  • test_bitmap
1
55 free(b);-
56}
executed 1 time by 1 test: end of block
Executed by:
  • test_bitmap
1
57-
58void-
59bitmap_zero(struct bitmap *b)-
60{-
61 memset(b->d, 0, b->len * (sizeof(u_int)));-
62 b->top = 0;-
63}
executed 6899905 times by 1 test: end of block
Executed by:
  • test_bitmap
6899905
64-
65int-
66bitmap_test_bit(struct bitmap *b, u_int n)-
67{-
68 if (b->top >= b->len
b->top >= b->lenDescription
TRUEnever evaluated
FALSEevaluated 903887424 times by 1 test
Evaluated by:
  • test_bitmap
)
0-903887424
69 return
never executed: return 0;
0;
never executed: return 0;
0
70 if (b->len == 0
b->len == 0Description
TRUEnever evaluated
FALSEevaluated 903887424 times by 1 test
Evaluated by:
  • test_bitmap
|| (
(n / (sizeof(u...* 8)) > b->topDescription
TRUEevaluated 91167192 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 812720232 times by 1 test
Evaluated by:
  • test_bitmap
n / (sizeof(u_int) * 8)) > b->top
(n / (sizeof(u...* 8)) > b->topDescription
TRUEevaluated 91167192 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 812720232 times by 1 test
Evaluated by:
  • test_bitmap
)
0-903887424
71 return
executed 91167192 times by 1 test: return 0;
Executed by:
  • test_bitmap
0;
executed 91167192 times by 1 test: return 0;
Executed by:
  • test_bitmap
91167192
72 return
executed 812720232 times by 1 test: return (b->d[n / (sizeof(u_int) * 8)] >> (n & ((u_int)(sizeof(u_int) * 8) - 1))) & 1;
Executed by:
  • test_bitmap
(b->d[n / (sizeof(u_int) * 8)] >> (n & ((u_int)(sizeof(u_int) * 8) - 1))) & 1;
executed 812720232 times by 1 test: return (b->d[n / (sizeof(u_int) * 8)] >> (n & ((u_int)(sizeof(u_int) * 8) - 1))) & 1;
Executed by:
  • test_bitmap
812720232
73}-
74-
75static int-
76reserve(struct bitmap *b, u_int n)-
77{-
78 u_int *tmp;-
79 size_t nlen;-
80-
81 if (b->top >= b->len
b->top >= b->lenDescription
TRUEnever evaluated
FALSEevaluated 310443408 times by 1 test
Evaluated by:
  • test_bitmap
|| n > (1<<24)
n > (1<<24)Description
TRUEnever evaluated
FALSEevaluated 310443408 times by 1 test
Evaluated by:
  • test_bitmap
)
0-310443408
82 return
never executed: return -1;
-1;
never executed: return -1;
0
83 nlen = (n / (sizeof(u_int) * 8)) + 1;-
84 if (b->len < nlen
b->len < nlenDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 310443404 times by 1 test
Evaluated by:
  • test_bitmap
) {
4-310443404
85 if ((
(tmp = recallo...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_bitmap
tmp = recallocarray(b->d, b->len,
(tmp = recallo...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_bitmap
0-4
86 nlen, (sizeof(u_int)))) ==
(tmp = recallo...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_bitmap
0-4
87 ((void *)0)
(tmp = recallo...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_bitmap
0-4
88 )-
89 return
never executed: return -1;
-1;
never executed: return -1;
0
90 b->d = tmp;-
91 b->len = nlen;-
92 }
executed 4 times by 1 test: end of block
Executed by:
  • test_bitmap
4
93 return
executed 310443408 times by 1 test: return 0;
Executed by:
  • test_bitmap
0;
executed 310443408 times by 1 test: return 0;
Executed by:
  • test_bitmap
310443408
94}-
95-
96int-
97bitmap_set_bit(struct bitmap *b, u_int n)-
98{-
99 int r;-
100 size_t offset;-
101-
102 if ((
(r = reserve(b, n)) != 0Description
TRUEnever evaluated
FALSEevaluated 308143440 times by 1 test
Evaluated by:
  • test_bitmap
r = reserve(b, n)) != 0
(r = reserve(b, n)) != 0Description
TRUEnever evaluated
FALSEevaluated 308143440 times by 1 test
Evaluated by:
  • test_bitmap
)
0-308143440
103 return
never executed: return r;
r;
never executed: return r;
0
104 offset = n / (sizeof(u_int) * 8);-
105 if (offset > b->top
offset > b->topDescription
TRUEevaluated 6490723 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 301652717 times by 1 test
Evaluated by:
  • test_bitmap
)
6490723-301652717
106 b->top = offset;
executed 6490723 times by 1 test: b->top = offset;
Executed by:
  • test_bitmap
6490723
107 b->d[offset] |= (u_int)1 << (n & ((u_int)(sizeof(u_int) * 8) - 1));-
108 return
executed 308143440 times by 1 test: return 0;
Executed by:
  • test_bitmap
0;
executed 308143440 times by 1 test: return 0;
Executed by:
  • test_bitmap
308143440
109}-
110-
111-
112static void-
113retop(struct bitmap *b)-
114{-
115 if (b->top >= b->len
b->top >= b->lenDescription
TRUEnever evaluated
FALSEevaluated 18347471 times by 1 test
Evaluated by:
  • test_bitmap
)
0-18347471
116 return;
never executed: return;
0
117 while (b->top > 0
b->top > 0Description
TRUEevaluated 18167793 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 179684 times by 1 test
Evaluated by:
  • test_bitmap
&& b->d[b->top] == 0
b->d[b->top] == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 18167787 times by 1 test
Evaluated by:
  • test_bitmap
)
6-18167793
118 b->top--;
executed 6 times by 1 test: b->top--;
Executed by:
  • test_bitmap
6
119}
executed 18347471 times by 1 test: end of block
Executed by:
  • test_bitmap
18347471
120-
121void-
122bitmap_clear_bit(struct bitmap *b, u_int n)-
123{-
124 size_t offset;-
125-
126 if (b->top >= b->len
b->top >= b->lenDescription
TRUEnever evaluated
FALSEevaluated 6847632 times by 1 test
Evaluated by:
  • test_bitmap
|| n > (1<<24)
n > (1<<24)Description
TRUEnever evaluated
FALSEevaluated 6847632 times by 1 test
Evaluated by:
  • test_bitmap
)
0-6847632
127 return;
never executed: return;
0
128 offset = n / (sizeof(u_int) * 8);-
129 if (offset > b->top
offset > b->topDescription
TRUEnever evaluated
FALSEevaluated 6847632 times by 1 test
Evaluated by:
  • test_bitmap
)
0-6847632
130 return;
never executed: return;
0
131 b->d[offset] &= ~((u_int)1 << (n & ((u_int)(sizeof(u_int) * 8) - 1)));-
132-
133 retop(b);-
134}
executed 6847632 times by 1 test: end of block
Executed by:
  • test_bitmap
6847632
135-
136size_t-
137bitmap_nbits(struct bitmap *b)-
138{-
139 size_t bits;-
140 u_int w;-
141-
142 retop(b);-
143 if (b->top >= b->len
b->top >= b->lenDescription
TRUEnever evaluated
FALSEevaluated 9199872 times by 1 test
Evaluated by:
  • test_bitmap
)
0-9199872
144 return
never executed: return 0;
0;
never executed: return 0;
0
145 if (b->len == 0
b->len == 0Description
TRUEnever evaluated
FALSEevaluated 9199872 times by 1 test
Evaluated by:
  • test_bitmap
|| (b->top == 0
b->top == 0Description
TRUEevaluated 143748 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 9056124 times by 1 test
Evaluated by:
  • test_bitmap
&& b->d[0] == 0
b->d[0] == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 143744 times by 1 test
Evaluated by:
  • test_bitmap
))
0-9199872
146 return
executed 4 times by 1 test: return 0;
Executed by:
  • test_bitmap
0;
executed 4 times by 1 test: return 0;
Executed by:
  • test_bitmap
4
147-
148 w = b->d[b->top];-
149 bits = (b->top + 1) * (sizeof(u_int) * 8);-
150 while (!(w & ((u_int)1 << ((sizeof(u_int) * 8) - 1)))
!(w & ((u_int)...t) * 8) - 1)))Description
TRUEevaluated 134459152 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 9199868 times by 1 test
Evaluated by:
  • test_bitmap
) {
9199868-134459152
151 w <<= 1;-
152 bits--;-
153 }
executed 134459152 times by 1 test: end of block
Executed by:
  • test_bitmap
134459152
154 return
executed 9199868 times by 1 test: return bits;
Executed by:
  • test_bitmap
bits;
executed 9199868 times by 1 test: return bits;
Executed by:
  • test_bitmap
9199868
155}-
156-
157size_t-
158bitmap_nbytes(struct bitmap *b)-
159{-
160 return
executed 6899904 times by 1 test: return (bitmap_nbits(b) + 7) / 8;
Executed by:
  • test_bitmap
(bitmap_nbits(b) + 7) / 8;
executed 6899904 times by 1 test: return (bitmap_nbits(b) + 7) / 8;
Executed by:
  • test_bitmap
6899904
161}-
162-
163int-
164bitmap_to_string(struct bitmap *b, void *p, size_t l)-
165{-
166 u_char *s = (u_char *)p;-
167 size_t i, j, k, need = bitmap_nbytes(b);-
168-
169 if (l < need
l < needDescription
TRUEnever evaluated
FALSEevaluated 2299968 times by 1 test
Evaluated by:
  • test_bitmap
|| b->top >= b->len
b->top >= b->lenDescription
TRUEnever evaluated
FALSEevaluated 2299968 times by 1 test
Evaluated by:
  • test_bitmap
)
0-2299968
170 return
never executed: return -1;
-1;
never executed: return -1;
0
171 if (l > need
l > needDescription
TRUEevaluated 2299968 times by 1 test
Evaluated by:
  • test_bitmap
FALSEnever evaluated
)
0-2299968
172 l = need;
executed 2299968 times by 1 test: l = need;
Executed by:
  • test_bitmap
2299968
173-
174 for (i = k = 0; i < b->top + 1
i < b->top + 1Description
TRUEevaluated 8129916 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 2299968 times by 1 test
Evaluated by:
  • test_bitmap
; i++) {
2299968-8129916
175 for (j = 0; j < (sizeof(u_int))
j < (sizeof(u_int))Description
TRUEevaluated 30946383 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 6522524 times by 1 test
Evaluated by:
  • test_bitmap
; j++) {
6522524-30946383
176 if (k >= l
k >= lDescription
TRUEevaluated 1607392 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 29338991 times by 1 test
Evaluated by:
  • test_bitmap
)
1607392-29338991
177 break;
executed 1607392 times by 1 test: break;
Executed by:
  • test_bitmap
1607392
178 s[need - 1 - k++] = (b->d[i] >> (j * 8)) & 0xff;-
179 }
executed 29338991 times by 1 test: end of block
Executed by:
  • test_bitmap
29338991
180 }
executed 8129916 times by 1 test: end of block
Executed by:
  • test_bitmap
8129916
181 return
executed 2299968 times by 1 test: return 0;
Executed by:
  • test_bitmap
0;
executed 2299968 times by 1 test: return 0;
Executed by:
  • test_bitmap
2299968
182}-
183-
184int-
185bitmap_from_string(struct bitmap *b, const void *p, size_t l)-
186{-
187 int r;-
188 size_t i, offset, shift;-
189 const u_char *s = (const u_char *)p;-
190-
191 if (l > (1<<24) / 8
l > (1<<24) / 8Description
TRUEnever evaluated
FALSEevaluated 2299968 times by 1 test
Evaluated by:
  • test_bitmap
)
0-2299968
192 return
never executed: return -1;
-1;
never executed: return -1;
0
193 if ((
(r = reserve(b, l * 8)) != 0Description
TRUEnever evaluated
FALSEevaluated 2299968 times by 1 test
Evaluated by:
  • test_bitmap
r = reserve(b, l * 8)) != 0
(r = reserve(b, l * 8)) != 0Description
TRUEnever evaluated
FALSEevaluated 2299968 times by 1 test
Evaluated by:
  • test_bitmap
)
0-2299968
194 return
never executed: return r;
r;
never executed: return r;
0
195 bitmap_zero(b);-
196 if (l == 0
l == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 2299967 times by 1 test
Evaluated by:
  • test_bitmap
)
1-2299967
197 return
executed 1 time by 1 test: return 0;
Executed by:
  • test_bitmap
0;
executed 1 time by 1 test: return 0;
Executed by:
  • test_bitmap
1
198 b->top = offset = ((l + ((sizeof(u_int)) - 1)) / (sizeof(u_int))) - 1;-
199 shift = ((l + ((sizeof(u_int)) - 1)) % (sizeof(u_int))) * 8;-
200 for (i = 0; i < l
i < lDescription
TRUEevaluated 29338991 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 2299967 times by 1 test
Evaluated by:
  • test_bitmap
; i++) {
2299967-29338991
201 b->d[offset] |= (u_int)s[i] << shift;-
202 if (shift == 0
shift == 0Description
TRUEevaluated 8129915 times by 1 test
Evaluated by:
  • test_bitmap
FALSEevaluated 21209076 times by 1 test
Evaluated by:
  • test_bitmap
) {
8129915-21209076
203 offset--;-
204 shift = (sizeof(u_int) * 8) - 8;-
205 }
executed 8129915 times by 1 test: end of block
Executed by:
  • test_bitmap
else
8129915
206 shift -= 8;
executed 21209076 times by 1 test: shift -= 8;
Executed by:
  • test_bitmap
21209076
207 }-
208 retop(b);-
209 return
executed 2299967 times by 1 test: return 0;
Executed by:
  • test_bitmap
0;
executed 2299967 times by 1 test: return 0;
Executed by:
  • test_bitmap
2299967
210}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2