OpenCoverage

fmt_scaled.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/openbsd-compat/fmt_scaled.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8typedef enum {-
9 NONE = 0, KILO = 1, MEGA = 2, GIGA = 3, TERA = 4, PETA = 5, EXA = 6-
10} unit_type;-
11-
12-
13static unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA };-
14static char scale_chars[] = "BKMGTPE";-
15static long long scale_factors[] = {-
16 1LL,-
17 1024LL,-
18 1024LL*1024,-
19 1024LL*1024*1024,-
20 1024LL*1024*1024*1024,-
21 1024LL*1024*1024*1024*1024,-
22 1024LL*1024*1024*1024*1024*1024,-
23};-
24-
25-
26-
27-
28-
29-
30-
31int-
32scan_scaled(char *scaled, long long *result)-
33{-
34 char *p = scaled;-
35 int sign = 0;-
36 unsigned int i, ndigits = 0, fract_digits = 0;-
37 long long scale_fact = 1, whole = 0, fpart = 0;-
38-
39-
40 while (-
41 (((
((( (unsigned ...& ~0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
42 (unsigned char)*p
((( (unsigned ...& ~0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
43 ) & ~0x7f) == 0)
((( (unsigned ...& ~0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
44 && -
45 ((*
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
__ctype_b_loc ())[(int) ((
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
46 (unsigned char)*p
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
47 ))] & (unsigned short int) _ISspace)
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
48 )-
49 ++
never executed: ++p;
p;
never executed: ++p;
0
50-
51-
52 while (*
*p == '-'Description
TRUEnever evaluated
FALSEnever evaluated
p == '-'
*p == '-'Description
TRUEnever evaluated
FALSEnever evaluated
|| *
*p == '+'Description
TRUEnever evaluated
FALSEnever evaluated
p == '+'
*p == '+'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
53 if (*
*p == '-'Description
TRUEnever evaluated
FALSEnever evaluated
p == '-'
*p == '-'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
54 if (sign
signDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
55 -
56 (*__errno_location ()) -
57 = -
58 22-
59 ;-
60 return
never executed: return -1;
-1;
never executed: return -1;
0
61 }-
62 sign = -1;-
63 ++p;-
64 }
never executed: end of block
else if (*
*p == '+'Description
TRUEnever evaluated
FALSEnever evaluated
p == '+'
*p == '+'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
65 if (sign
signDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
66 -
67 (*__errno_location ()) -
68 = -
69 22-
70 ;-
71 return
never executed: return -1;
-1;
never executed: return -1;
0
72 }-
73 sign = +1;-
74 ++p;-
75 }
never executed: end of block
0
76 }
never executed: end of block
0
77-
78-
79-
80-
81-
82-
83 for (; -
84 (((
((( (unsigned ...& ~0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
85 (unsigned char)*p
((( (unsigned ...& ~0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
86 ) & ~0x7f) == 0)
((( (unsigned ...& ~0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
87 &&-
88 (-
89 ((*
((*__ctype_b_l...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
__ctype_b_loc ())[(int) ((
((*__ctype_b_l...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
90 (unsigned char)*p
((*__ctype_b_l...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
91 ))] & (unsigned short int) _ISdigit)
((*__ctype_b_l...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
92 || *
*p=='.'Description
TRUEnever evaluated
FALSEnever evaluated
p=='.'
*p=='.'Description
TRUEnever evaluated
FALSEnever evaluated
); ++p) {
0
93 if (*
*p == '.'Description
TRUEnever evaluated
FALSEnever evaluated
p == '.'
*p == '.'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
94 if (fract_digits > 0
fract_digits > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
95 -
96 (*__errno_location ()) -
97 = -
98 22-
99 ;-
100 return
never executed: return -1;
-1;
never executed: return -1;
0
101 }-
102 fract_digits = 1;-
103 continue;
never executed: continue;
0
104 }-
105-
106 i = (*p) - '0';-
107 if (fract_digits > 0
fract_digits > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
108 if (fract_digits >= ((sizeof(units)/sizeof(units[0])) * 3)-1
fract_digits >...ts[0])) * 3)-1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
109-
110 continue;
never executed: continue;
0
111 fract_digits++;-
112 if (fpart > 0x7fffffffffffffffLL / 10
fpart > 0x7fff...fffffffLL / 10Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
113 -
114 (*__errno_location ()) -
115 = -
116 34-
117 ;-
118 return
never executed: return -1;
-1;
never executed: return -1;
0
119 }-
120 fpart *= 10;-
121 if (i > 0x7fffffffffffffffLL - fpart
i > 0x7fffffff...ffffLL - fpartDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
122 -
123 (*__errno_location ()) -
124 = -
125 34-
126 ;-
127 return
never executed: return -1;
-1;
never executed: return -1;
0
128 }-
129 fpart += i;-
130 }
never executed: end of block
else {
0
131 if (++
++ndigits >= (...nits[0])) * 3)Description
TRUEnever evaluated
FALSEnever evaluated
ndigits >= ((sizeof(units)/sizeof(units[0])) * 3)
++ndigits >= (...nits[0])) * 3)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
132 -
133 (*__errno_location ()) -
134 = -
135 34-
136 ;-
137 return
never executed: return -1;
-1;
never executed: return -1;
0
138 }-
139 if (whole > 0x7fffffffffffffffLL / 10
whole > 0x7fff...fffffffLL / 10Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
140 -
141 (*__errno_location ()) -
142 = -
143 34-
144 ;-
145 return
never executed: return -1;
-1;
never executed: return -1;
0
146 }-
147 whole *= 10;-
148 if (i > 0x7fffffffffffffffLL - whole
i > 0x7fffffff...ffffLL - wholeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
149 -
150 (*__errno_location ()) -
151 = -
152 34-
153 ;-
154 return
never executed: return -1;
-1;
never executed: return -1;
0
155 }-
156 whole += i;-
157 }
never executed: end of block
0
158 }-
159-
160 if (sign
signDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
161 whole *= sign;-
162 fpart *= sign;-
163 }
never executed: end of block
0
164-
165-
166 if (!*p
!*pDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
167 *result = whole;-
168 return
never executed: return 0;
0;
never executed: return 0;
0
169 }-
170-
171-
172 for (i = 0; i < (sizeof(units)/sizeof(units[0]))
i < (sizeof(un...eof(units[0]))Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
173-
174-
175 if (*
*p == scale_chars[i]Description
TRUEnever evaluated
FALSEnever evaluated
p == scale_chars[i]
*p == scale_chars[i]Description
TRUEnever evaluated
FALSEnever evaluated
||
0
176 *
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
p ==
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
0
177 (__extension__ ({ int __res; if (sizeof (
sizeof ( (unsi...chars[i] ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
178 (unsigned char)scale_chars[i]
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
sizeof ( (unsi...chars[i] ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
179 ) > 1) { if (__builtin_constant_p (
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...ale_chars[i] )Description
TRUEnever evaluated
FALSEnever evaluated
0
180 (unsigned char)scale_chars[i]
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...ale_chars[i] )Description
TRUEnever evaluated
FALSEnever evaluated
0
181 )) { int __c = (
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
0
182 (unsigned char)scale_chars[i]
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
0
183 ); __res = __c < -128
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
|| __c > 255
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower (
never executed: __res = tolower ( (unsigned char)scale_chars[i] );
0
184 (unsigned char)scale_chars[i]
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
never executed: __res = tolower ( (unsigned char)scale_chars[i] );
0
185 ); } else __res = (*__ctype_tolower_loc ())[(int) (
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
never executed: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)scale_chars[i] )];
0
186 (unsigned char)scale_chars[i]
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
never executed: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)scale_chars[i] )];
0
187 )]; __res; }))
*p == (__exten...)]; __res; }))Description
TRUEnever evaluated
FALSEnever evaluated
0
188 ) {-
189-
190-
191 if (-
192 ((*
((*__ctype_b_l...int) _ISalnum)Description
TRUEnever evaluated
FALSEnever evaluated
__ctype_b_loc ())[(int) ((
((*__ctype_b_l...int) _ISalnum)Description
TRUEnever evaluated
FALSEnever evaluated
0
193 (unsigned char)*(p+1)
((*__ctype_b_l...int) _ISalnum)Description
TRUEnever evaluated
FALSEnever evaluated
0
194 ))] & (unsigned short int) _ISalnum)
((*__ctype_b_l...int) _ISalnum)Description
TRUEnever evaluated
FALSEnever evaluated
0
195 ) {-
196 -
197 (*__errno_location ()) -
198 = -
199 22-
200 ;-
201 return
never executed: return -1;
-1;
never executed: return -1;
0
202 }-
203 scale_fact = scale_factors[i];-
204-
205-
206 if (whole > 0x7fffffffffffffffLL / scale_fact
whole > 0x7fff...L / scale_factDescription
TRUEnever evaluated
FALSEnever evaluated
||
0
207 whole <
whole < (-0x7f...) / scale_factDescription
TRUEnever evaluated
FALSEnever evaluated
0
208 (-0x7fffffffffffffffLL - 1LL)
whole < (-0x7f...) / scale_factDescription
TRUEnever evaluated
FALSEnever evaluated
0
209 / scale_fact
whole < (-0x7f...) / scale_factDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
210 -
211 (*__errno_location ()) -
212 = -
213 34-
214 ;-
215 return
never executed: return -1;
-1;
never executed: return -1;
0
216 }-
217-
218-
219 whole *= scale_fact;-
220-
221-
222-
223-
224 while (fpart >= 0x7fffffffffffffffLL / scale_fact
fpart >= 0x7ff...L / scale_factDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
225 fpart /= 10;-
226 fract_digits--;-
227 }
never executed: end of block
0
228 fpart *= scale_fact;-
229 if (fract_digits > 0
fract_digits > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
230 for (i = 0; i < fract_digits -1
i < fract_digits -1Description
TRUEnever evaluated
FALSEnever evaluated
; i++)
0
231 fpart /= 10;
never executed: fpart /= 10;
0
232 }
never executed: end of block
0
233 whole += fpart;-
234 *result = whole;-
235 return
never executed: return 0;
0;
never executed: return 0;
0
236 }-
237 }
never executed: end of block
0
238-
239-
240 -
241(*__errno_location ()) -
242 = -
243 22-
244 ;-
245 return
never executed: return -1;
-1;
never executed: return -1;
0
246}-
247-
248-
249-
250-
251-
252int-
253fmt_scaled(long long number, char *result)-
254{-
255 long long abval, fract = 0;-
256 unsigned int i;-
257 unit_type unit = NONE;-
258-
259 abval = llabs(number);-
260-
261-
262-
263-
264 if (abval < 0
abval < 0Description
TRUEnever evaluated
FALSEnever evaluated
|| abval / 1024 >= scale_factors[(sizeof(units)/sizeof(units[0]))-1]
abval / 1024 >...(units[0]))-1]Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
265 -
266 (*__errno_location ()) -
267 = -
268 34-
269 ;-
270 return
never executed: return -1;
-1;
never executed: return -1;
0
271 }-
272-
273-
274 for (i = 0; i < (sizeof(units)/sizeof(units[0]))
i < (sizeof(un...eof(units[0]))Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
275 if (abval/1024 < scale_factors[i]
abval/1024 < scale_factors[i]Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
276 unit = units[i];-
277 fract = (
(i == 0)Description
TRUEnever evaluated
FALSEnever evaluated
i == 0)
(i == 0)Description
TRUEnever evaluated
FALSEnever evaluated
? 0 : abval % scale_factors[i];
0
278 number /= scale_factors[i];-
279 if (i > 0
i > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
280 fract /= scale_factors[i - 1];
never executed: fract /= scale_factors[i - 1];
0
281 break;
never executed: break;
0
282 }-
283 }
never executed: end of block
0
284-
285 fract = (10 * fract + 512) / 1024;-
286-
287 if (fract >= 10
fract >= 10Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
288 if (number >= 0
number >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
289 number++;
never executed: number++;
0
290 else-
291 number--;
never executed: number--;
0
292 fract = 0;-
293 }
never executed: end of block
else if (fract < 0
fract < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
294-
295 fract = 0;-
296 }
never executed: end of block
0
297-
298 if (number == 0
number == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
299 strlcpy(result, "0B", 7);
never executed: strlcpy(result, "0B", 7);
0
300 else if (unit == NONE
unit == NONEDescription
TRUEnever evaluated
FALSEnever evaluated
|| number >= 100
number >= 100Description
TRUEnever evaluated
FALSEnever evaluated
|| number <= -100
number <= -100Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
301 if (fract >= 5
fract >= 5Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
302 if (number >= 0
number >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
303 number++;
never executed: number++;
0
304 else-
305 number--;
never executed: number--;
0
306 }-
307 (void)snprintf(result, 7, "%lld%c",-
308 number, scale_chars[unit]);-
309 }
never executed: end of block
else
0
310 (
never executed: (void)snprintf(result, 7, "%lld.%1lld%c", number, fract, scale_chars[unit]);
void)snprintf(result, 7, "%lld.%1lld%c",
never executed: (void)snprintf(result, 7, "%lld.%1lld%c", number, fract, scale_chars[unit]);
0
311 number, fract, scale_chars[unit]);
never executed: (void)snprintf(result, 7, "%lld.%1lld%c", number, fract, scale_chars[unit]);
0
312-
313 return
never executed: return 0;
0;
never executed: return 0;
0
314}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2