Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssh/src/bitmap.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | struct bitmap { | - | ||||||||||||||||||
12 | u_int *d; | - | ||||||||||||||||||
13 | size_t len; | - | ||||||||||||||||||
14 | size_t top; | - | ||||||||||||||||||
15 | }; | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | struct bitmap * | - | ||||||||||||||||||
18 | bitmap_new(void) | - | ||||||||||||||||||
19 | { | - | ||||||||||||||||||
20 | struct bitmap *ret; | - | ||||||||||||||||||
21 | - | |||||||||||||||||||
22 | if ((
| 0-1 | ||||||||||||||||||
23 | ((void *)0)
| 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 ((
| 0-1 | ||||||||||||||||||
29 | ((void *)0)
| 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: ret;return ret; Executed by:
executed 1 time by 1 test: return ret; Executed by:
| 1 | ||||||||||||||||||
39 | } | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | void | - | ||||||||||||||||||
42 | bitmap_free(struct bitmap *b) | - | ||||||||||||||||||
43 | { | - | ||||||||||||||||||
44 | if (b !=
| 0-1 | ||||||||||||||||||
45 | ((void *)0)
| 0-1 | ||||||||||||||||||
46 | && b->d !=
| 0-1 | ||||||||||||||||||
47 | ((void *)0)
| 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:
| 1 | ||||||||||||||||||
55 | free(b); | - | ||||||||||||||||||
56 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | void | - | ||||||||||||||||||
59 | bitmap_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:
| 6899905 | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | int | - | ||||||||||||||||||
66 | bitmap_test_bit(struct bitmap *b, u_int n) | - | ||||||||||||||||||
67 | { | - | ||||||||||||||||||
68 | if (b->top >= b->len
| 0-903887424 | ||||||||||||||||||
69 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
70 | if (b->len == 0
| 0-903887424 | ||||||||||||||||||
71 | return executed 91167192 times by 1 test: 0;return 0; Executed by:
executed 91167192 times by 1 test: return 0; Executed by:
| 91167192 | ||||||||||||||||||
72 | return executed 812720232 times by 1 test: (b->d[n / (sizeof(u_int) * 8)] >> (n & ((u_int)(sizeof(u_int) * 8) - 1))) & 1;return (b->d[n / (sizeof(u_int) * 8)] >> (n & ((u_int)(sizeof(u_int) * 8) - 1))) & 1; Executed by:
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:
| 812720232 | ||||||||||||||||||
73 | } | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | static int | - | ||||||||||||||||||
76 | reserve(struct bitmap *b, u_int n) | - | ||||||||||||||||||
77 | { | - | ||||||||||||||||||
78 | u_int *tmp; | - | ||||||||||||||||||
79 | size_t nlen; | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | if (b->top >= b->len
| 0-310443408 | ||||||||||||||||||
82 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
83 | nlen = (n / (sizeof(u_int) * 8)) + 1; | - | ||||||||||||||||||
84 | if (b->len < nlen
| 4-310443404 | ||||||||||||||||||
85 | if ((
| 0-4 | ||||||||||||||||||
86 | nlen, (sizeof(u_int)))) ==
| 0-4 | ||||||||||||||||||
87 | ((void *)0)
| 0-4 | ||||||||||||||||||
88 | ) | - | ||||||||||||||||||
89 | return never executed: -1;return -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:
| 4 | ||||||||||||||||||
93 | return executed 310443408 times by 1 test: 0;return 0; Executed by:
executed 310443408 times by 1 test: return 0; Executed by:
| 310443408 | ||||||||||||||||||
94 | } | - | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | int | - | ||||||||||||||||||
97 | bitmap_set_bit(struct bitmap *b, u_int n) | - | ||||||||||||||||||
98 | { | - | ||||||||||||||||||
99 | int r; | - | ||||||||||||||||||
100 | size_t offset; | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | if ((
| 0-308143440 | ||||||||||||||||||
103 | return never executed: r;return r; never executed: return r; | 0 | ||||||||||||||||||
104 | offset = n / (sizeof(u_int) * 8); | - | ||||||||||||||||||
105 | if (offset > b->top
| 6490723-301652717 | ||||||||||||||||||
106 | b->top = offset; executed 6490723 times by 1 test: b->top = offset; Executed by:
| 6490723 | ||||||||||||||||||
107 | b->d[offset] |= (u_int)1 << (n & ((u_int)(sizeof(u_int) * 8) - 1)); | - | ||||||||||||||||||
108 | return executed 308143440 times by 1 test: 0;return 0; Executed by:
executed 308143440 times by 1 test: return 0; Executed by:
| 308143440 | ||||||||||||||||||
109 | } | - | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | - | |||||||||||||||||||
112 | static void | - | ||||||||||||||||||
113 | retop(struct bitmap *b) | - | ||||||||||||||||||
114 | { | - | ||||||||||||||||||
115 | if (b->top >= b->len
| 0-18347471 | ||||||||||||||||||
116 | return; never executed: return; | 0 | ||||||||||||||||||
117 | while (b->top > 0
| 6-18167793 | ||||||||||||||||||
118 | b->top--; executed 6 times by 1 test: b->top--; Executed by:
| 6 | ||||||||||||||||||
119 | } executed 18347471 times by 1 test: end of block Executed by:
| 18347471 | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | void | - | ||||||||||||||||||
122 | bitmap_clear_bit(struct bitmap *b, u_int n) | - | ||||||||||||||||||
123 | { | - | ||||||||||||||||||
124 | size_t offset; | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | if (b->top >= b->len
| 0-6847632 | ||||||||||||||||||
127 | return; never executed: return; | 0 | ||||||||||||||||||
128 | offset = n / (sizeof(u_int) * 8); | - | ||||||||||||||||||
129 | if (offset > b->top
| 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:
| 6847632 | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | size_t | - | ||||||||||||||||||
137 | bitmap_nbits(struct bitmap *b) | - | ||||||||||||||||||
138 | { | - | ||||||||||||||||||
139 | size_t bits; | - | ||||||||||||||||||
140 | u_int w; | - | ||||||||||||||||||
141 | - | |||||||||||||||||||
142 | retop(b); | - | ||||||||||||||||||
143 | if (b->top >= b->len
| 0-9199872 | ||||||||||||||||||
144 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
145 | if (b->len == 0
| 0-9199872 | ||||||||||||||||||
146 | return executed 4 times by 1 test: 0;return 0; Executed by:
executed 4 times by 1 test: return 0; Executed by:
| 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)))
| 9199868-134459152 | ||||||||||||||||||
151 | w <<= 1; | - | ||||||||||||||||||
152 | bits--; | - | ||||||||||||||||||
153 | } executed 134459152 times by 1 test: end of block Executed by:
| 134459152 | ||||||||||||||||||
154 | return executed 9199868 times by 1 test: bits;return bits; Executed by:
executed 9199868 times by 1 test: return bits; Executed by:
| 9199868 | ||||||||||||||||||
155 | } | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | size_t | - | ||||||||||||||||||
158 | bitmap_nbytes(struct bitmap *b) | - | ||||||||||||||||||
159 | { | - | ||||||||||||||||||
160 | return executed 6899904 times by 1 test: (bitmap_nbits(b) + 7) / 8;return (bitmap_nbits(b) + 7) / 8; Executed by:
executed 6899904 times by 1 test: return (bitmap_nbits(b) + 7) / 8; Executed by:
| 6899904 | ||||||||||||||||||
161 | } | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | int | - | ||||||||||||||||||
164 | bitmap_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
| 0-2299968 | ||||||||||||||||||
170 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
171 | if (l > need
| 0-2299968 | ||||||||||||||||||
172 | l = need; executed 2299968 times by 1 test: l = need; Executed by:
| 2299968 | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | for (i = k = 0; i < b->top + 1
| 2299968-8129916 | ||||||||||||||||||
175 | for (j = 0; j < (sizeof(u_int))
| 6522524-30946383 | ||||||||||||||||||
176 | if (k >= l
| 1607392-29338991 | ||||||||||||||||||
177 | break; executed 1607392 times by 1 test: break; Executed by:
| 1607392 | ||||||||||||||||||
178 | s[need - 1 - k++] = (b->d[i] >> (j * 8)) & 0xff; | - | ||||||||||||||||||
179 | } executed 29338991 times by 1 test: end of block Executed by:
| 29338991 | ||||||||||||||||||
180 | } executed 8129916 times by 1 test: end of block Executed by:
| 8129916 | ||||||||||||||||||
181 | return executed 2299968 times by 1 test: 0;return 0; Executed by:
executed 2299968 times by 1 test: return 0; Executed by:
| 2299968 | ||||||||||||||||||
182 | } | - | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | int | - | ||||||||||||||||||
185 | bitmap_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
| 0-2299968 | ||||||||||||||||||
192 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
193 | if ((
| 0-2299968 | ||||||||||||||||||
194 | return never executed: r;return r; never executed: return r; | 0 | ||||||||||||||||||
195 | bitmap_zero(b); | - | ||||||||||||||||||
196 | if (l == 0
| 1-2299967 | ||||||||||||||||||
197 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 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
| 2299967-29338991 | ||||||||||||||||||
201 | b->d[offset] |= (u_int)s[i] << shift; | - | ||||||||||||||||||
202 | if (shift == 0
| 8129915-21209076 | ||||||||||||||||||
203 | offset--; | - | ||||||||||||||||||
204 | shift = (sizeof(u_int) * 8) - 8; | - | ||||||||||||||||||
205 | } executed 8129915 times by 1 test: elseend of block Executed by:
| 8129915 | ||||||||||||||||||
206 | shift -= 8; executed 21209076 times by 1 test: shift -= 8; Executed by:
| 21209076 | ||||||||||||||||||
207 | } | - | ||||||||||||||||||
208 | retop(b); | - | ||||||||||||||||||
209 | return executed 2299967 times by 1 test: 0;return 0; Executed by:
executed 2299967 times by 1 test: return 0; Executed by:
| 2299967 | ||||||||||||||||||
210 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |