OpenCoverage

numfmt.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/numfmt.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* Reformat numbers like 11505426432 to the more human-readable 11G-
2 Copyright (C) 2012-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17#include <config.h>-
18#include <float.h>-
19#include <getopt.h>-
20#include <stdio.h>-
21#include <sys/types.h>-
22#include <langinfo.h>-
23-
24#include "mbsalign.h"-
25#include "argmatch.h"-
26#include "c-ctype.h"-
27#include "die.h"-
28#include "error.h"-
29#include "quote.h"-
30#include "system.h"-
31#include "xstrtol.h"-
32#include "xstrndup.h"-
33-
34#include "set-fields.h"-
35-
36#if HAVE_FPSETPREC-
37# include <ieeefp.h>-
38#endif-
39-
40/* The official name of this program (e.g., no 'g' prefix). */-
41#define PROGRAM_NAME "numfmt"-
42-
43#define AUTHORS proper_name ("Assaf Gordon")-
44-
45/* Exit code when some numbers fail to convert. */-
46enum { EXIT_CONVERSION_WARNINGS = 2 };-
47-
48enum-
49{-
50 FROM_OPTION = CHAR_MAX + 1,-
51 FROM_UNIT_OPTION,-
52 TO_OPTION,-
53 TO_UNIT_OPTION,-
54 ROUND_OPTION,-
55 SUFFIX_OPTION,-
56 GROUPING_OPTION,-
57 PADDING_OPTION,-
58 FIELD_OPTION,-
59 DEBUG_OPTION,-
60 DEV_DEBUG_OPTION,-
61 HEADER_OPTION,-
62 FORMAT_OPTION,-
63 INVALID_OPTION-
64};-
65-
66enum scale_type-
67{-
68 scale_none, /* the default: no scaling. */-
69 scale_auto, /* --from only. */-
70 scale_SI,-
71 scale_IEC,-
72 scale_IEC_I /* 'i' suffix is required. */-
73};-
74-
75static char const *const scale_from_args[] =-
76{-
77 "none", "auto", "si", "iec", "iec-i", NULL-
78};-
79-
80static enum scale_type const scale_from_types[] =-
81{-
82 scale_none, scale_auto, scale_SI, scale_IEC, scale_IEC_I-
83};-
84-
85static char const *const scale_to_args[] =-
86{-
87 "none", "si", "iec", "iec-i", NULL-
88};-
89-
90static enum scale_type const scale_to_types[] =-
91{-
92 scale_none, scale_SI, scale_IEC, scale_IEC_I-
93};-
94-
95-
96enum round_type-
97{-
98 round_ceiling,-
99 round_floor,-
100 round_from_zero,-
101 round_to_zero,-
102 round_nearest,-
103};-
104-
105static char const *const round_args[] =-
106{-
107 "up", "down", "from-zero", "towards-zero", "nearest", NULL-
108};-
109-
110static enum round_type const round_types[] =-
111{-
112 round_ceiling, round_floor, round_from_zero, round_to_zero, round_nearest-
113};-
114-
115-
116enum inval_type-
117{-
118 inval_abort,-
119 inval_fail,-
120 inval_warn,-
121 inval_ignore-
122};-
123-
124static char const *const inval_args[] =-
125{-
126 "abort", "fail", "warn", "ignore", NULL-
127};-
128-
129static enum inval_type const inval_types[] =-
130{-
131 inval_abort, inval_fail, inval_warn, inval_ignore-
132};-
133-
134static struct option const longopts[] =-
135{-
136 {"from", required_argument, NULL, FROM_OPTION},-
137 {"from-unit", required_argument, NULL, FROM_UNIT_OPTION},-
138 {"to", required_argument, NULL, TO_OPTION},-
139 {"to-unit", required_argument, NULL, TO_UNIT_OPTION},-
140 {"round", required_argument, NULL, ROUND_OPTION},-
141 {"padding", required_argument, NULL, PADDING_OPTION},-
142 {"suffix", required_argument, NULL, SUFFIX_OPTION},-
143 {"grouping", no_argument, NULL, GROUPING_OPTION},-
144 {"delimiter", required_argument, NULL, 'd'},-
145 {"field", required_argument, NULL, FIELD_OPTION},-
146 {"debug", no_argument, NULL, DEBUG_OPTION},-
147 {"-debug", no_argument, NULL, DEV_DEBUG_OPTION},-
148 {"header", optional_argument, NULL, HEADER_OPTION},-
149 {"format", required_argument, NULL, FORMAT_OPTION},-
150 {"invalid", required_argument, NULL, INVALID_OPTION},-
151 {"zero-terminated", no_argument, NULL, 'z'},-
152 {GETOPT_HELP_OPTION_DECL},-
153 {GETOPT_VERSION_OPTION_DECL},-
154 {NULL, 0, NULL, 0}-
155};-
156-
157/* If delimiter has this value, blanks separate fields. */-
158enum { DELIMITER_DEFAULT = CHAR_MAX + 1 };-
159-
160/* Maximum number of digits we can safely handle-
161 without precision loss, if scaling is 'none'. */-
162enum { MAX_UNSCALED_DIGITS = LDBL_DIG };-
163-
164/* Maximum number of digits we can work with.-
165 This is equivalent to 999Y.-
166 NOTE: 'long double' can handle more than that, but there's-
167 no official suffix assigned beyond Yotta (1000^8). */-
168enum { MAX_ACCEPTABLE_DIGITS = 27 };-
169-
170static enum scale_type scale_from = scale_none;-
171static enum scale_type scale_to = scale_none;-
172static enum round_type round_style = round_from_zero;-
173static enum inval_type inval_style = inval_abort;-
174static const char *suffix = NULL;-
175static uintmax_t from_unit_size = 1;-
176static uintmax_t to_unit_size = 1;-
177static int grouping = 0;-
178static char *padding_buffer = NULL;-
179static size_t padding_buffer_size = 0;-
180static long int padding_width = 0;-
181static long int zero_padding_width = 0;-
182static long int user_precision = -1;-
183static const char *format_str = NULL;-
184static char *format_str_prefix = NULL;-
185static char *format_str_suffix = NULL;-
186-
187/* By default, any conversion error will terminate the program. */-
188static int conv_exit_code = EXIT_CONVERSION_WARNINGS;-
189-
190-
191/* auto-pad each line based on skipped whitespace. */-
192static int auto_padding = 0;-
193static mbs_align_t padding_alignment = MBS_ALIGN_RIGHT;-
194-
195/* field delimiter */-
196static int delimiter = DELIMITER_DEFAULT;-
197-
198/* line delimiter. */-
199static unsigned char line_delim = '\n';-
200-
201/* if non-zero, the first 'header' lines from STDIN are skipped. */-
202static uintmax_t header = 0;-
203-
204/* Debug for users: print warnings to STDERR about possible-
205 error (similar to sort's debug). */-
206static bool debug;-
207-
208/* will be set according to the current locale. */-
209static const char *decimal_point;-
210static int decimal_point_length;-
211-
212/* debugging for developers. Enables devmsg(). */-
213static bool dev_debug = false;-
214-
215-
216static inline int-
217default_scale_base (enum scale_type scale)-
218{-
219 switch (scale)-
220 {-
221 case scale_IEC:
executed 87 times by 1 test: case scale_IEC:
Executed by:
  • numfmt
87
222 case scale_IEC_I:
executed 22 times by 1 test: case scale_IEC_I:
Executed by:
  • numfmt
22
223 return 1024;
executed 109 times by 1 test: return 1024;
Executed by:
  • numfmt
109
224-
225 case scale_none:
executed 351 times by 1 test: case scale_none:
Executed by:
  • numfmt
351
226 case scale_auto:
executed 30 times by 1 test: case scale_auto:
Executed by:
  • numfmt
30
227 case scale_SI:
executed 326 times by 1 test: case scale_SI:
Executed by:
  • numfmt
326
228 default:
never executed: default:
0
229 return 1000;
executed 707 times by 1 test: return 1000;
Executed by:
  • numfmt
707
230 }-
231}-
232-
233static inline int-
234valid_suffix (const char suf)-
235{-
236 static const char *valid_suffixes = "KMGTPEZY";-
237 return (strchr (valid_suffixes, suf) != NULL);
executed 180 times by 1 test: return ( (__extension__ (__builtin_constant_p ( suf ) && !__builtin_constant_p ( valid_suffixes ) && ( suf ) == '\0' ? (char *) __rawmemchr ( valid_suffixes , suf ) : __builtin_strchr ( valid_suffixes , suf ))) != ((void *)0) );
Executed by:
  • numfmt
180
238}-
239-
240static inline int-
241suffix_power (const char suf)-
242{-
243 switch (suf)-
244 {-
245 case 'K': /* kilo or kibi. */
executed 22 times by 1 test: case 'K':
Executed by:
  • numfmt
22
246 return 1;
executed 22 times by 1 test: return 1;
Executed by:
  • numfmt
22
247-
248 case 'M': /* mega or mebi. */
executed 35 times by 1 test: case 'M':
Executed by:
  • numfmt
35
249 return 2;
executed 35 times by 1 test: return 2;
Executed by:
  • numfmt
35
250-
251 case 'G': /* giga or gibi. */
executed 12 times by 1 test: case 'G':
Executed by:
  • numfmt
12
252 return 3;
executed 12 times by 1 test: return 3;
Executed by:
  • numfmt
12
253-
254 case 'T': /* tera or tebi. */
executed 8 times by 1 test: case 'T':
Executed by:
  • numfmt
8
255 return 4;
executed 8 times by 1 test: return 4;
Executed by:
  • numfmt
8
256-
257 case 'P': /* peta or pebi. */
executed 10 times by 1 test: case 'P':
Executed by:
  • numfmt
10
258 return 5;
executed 10 times by 1 test: return 5;
Executed by:
  • numfmt
10
259-
260 case 'E': /* exa or exbi. */
executed 9 times by 1 test: case 'E':
Executed by:
  • numfmt
9
261 return 6;
executed 9 times by 1 test: return 6;
Executed by:
  • numfmt
9
262-
263 case 'Z': /* zetta or 2**70. */
executed 10 times by 1 test: case 'Z':
Executed by:
  • numfmt
10
264 return 7;
executed 10 times by 1 test: return 7;
Executed by:
  • numfmt
10
265-
266 case 'Y': /* yotta or 2**80. */
executed 16 times by 1 test: case 'Y':
Executed by:
  • numfmt
16
267 return 8;
executed 16 times by 1 test: return 8;
Executed by:
  • numfmt
16
268-
269 default: /* should never happen. assert? */
never executed: default:
0
270 return 0;
never executed: return 0;
0
271 }-
272}-
273-
274static inline const char *-
275suffix_power_char (unsigned int power)-
276{-
277 switch (power)-
278 {-
279 case 0:
executed 14 times by 1 test: case 0:
Executed by:
  • numfmt
14
280 return "";
executed 14 times by 1 test: return "";
Executed by:
  • numfmt
14
281-
282 case 1:
executed 173 times by 1 test: case 1:
Executed by:
  • numfmt
173
283 return "K";
executed 173 times by 1 test: return "K";
Executed by:
  • numfmt
173
284-
285 case 2:
executed 26 times by 1 test: case 2:
Executed by:
  • numfmt
26
286 return "M";
executed 26 times by 1 test: return "M";
Executed by:
  • numfmt
26
287-
288 case 3:
executed 15 times by 1 test: case 3:
Executed by:
  • numfmt
15
289 return "G";
executed 15 times by 1 test: return "G";
Executed by:
  • numfmt
15
290-
291 case 4:
executed 9 times by 1 test: case 4:
Executed by:
  • numfmt
9
292 return "T";
executed 9 times by 1 test: return "T";
Executed by:
  • numfmt
9
293-
294 case 5:
executed 8 times by 1 test: case 5:
Executed by:
  • numfmt
8
295 return "P";
executed 8 times by 1 test: return "P";
Executed by:
  • numfmt
8
296-
297 case 6:
executed 11 times by 1 test: case 6:
Executed by:
  • numfmt
11
298 return "E";
executed 11 times by 1 test: return "E";
Executed by:
  • numfmt
11
299-
300 case 7:
executed 10 times by 1 test: case 7:
Executed by:
  • numfmt
10
301 return "Z";
executed 10 times by 1 test: return "Z";
Executed by:
  • numfmt
10
302-
303 case 8:
executed 15 times by 1 test: case 8:
Executed by:
  • numfmt
15
304 return "Y";
executed 15 times by 1 test: return "Y";
Executed by:
  • numfmt
15
305-
306 default:
never executed: default:
0
307 return "(error)";
never executed: return "(error)";
0
308 }-
309}-
310-
311/* Similar to 'powl(3)' but without requiring 'libm'. */-
312static long double-
313powerld (long double base, unsigned int x)-
314{-
315 long double result = base;-
316 if (x == 0)
x == 0Description
TRUEevaluated 662 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 725 times by 1 test
Evaluated by:
  • numfmt
662-725
317 return 1; /* note for test coverage: this is never
executed 662 times by 1 test: return 1;
Executed by:
  • numfmt
662
318 reached, as 'powerld' won't be called if-
319 there's no suffix, hence, no "power". */-
320-
321 /* TODO: check for overflow, inf? */-
322 while (--x)
--xDescription
TRUEevaluated 602 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 725 times by 1 test
Evaluated by:
  • numfmt
602-725
323 result *= base;
executed 602 times by 1 test: result *= base;
Executed by:
  • numfmt
602
324 return result;
executed 725 times by 1 test: return result;
Executed by:
  • numfmt
725
325}-
326-
327/* Similar to 'fabs(3)' but without requiring 'libm'. */-
328static inline long double-
329absld (long double val)-
330{-
331 return val < 0 ? -val : val;
executed 4894 times by 1 test: return val < 0 ? -val : val;
Executed by:
  • numfmt
4894
332}-
333-
334/* Scale down 'val', returns 'updated val' and 'x', such that-
335 val*base^X = original val-
336 Similar to "frexpl(3)" but without requiring 'libm',-
337 allowing only integer scale, limited functionality and error checking. */-
338static long double-
339expld (long double val, unsigned int base, unsigned int /*output */ *x)-
340{-
341 unsigned int power = 0;-
342-
343 if (val >= -LDBL_MAX && val <= LDBL_MAX)
val >= -1.1897...3176502e+4932LDescription
TRUEevaluated 731 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
val <= 1.18973...3176502e+4932LDescription
TRUEevaluated 731 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-731
344 {-
345 while (absld (val) >= base)
absld (val) >= baseDescription
TRUEevaluated 3325 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 731 times by 1 test
Evaluated by:
  • numfmt
731-3325
346 {-
347 ++power;-
348 val /= base;-
349 }
executed 3325 times by 1 test: end of block
Executed by:
  • numfmt
3325
350 }
executed 731 times by 1 test: end of block
Executed by:
  • numfmt
731
351 if (x)
xDescription
TRUEevaluated 731 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-731
352 *x = power;
executed 731 times by 1 test: *x = power;
Executed by:
  • numfmt
731
353 return val;
executed 731 times by 1 test: return val;
Executed by:
  • numfmt
731
354}-
355-
356/* EXTREMELY limited 'ceil' - without 'libm'.-
357 Assumes values that fit in intmax_t. */-
358static inline intmax_t-
359simple_round_ceiling (long double val)-
360{-
361 intmax_t intval = val;-
362 if (intval < val)
intval < valDescription
TRUEevaluated 72 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 335 times by 1 test
Evaluated by:
  • numfmt
72-335
363 intval++;
executed 72 times by 1 test: intval++;
Executed by:
  • numfmt
72
364 return intval;
executed 407 times by 1 test: return intval;
Executed by:
  • numfmt
407
365}-
366-
367/* EXTREMELY limited 'floor' - without 'libm'.-
368 Assumes values that fit in intmax_t. */-
369static inline intmax_t-
370simple_round_floor (long double val)-
371{-
372 return -simple_round_ceiling (-val);
executed 34 times by 1 test: return -simple_round_ceiling (-val);
Executed by:
  • numfmt
34
373}-
374-
375/* EXTREMELY limited 'round away from zero'.-
376 Assumes values that fit in intmax_t. */-
377static inline intmax_t-
378simple_round_from_zero (long double val)-
379{-
380 return val < 0 ? simple_round_floor (val) : simple_round_ceiling (val);
executed 369 times by 1 test: return val < 0 ? simple_round_floor (val) : simple_round_ceiling (val);
Executed by:
  • numfmt
369
381}-
382-
383/* EXTREMELY limited 'round away to zero'.-
384 Assumes values that fit in intmax_t. */-
385static inline intmax_t-
386simple_round_to_zero (long double val)-
387{-
388 return val;
executed 10 times by 1 test: return val;
Executed by:
  • numfmt
10
389}-
390-
391/* EXTREMELY limited 'round' - without 'libm'.-
392 Assumes values that fit in intmax_t. */-
393static inline intmax_t-
394simple_round_nearest (long double val)-
395{-
396 return val < 0 ? val - 0.5 : val + 0.5;
executed 19 times by 1 test: return val < 0 ? val - 0.5 : val + 0.5;
Executed by:
  • numfmt
19
397}-
398-
399static inline long double _GL_ATTRIBUTE_CONST-
400simple_round (long double val, enum round_type t)-
401{-
402 intmax_t rval;-
403 intmax_t intmax_mul = val / INTMAX_MAX;-
404 val -= (long double) INTMAX_MAX * intmax_mul;-
405-
406 switch (t)-
407 {-
408 case round_ceiling:
executed 14 times by 1 test: case round_ceiling:
Executed by:
  • numfmt
14
409 rval = simple_round_ceiling (val);-
410 break;
executed 14 times by 1 test: break;
Executed by:
  • numfmt
14
411-
412 case round_floor:
executed 24 times by 1 test: case round_floor:
Executed by:
  • numfmt
24
413 rval = simple_round_floor (val);-
414 break;
executed 24 times by 1 test: break;
Executed by:
  • numfmt
24
415-
416 case round_from_zero:
executed 369 times by 1 test: case round_from_zero:
Executed by:
  • numfmt
369
417 rval = simple_round_from_zero (val);-
418 break;
executed 369 times by 1 test: break;
Executed by:
  • numfmt
369
419-
420 case round_to_zero:
executed 10 times by 1 test: case round_to_zero:
Executed by:
  • numfmt
10
421 rval = simple_round_to_zero (val);-
422 break;
executed 10 times by 1 test: break;
Executed by:
  • numfmt
10
423-
424 case round_nearest:
executed 19 times by 1 test: case round_nearest:
Executed by:
  • numfmt
19
425 rval = simple_round_nearest (val);-
426 break;
executed 19 times by 1 test: break;
Executed by:
  • numfmt
19
427-
428 default:
never executed: default:
0
429 /* to silence the compiler - this should never happen. */-
430 return 0;
never executed: return 0;
0
431 }-
432-
433 return (long double) INTMAX_MAX * intmax_mul + rval;
executed 436 times by 1 test: return (long double) (9223372036854775807L) * intmax_mul + rval;
Executed by:
  • numfmt
436
434}-
435-
436enum simple_strtod_error-
437{-
438 SSE_OK = 0,-
439 SSE_OK_PRECISION_LOSS,-
440 SSE_OVERFLOW,-
441 SSE_INVALID_NUMBER,-
442-
443 /* the following are returned by 'simple_strtod_human'. */-
444 SSE_VALID_BUT_FORBIDDEN_SUFFIX,-
445 SSE_INVALID_SUFFIX,-
446 SSE_MISSING_I_SUFFIX-
447};-
448-
449/* Read an *integer* INPUT_STR,-
450 but return the integer value in a 'long double' VALUE-
451 hence, no UINTMAX_MAX limitation.-
452 NEGATIVE is updated, and is stored separately from the VALUE-
453 so that signbit() isn't required to determine the sign of -0..-
454 ENDPTR is required (unlike strtod) and is used to store a pointer-
455 to the character after the last character used in the conversion.-
456-
457 Note locale'd grouping is not supported,-
458 nor is skipping of white-space supported.-
459-
460 Returns:-
461 SSE_OK - valid number.-
462 SSE_OK_PRECISION_LOSS - if more than 18 digits were used.-
463 SSE_OVERFLOW - if more than 27 digits (999Y) were used.-
464 SSE_INVALID_NUMBER - if no digits were found. */-
465static enum simple_strtod_error-
466simple_strtod_int (const char *input_str,-
467 char **endptr, long double *value, bool *negative)-
468{-
469 enum simple_strtod_error e = SSE_OK;-
470-
471 long double val = 0;-
472 unsigned int digits = 0;-
473 bool found_digit = false;-
474-
475 if (*input_str == '-')
*input_str == '-'Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 570 times by 1 test
Evaluated by:
  • numfmt
33-570
476 {-
477 input_str++;-
478 *negative = true;-
479 }
executed 33 times by 1 test: end of block
Executed by:
  • numfmt
33
480 else-
481 *negative = false;
executed 570 times by 1 test: *negative = 0 ;
Executed by:
  • numfmt
570
482-
483 *endptr = (char *) input_str;-
484 while (*endptr && c_isdigit (**endptr))
*endptrDescription
TRUEevaluated 2944 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
c_isdigit (**endptr)Description
TRUEevaluated 2345 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 599 times by 1 test
Evaluated by:
  • numfmt
0-2944
485 {-
486 int digit = (**endptr) - '0';-
487-
488 found_digit = true;-
489-
490 if (val || digit)
valDescription
TRUEevaluated 1675 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 670 times by 1 test
Evaluated by:
  • numfmt
digitDescription
TRUEevaluated 534 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 136 times by 1 test
Evaluated by:
  • numfmt
136-1675
491 digits++;
executed 2209 times by 1 test: digits++;
Executed by:
  • numfmt
2209
492-
493 if (digits > MAX_UNSCALED_DIGITS)
digits > MAX_UNSCALED_DIGITSDescription
TRUEevaluated 97 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2248 times by 1 test
Evaluated by:
  • numfmt
97-2248
494 e = SSE_OK_PRECISION_LOSS;
executed 97 times by 1 test: e = SSE_OK_PRECISION_LOSS;
Executed by:
  • numfmt
97
495-
496 if (digits > MAX_ACCEPTABLE_DIGITS)
digits > MAX_ACCEPTABLE_DIGITSDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2341 times by 1 test
Evaluated by:
  • numfmt
4-2341
497 return SSE_OVERFLOW;
executed 4 times by 1 test: return SSE_OVERFLOW;
Executed by:
  • numfmt
4
498-
499 val *= 10;-
500 val += digit;-
501-
502 ++(*endptr);-
503 }
executed 2341 times by 1 test: end of block
Executed by:
  • numfmt
2341
504 if (! found_digit
! found_digitDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 579 times by 1 test
Evaluated by:
  • numfmt
20-579
505 && ! STREQ_LEN (*endptr, decimal_point, decimal_point_length))
never executed: __result = (((const unsigned char *) (const char *) ( *endptr ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( decimal_point ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
! ( (__extensi...ngth ))) == 0)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
__builtin_cons...point_length )Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • numfmt
__builtin_cons..._p ( *endptr )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( *endp...oint_length ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...ecimal_point )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( decim...oint_length ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-20
506 return SSE_INVALID_NUMBER;
executed 17 times by 1 test: return SSE_INVALID_NUMBER;
Executed by:
  • numfmt
17
507 if (*negative)
*negativeDescription
TRUEevaluated 33 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 549 times by 1 test
Evaluated by:
  • numfmt
33-549
508 val = -val;
executed 33 times by 1 test: val = -val;
Executed by:
  • numfmt
33
509-
510 if (value)
valueDescription
TRUEevaluated 582 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-582
511 *value = val;
executed 582 times by 1 test: *value = val;
Executed by:
  • numfmt
582
512-
513 return e;
executed 582 times by 1 test: return e;
Executed by:
  • numfmt
582
514}-
515-
516/* Read a floating-point INPUT_STR represented as "NNNN[.NNNNN]",-
517 and return the value in a 'long double' VALUE.-
518 ENDPTR is required (unlike strtod) and is used to store a pointer-
519 to the character after the last character used in the conversion.-
520 PRECISION is optional and used to indicate fractions are present.-
521-
522 Note locale'd grouping is not supported,-
523 nor is skipping of white-space supported.-
524-
525 Returns:-
526 SSE_OK - valid number.-
527 SSE_OK_PRECISION_LOSS - if more than 18 digits were used.-
528 SSE_OVERFLOW - if more than 27 digits (999Y) were used.-
529 SSE_INVALID_NUMBER - if no digits were found. */-
530static enum simple_strtod_error-
531simple_strtod_float (const char *input_str,-
532 char **endptr,-
533 long double *value,-
534 size_t *precision)-
535{-
536 bool negative;-
537 enum simple_strtod_error e = SSE_OK;-
538-
539 if (precision)
precisionDescription
TRUEevaluated 535 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-535
540 *precision = 0;
executed 535 times by 1 test: *precision = 0;
Executed by:
  • numfmt
535
541-
542 /* TODO: accept locale'd grouped values for the integral part. */-
543 e = simple_strtod_int (input_str, endptr, value, &negative);-
544 if (e != SSE_OK && e != SSE_OK_PRECISION_LOSS)
e != SSE_OKDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 503 times by 1 test
Evaluated by:
  • numfmt
e != SSE_OK_PRECISION_LOSSDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 16 times by 1 test
Evaluated by:
  • numfmt
16-503
545 return e;
executed 16 times by 1 test: return e;
Executed by:
  • numfmt
16
546-
547 /* optional decimal point + fraction. */-
548 if (STREQ_LEN (*endptr, decimal_point, decimal_point_length))
never executed: __result = (((const unsigned char *) (const char *) ( *endptr ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( decimal_point ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
( (__extension...ngth ))) == 0)Description
TRUEevaluated 68 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 451 times by 1 test
Evaluated by:
  • numfmt
__builtin_cons...point_length )Description
TRUEnever evaluated
FALSEevaluated 519 times by 1 test
Evaluated by:
  • numfmt
__builtin_cons..._p ( *endptr )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( *endp...oint_length ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...ecimal_point )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( decim...oint_length ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-519
549 {-
550 char *ptr2;-
551 long double val_frac = 0;-
552 bool neg_frac;-
553-
554 (*endptr) += decimal_point_length;-
555 enum simple_strtod_error e2 =-
556 simple_strtod_int (*endptr, &ptr2, &val_frac, &neg_frac);-
557 if (e2 != SSE_OK && e2 != SSE_OK_PRECISION_LOSS)
e2 != SSE_OKDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 62 times by 1 test
Evaluated by:
  • numfmt
e2 != SSE_OK_PRECISION_LOSSDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-62
558 return e2;
executed 5 times by 1 test: return e2;
Executed by:
  • numfmt
5
559 if (e2 == SSE_OK_PRECISION_LOSS)
e2 == SSE_OK_PRECISION_LOSSDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 62 times by 1 test
Evaluated by:
  • numfmt
1-62
560 e = e2; /* propagate warning. */
executed 1 time by 1 test: e = e2;
Executed by:
  • numfmt
1
561 if (neg_frac)
neg_fracDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 62 times by 1 test
Evaluated by:
  • numfmt
1-62
562 return SSE_INVALID_NUMBER;
executed 1 time by 1 test: return SSE_INVALID_NUMBER;
Executed by:
  • numfmt
1
563-
564 /* number of digits in the fractions. */-
565 size_t exponent = ptr2 - *endptr;-
566-
567 val_frac = ((long double) val_frac) / powerld (10, exponent);-
568-
569 /* TODO: detect loss of precision (only really 18 digits-
570 of precision across all digits (before and after '.')). */-
571 if (value)
valueDescription
TRUEevaluated 62 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-62
572 {-
573 if (negative)
negativeDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 41 times by 1 test
Evaluated by:
  • numfmt
21-41
574 *value -= val_frac;
executed 21 times by 1 test: *value -= val_frac;
Executed by:
  • numfmt
21
575 else-
576 *value += val_frac;
executed 41 times by 1 test: *value += val_frac;
Executed by:
  • numfmt
41
577 }-
578-
579 if (precision)
precisionDescription
TRUEevaluated 62 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-62
580 *precision = exponent;
executed 62 times by 1 test: *precision = exponent;
Executed by:
  • numfmt
62
581-
582 *endptr = ptr2;-
583 }
executed 62 times by 1 test: end of block
Executed by:
  • numfmt
62
584 return e;
executed 513 times by 1 test: return e;
Executed by:
  • numfmt
513
585}-
586-
587/* Read a 'human' INPUT_STR represented as "NNNN[.NNNNN] + suffix",-
588 and return the value in a 'long double' VALUE,-
589 with the precision of the input returned in PRECISION.-
590 ENDPTR is required (unlike strtod) and is used to store a pointer-
591 to the character after the last character used in the conversion.-
592 ALLOWED_SCALING determines the scaling supported.-
593-
594 TODO:-
595 support locale'd grouping-
596 accept scentific and hex floats (probably use strtold directly)-
597-
598 Returns:-
599 SSE_OK - valid number.-
600 SSE_OK_PRECISION_LOSS - if more than LDBL_DIG digits were used.-
601 SSE_OVERFLOW - if more than 27 digits (999Y) were used.-
602 SSE_INVALID_NUMBER - if no digits were found.-
603 SSE_VALID_BUT_FORBIDDEN_SUFFIX-
604 SSE_INVALID_SUFFIX-
605 SSE_MISSING_I_SUFFIX */-
606static enum simple_strtod_error-
607simple_strtod_human (const char *input_str,-
608 char **endptr, long double *value, size_t *precision,-
609 enum scale_type allowed_scaling)-
610{-
611 int power = 0;-
612 /* 'scale_auto' is checked below. */-
613 int scale_base = default_scale_base (allowed_scaling);-
614-
615 devmsg ("simple_strtod_human:\n input string: %s\n"
executed 11 times by 1 test: fprintf ( stderr , "simple_strtod_human:\n input string: %s\n" " locale decimal-point: %s\n" " MAX_UNSCALED_DIGITS: %d\n", quote_n (0, input_str), quote_n (1, decimal_point), MAX_UNSCALED_DIGITS);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 524 times by 1 test
Evaluated by:
  • numfmt
11-524
616 " locale decimal-point: %s\n"-
617 " MAX_UNSCALED_DIGITS: %d\n",-
618 quote_n (0, input_str),-
619 quote_n (1, decimal_point),-
620 MAX_UNSCALED_DIGITS);-
621-
622 enum simple_strtod_error e =-
623 simple_strtod_float (input_str, endptr, value, precision);-
624 if (e != SSE_OK && e != SSE_OK_PRECISION_LOSS)
e != SSE_OKDescription
TRUEevaluated 39 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 496 times by 1 test
Evaluated by:
  • numfmt
e != SSE_OK_PRECISION_LOSSDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
17-496
625 return e;
executed 22 times by 1 test: return e;
Executed by:
  • numfmt
22
626-
627 devmsg (" parsed numeric value: %Lf\n"
executed 11 times by 1 test: fprintf ( stderr , " parsed numeric value: %Lf\n" " input precision = %d\n", *value, (int)*precision);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 502 times by 1 test
Evaluated by:
  • numfmt
11-502
628 " input precision = %d\n", *value, (int)*precision);-
629-
630 if (**endptr != '\0')
**endptr != '\0'Description
TRUEevaluated 180 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 333 times by 1 test
Evaluated by:
  • numfmt
180-333
631 {-
632 /* process suffix. */-
633-
634 /* Skip any blanks between the number and suffix. */-
635 while (isblank (to_uchar (**endptr)))
((*__ctype_b_l...int) _ISblank)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 180 times by 1 test
Evaluated by:
  • numfmt
2-180
636 (*endptr)++;
executed 2 times by 1 test: (*endptr)++;
Executed by:
  • numfmt
2
637-
638 if (!valid_suffix (**endptr))
!valid_suffix (**endptr)Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 126 times by 1 test
Evaluated by:
  • numfmt
54-126
639 return SSE_INVALID_SUFFIX;
executed 54 times by 1 test: return SSE_INVALID_SUFFIX;
Executed by:
  • numfmt
54
640-
641 if (allowed_scaling == scale_none)
allowed_scaling == scale_noneDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 122 times by 1 test
Evaluated by:
  • numfmt
4-122
642 return SSE_VALID_BUT_FORBIDDEN_SUFFIX;
executed 4 times by 1 test: return SSE_VALID_BUT_FORBIDDEN_SUFFIX;
Executed by:
  • numfmt
4
643-
644 power = suffix_power (**endptr);-
645 (*endptr)++; /* skip first suffix character. */-
646-
647 if (allowed_scaling == scale_auto && **endptr == 'i')
allowed_scaling == scale_autoDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 97 times by 1 test
Evaluated by:
  • numfmt
**endptr == 'i'Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 12 times by 1 test
Evaluated by:
  • numfmt
12-97
648 {-
649 /* auto-scaling enabled, and the first suffix character-
650 is followed by an 'i' (e.g. Ki, Mi, Gi). */-
651 scale_base = 1024;-
652 (*endptr)++; /* skip second ('i') suffix character. */-
653 devmsg (" Auto-scaling, found 'i', switching to base %d\n",
executed 1 time by 1 test: fprintf ( stderr , " Auto-scaling, found 'i', switching to base %d\n", scale_base);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 12 times by 1 test
Evaluated by:
  • numfmt
1-12
654 scale_base);-
655 }
executed 13 times by 1 test: end of block
Executed by:
  • numfmt
13
656-
657 *precision = 0; /* Reset, to select precision based on scale. */-
658 }
executed 122 times by 1 test: end of block
Executed by:
  • numfmt
122
659-
660 if (allowed_scaling == scale_IEC_I)
allowed_scaling == scale_IEC_IDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 444 times by 1 test
Evaluated by:
  • numfmt
11-444
661 {-
662 if (**endptr == 'i')
**endptr == 'i'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
2-9
663 (*endptr)++;
executed 9 times by 1 test: (*endptr)++;
Executed by:
  • numfmt
9
664 else-
665 return SSE_MISSING_I_SUFFIX;
executed 2 times by 1 test: return SSE_MISSING_I_SUFFIX;
Executed by:
  • numfmt
2
666 }-
667-
668 long double multiplier = powerld (scale_base, power);-
669-
670 devmsg (" suffix power=%d^%d = %Lf\n", scale_base, power, multiplier);
executed 11 times by 1 test: fprintf ( stderr , " suffix power=%d^%d = %Lf\n", scale_base, power, multiplier);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 442 times by 1 test
Evaluated by:
  • numfmt
11-442
671-
672 /* TODO: detect loss of precision and overflows. */-
673 (*value) = (*value) * multiplier;-
674-
675 devmsg (" returning value: %Lf (%LG)\n", *value, *value);
executed 11 times by 1 test: fprintf ( stderr , " returning value: %Lf (%LG)\n", *value, *value);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 442 times by 1 test
Evaluated by:
  • numfmt
11-442
676-
677 return e;
executed 453 times by 1 test: return e;
Executed by:
  • numfmt
453
678}-
679-
680-
681static void-
682simple_strtod_fatal (enum simple_strtod_error err, char const *input_str)-
683{-
684 char const *msgid = NULL;-
685-
686 switch (err)-
687 {-
688 case SSE_OK_PRECISION_LOSS:
never executed: case SSE_OK_PRECISION_LOSS:
0
689 case SSE_OK:
never executed: case SSE_OK:
0
690 /* should never happen - this function isn't called when OK. */-
691 abort ();
never executed: abort ();
0
692-
693 case SSE_OVERFLOW:
code before this statement never executed: case SSE_OVERFLOW:
executed 4 times by 1 test: case SSE_OVERFLOW:
Executed by:
  • numfmt
0-4
694 msgid = N_("value too large to be converted: %s");-
695 break;
executed 4 times by 1 test: break;
Executed by:
  • numfmt
4
696-
697 case SSE_INVALID_NUMBER:
executed 18 times by 1 test: case SSE_INVALID_NUMBER:
Executed by:
  • numfmt
18
698 msgid = N_("invalid number: %s");-
699 break;
executed 18 times by 1 test: break;
Executed by:
  • numfmt
18
700-
701 case SSE_VALID_BUT_FORBIDDEN_SUFFIX:
executed 4 times by 1 test: case SSE_VALID_BUT_FORBIDDEN_SUFFIX:
Executed by:
  • numfmt
4
702 msgid = N_("rejecting suffix in input: %s (consider using --from)");-
703 break;
executed 4 times by 1 test: break;
Executed by:
  • numfmt
4
704-
705 case SSE_INVALID_SUFFIX:
executed 54 times by 1 test: case SSE_INVALID_SUFFIX:
Executed by:
  • numfmt
54
706 msgid = N_("invalid suffix in input: %s");-
707 break;
executed 54 times by 1 test: break;
Executed by:
  • numfmt
54
708-
709 case SSE_MISSING_I_SUFFIX:
executed 2 times by 1 test: case SSE_MISSING_I_SUFFIX:
Executed by:
  • numfmt
2
710 msgid = N_("missing 'i' suffix in input: %s (e.g Ki/Mi/Gi)");-
711 break;
executed 2 times by 1 test: break;
Executed by:
  • numfmt
2
712-
713 }-
714-
715 if (inval_style != inval_ignore)
inval_style != inval_ignoreDescription
TRUEevaluated 80 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
2-80
716 error (conv_exit_code, 0, gettext (msgid), quote (input_str));
executed 80 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), msgid , 5) , quote (input_str));
Executed by:
  • numfmt
80
717}
executed 15 times by 1 test: end of block
Executed by:
  • numfmt
15
718-
719/* Convert VAL to a human format string in BUF. */-
720static void-
721double_to_human (long double val, int precision,-
722 char *buf, size_t buf_size,-
723 enum scale_type scale, int group, enum round_type round)-
724{-
725 int num_size;-
726 char fmt[64];-
727 verify (sizeof (fmt) > (INT_BUFSIZE_BOUND (zero_padding_width)-
728 + INT_BUFSIZE_BOUND (precision)-
729 + 10 /* for %.Lf etc. */));-
730-
731 char *pfmt = fmt;-
732 *pfmt++ = '%';-
733-
734 if (group)
groupDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 428 times by 1 test
Evaluated by:
  • numfmt
8-428
735 *pfmt++ = '\'';
executed 8 times by 1 test: *pfmt++ = '\'';
Executed by:
  • numfmt
8
736-
737 if (zero_padding_width)
zero_padding_widthDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 432 times by 1 test
Evaluated by:
  • numfmt
4-432
738 pfmt += snprintf (pfmt, sizeof (fmt) - 2, "0%ld", zero_padding_width);
executed 4 times by 1 test: pfmt += snprintf (pfmt, sizeof (fmt) - 2, "0%ld", zero_padding_width);
Executed by:
  • numfmt
4
739-
740 devmsg ("double_to_human:\n");
executed 11 times by 1 test: fprintf ( stderr , "double_to_human:\n");
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 425 times by 1 test
Evaluated by:
  • numfmt
11-425
741-
742 if (scale == scale_none)
scale == scale_noneDescription
TRUEevaluated 155 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 281 times by 1 test
Evaluated by:
  • numfmt
155-281
743 {-
744 val *= powerld (10, precision);-
745 val = simple_round (val, round);-
746 val /= powerld (10, precision);-
747-
748 devmsg ((group) ?
executed 9 times by 1 test: fprintf ( stderr , (group) ? " no scaling, returning (grouped) value: %'.*Lf\n" : " no scaling, returning value: %.*Lf\n", precision, val);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 146 times by 1 test
Evaluated by:
  • numfmt
9-146
749 " no scaling, returning (grouped) value: %'.*Lf\n" :-
750 " no scaling, returning value: %.*Lf\n", precision, val);-
751-
752 stpcpy (pfmt, ".*Lf");-
753-
754 num_size = snprintf (buf, buf_size, fmt, precision, val);-
755 if (num_size < 0 || num_size >= (int) buf_size)
num_size < 0Description
TRUEnever evaluated
FALSEevaluated 155 times by 1 test
Evaluated by:
  • numfmt
num_size >= (int) buf_sizeDescription
TRUEnever evaluated
FALSEevaluated 155 times by 1 test
Evaluated by:
  • numfmt
0-155
756 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"failed to prepare value '%Lf' for printing\", 5), val), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
757 _("failed to prepare value '%Lf' for printing"), val);
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"failed to prepare value '%Lf' for printing\", 5), val), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
758 return;
executed 155 times by 1 test: return;
Executed by:
  • numfmt
155
759 }-
760-
761 /* Scaling requested by user. */-
762 double scale_base = default_scale_base (scale);-
763-
764 /* Normalize val to scale. */-
765 unsigned int power = 0;-
766 val = expld (val, scale_base, &power);-
767 devmsg (" scaled value to %Lf * %0.f ^ %u\n", val, scale_base, power);
executed 2 times by 1 test: fprintf ( stderr , " scaled value to %Lf * %0.f ^ %u\n", val, scale_base, power);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 279 times by 1 test
Evaluated by:
  • numfmt
2-279
768-
769 /* Perform rounding. */-
770 unsigned int power_adjust = 0;-
771 if (user_precision != -1)
user_precision != -1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 279 times by 1 test
Evaluated by:
  • numfmt
2-279
772 power_adjust = MIN (power * 3, user_precision);
executed 2 times by 1 test: power_adjust = ((( power * 3 )<( user_precision ))?( power * 3 ):( user_precision )) ;
Executed by:
  • numfmt
(( power * 3 )...r_precision ))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
0-2
773 else if (absld (val) < 10)
absld (val) < 10Description
TRUEevaluated 221 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 58 times by 1 test
Evaluated by:
  • numfmt
58-221
774 {-
775 /* for values less than 10, we allow one decimal-point digit,-
776 so adjust before rounding. */-
777 power_adjust = 1;-
778 }
executed 221 times by 1 test: end of block
Executed by:
  • numfmt
221
779-
780 val *= powerld (10, power_adjust);-
781 val = simple_round (val, round);-
782 val /= powerld (10, power_adjust);-
783-
784 /* two special cases after rounding:-
785 1. a "999.99" can turn into 1000 - so scale down-
786 2. a "9.99" can turn into 10 - so don't display decimal-point. */-
787 if (absld (val) >= scale_base)
absld (val) >= scale_baseDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 280 times by 1 test
Evaluated by:
  • numfmt
1-280
788 {-
789 val /= scale_base;-
790 power++;-
791 }
executed 1 time by 1 test: end of block
Executed by:
  • numfmt
1
792-
793 /* should "7.0" be printed as "7" ?-
794 if removing the ".0" is preferred, enable the fourth condition. */-
795 int show_decimal_point = (val != 0) && (absld (val) < 10) && (power > 0);
(val != 0)Description
TRUEevaluated 278 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
(absld (val) < 10)Description
TRUEevaluated 218 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 60 times by 1 test
Evaluated by:
  • numfmt
(power > 0)Description
TRUEevaluated 217 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-278
796 /* && (absld (val) > simple_round_floor (val))) */-
797-
798 devmsg (" after rounding, value=%Lf * %0.f ^ %u\n", val, scale_base, power);
executed 2 times by 1 test: fprintf ( stderr , " after rounding, value=%Lf * %0.f ^ %u\n", val, scale_base, power);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 279 times by 1 test
Evaluated by:
  • numfmt
2-279
799-
800 stpcpy (pfmt, ".*Lf%s");-
801-
802 int prec = user_precision == -1 ? show_decimal_point : user_precision;
user_precision == -1Description
TRUEevaluated 279 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
2-279
803-
804 /* buf_size - 1 used here to ensure place for possible scale_IEC_I suffix. */-
805 num_size = snprintf (buf, buf_size - 1, fmt, prec, val,-
806 suffix_power_char (power));-
807 if (num_size < 0 || num_size >= (int) buf_size - 1)
num_size < 0Description
TRUEnever evaluated
FALSEevaluated 281 times by 1 test
Evaluated by:
  • numfmt
num_size >= (int) buf_size - 1Description
TRUEnever evaluated
FALSEevaluated 281 times by 1 test
Evaluated by:
  • numfmt
0-281
808 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"failed to prepare value '%Lf' for printing\", 5), val), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
809 _("failed to prepare value '%Lf' for printing"), val);
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"failed to prepare value '%Lf' for printing\", 5), val), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "failed to prepare value '%Lf' for printing" , 5) , val), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
810-
811 if (scale == scale_IEC_I && power > 0)
scale == scale_IEC_IDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 270 times by 1 test
Evaluated by:
  • numfmt
power > 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-270
812 strncat (buf, "i", buf_size - num_size - 1);
executed 10 times by 1 test: strncat (buf, "i", buf_size - num_size - 1);
Executed by:
  • numfmt
10
813-
814 devmsg (" returning value: %s\n", quote (buf));
executed 2 times by 1 test: fprintf ( stderr , " returning value: %s\n", quote (buf));
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 279 times by 1 test
Evaluated by:
  • numfmt
2-279
815-
816 return;
executed 281 times by 1 test: return;
Executed by:
  • numfmt
281
817}-
818-
819/* Convert a string of decimal digits, N_STRING, with an optional suffix-
820 to an integral value. Suffixes are handled as with --from=auto.-
821 Upon successful conversion, return that value.-
822 If it cannot be converted, give a diagnostic and exit. */-
823static uintmax_t-
824unit_to_umax (const char *n_string)-
825{-
826 strtol_error s_err;-
827 const char *c_string = n_string;-
828 char *t_string = NULL;-
829 size_t n_len = strlen (n_string);-
830 char *end = NULL;-
831 uintmax_t n;-
832 const char *suffixes = "KMGTPEZY";-
833-
834 /* Adjust suffixes so K=1000, Ki=1024, KiB=invalid. */-
835 if (n_len && ! c_isdigit (n_string[n_len - 1]))
n_lenDescription
TRUEevaluated 45 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
! c_isdigit (n...ng[n_len - 1])Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 35 times by 1 test
Evaluated by:
  • numfmt
0-45
836 {-
837 t_string = xmalloc (n_len + 2);-
838 end = t_string + n_len - 1;-
839 memcpy (t_string, n_string, n_len);-
840-
841 if (*end == 'i' && 2 <= n_len && ! c_isdigit (*(end - 1)))
*end == 'i'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 7 times by 1 test
Evaluated by:
  • numfmt
2 <= n_lenDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
! c_isdigit (*(end - 1))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-7
842 *end = '\0';
executed 1 time by 1 test: *end = '\0';
Executed by:
  • numfmt
1
843 else-
844 {-
845 *++end = 'B';-
846 *++end = '\0';-
847 suffixes = "KMGTPEZY0";-
848 }
executed 9 times by 1 test: end of block
Executed by:
  • numfmt
9
849-
850 c_string = t_string;-
851 }
executed 10 times by 1 test: end of block
Executed by:
  • numfmt
10
852-
853 s_err = xstrtoumax (c_string, &end, 10, &n, suffixes);-
854-
855 if (s_err != LONGINT_OK || *end || n == 0)
s_err != LONGINT_OKDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 38 times by 1 test
Evaluated by:
  • numfmt
*endDescription
TRUEnever evaluated
FALSEevaluated 38 times by 1 test
Evaluated by:
  • numfmt
n == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 36 times by 1 test
Evaluated by:
  • numfmt
0-38
856 {-
857 free (t_string);-
858 die (EXIT_FAILURE, 0, _("invalid unit size: %s"), quote (n_string));-
859 }
never executed: end of block
0
860-
861 free (t_string);-
862-
863 return n;
executed 36 times by 1 test: return n;
Executed by:
  • numfmt
36
864}-
865-
866-
867static void-
868setup_padding_buffer (size_t min_size)-
869{-
870 if (padding_buffer_size > min_size)
padding_buffer_size > min_sizeDescription
TRUEevaluated 132 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 790 times by 1 test
Evaluated by:
  • numfmt
132-790
871 return;
executed 132 times by 1 test: return;
Executed by:
  • numfmt
132
872-
873 padding_buffer_size = min_size + 1;-
874 padding_buffer = xrealloc (padding_buffer, padding_buffer_size);-
875}
executed 790 times by 1 test: end of block
Executed by:
  • numfmt
790
876-
877void-
878usage (int status)-
879{-
880 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 10 times by 1 test
Evaluated by:
  • numfmt
10-17
881 emit_try_help ();
executed 17 times by 1 test: end of block
Executed by:
  • numfmt
17
882 else-
883 {-
884 printf (_("\-
885Usage: %s [OPTION]... [NUMBER]...\n\-
886"), program_name);-
887 fputs (_("\-
888Reformat NUMBER(s), or the numbers from standard input if none are specified.\n\-
889"), stdout);-
890 emit_mandatory_arg_note ();-
891 fputs (_("\-
892 --debug print warnings about invalid input\n\-
893"), stdout);-
894 fputs (_("\-
895 -d, --delimiter=X use X instead of whitespace for field delimiter\n\-
896"), stdout);-
897 fputs (_("\-
898 --field=FIELDS replace the numbers in these input fields (default=1)\n\-
899 see FIELDS below\n\-
900"), stdout);-
901 fputs (_("\-
902 --format=FORMAT use printf style floating-point FORMAT;\n\-
903 see FORMAT below for details\n\-
904"), stdout);-
905 fputs (_("\-
906 --from=UNIT auto-scale input numbers to UNITs; default is 'none';\n\-
907 see UNIT below\n\-
908"), stdout);-
909 fputs (_("\-
910 --from-unit=N specify the input unit size (instead of the default 1)\n\-
911"), stdout);-
912 fputs (_("\-
913 --grouping use locale-defined grouping of digits, e.g. 1,000,000\n\-
914 (which means it has no effect in the C/POSIX locale)\n\-
915"), stdout);-
916 fputs (_("\-
917 --header[=N] print (without converting) the first N header lines;\n\-
918 N defaults to 1 if not specified\n\-
919"), stdout);-
920 fputs (_("\-
921 --invalid=MODE failure mode for invalid numbers: MODE can be:\n\-
922 abort (default), fail, warn, ignore\n\-
923"), stdout);-
924 fputs (_("\-
925 --padding=N pad the output to N characters; positive N will\n\-
926 right-align; negative N will left-align;\n\-
927 padding is ignored if the output is wider than N;\n\-
928 the default is to automatically pad if a whitespace\n\-
929 is found\n\-
930"), stdout);-
931 fputs (_("\-
932 --round=METHOD use METHOD for rounding when scaling; METHOD can be:\n\-
933 up, down, from-zero (default), towards-zero, nearest\n\-
934"), stdout);-
935 fputs (_("\-
936 --suffix=SUFFIX add SUFFIX to output numbers, and accept optional\n\-
937 SUFFIX in input numbers\n\-
938"), stdout);-
939 fputs (_("\-
940 --to=UNIT auto-scale output numbers to UNITs; see UNIT below\n\-
941"), stdout);-
942 fputs (_("\-
943 --to-unit=N the output unit size (instead of the default 1)\n\-
944"), stdout);-
945 fputs (_("\-
946 -z, --zero-terminated line delimiter is NUL, not newline\n\-
947"), stdout);-
948 fputs (HELP_OPTION_DESCRIPTION, stdout);-
949 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
950-
951 fputs (_("\-
952\n\-
953UNIT options:\n"), stdout);-
954 fputs (_("\-
955 none no auto-scaling is done; suffixes will trigger an error\n\-
956"), stdout);-
957 fputs (_("\-
958 auto accept optional single/two letter suffix:\n\-
959 1K = 1000,\n\-
960 1Ki = 1024,\n\-
961 1M = 1000000,\n\-
962 1Mi = 1048576,\n"), stdout);-
963 fputs (_("\-
964 si accept optional single letter suffix:\n\-
965 1K = 1000,\n\-
966 1M = 1000000,\n\-
967 ...\n"), stdout);-
968 fputs (_("\-
969 iec accept optional single letter suffix:\n\-
970 1K = 1024,\n\-
971 1M = 1048576,\n\-
972 ...\n"), stdout);-
973 fputs (_("\-
974 iec-i accept optional two-letter suffix:\n\-
975 1Ki = 1024,\n\-
976 1Mi = 1048576,\n\-
977 ...\n"), stdout);-
978-
979 fputs (_("\n\-
980FIELDS supports cut(1) style field ranges:\n\-
981 N N'th field, counted from 1\n\-
982 N- from N'th field, to end of line\n\-
983 N-M from N'th to M'th field (inclusive)\n\-
984 -M from first to M'th field (inclusive)\n\-
985 - all fields\n\-
986Multiple fields/ranges can be separated with commas\n\-
987"), stdout);-
988-
989 fputs (_("\n\-
990FORMAT must be suitable for printing one floating-point argument '%f'.\n\-
991Optional quote (%'f) will enable --grouping (if supported by current locale).\n\-
992Optional width value (%10f) will pad output. Optional zero (%010f) width\n\-
993will zero pad the number. Optional negative values (%-10f) will left align.\n\-
994Optional precision (%.1f) will override the input determined precision.\n\-
995"), stdout);-
996-
997 printf (_("\n\-
998Exit status is 0 if all input numbers were successfully converted.\n\-
999By default, %s will stop at the first conversion error with exit status 2.\n\-
1000With --invalid='fail' a warning is printed for each conversion error\n\-
1001and the exit status is 2. With --invalid='warn' each conversion error is\n\-
1002diagnosed, but the exit status is 0. With --invalid='ignore' conversion\n\-
1003errors are not diagnosed and the exit status is 0.\n\-
1004"), program_name);-
1005-
1006 printf (_("\n\-
1007Examples:\n\-
1008 $ %s --to=si 1000\n\-
1009 -> \"1.0K\"\n\-
1010 $ %s --to=iec 2048\n\-
1011 -> \"2.0K\"\n\-
1012 $ %s --to=iec-i 4096\n\-
1013 -> \"4.0Ki\"\n\-
1014 $ echo 1K | %s --from=si\n\-
1015 -> \"1000\"\n\-
1016 $ echo 1K | %s --from=iec\n\-
1017 -> \"1024\"\n\-
1018 $ df -B1 | %s --header --field 2-4 --to=si\n\-
1019 $ ls -l | %s --header --field 5 --to=iec\n\-
1020 $ ls -lh | %s --header --field 5 --from=iec --padding=10\n\-
1021 $ ls -lh | %s --header --field 5 --from=iec --format %%10f\n"),-
1022 program_name, program_name, program_name,-
1023 program_name, program_name, program_name,-
1024 program_name, program_name, program_name);-
1025 emit_ancillary_info (PROGRAM_NAME);-
1026 }
executed 10 times by 1 test: end of block
Executed by:
  • numfmt
10
1027 exit (status);
executed 27 times by 1 test: exit (status);
Executed by:
  • numfmt
27
1028}-
1029-
1030/* Given 'fmt' (a printf(3) compatible format string), extracts the following:-
1031 1. padding (e.g. %20f)-
1032 2. alignment (e.g. %-20f)-
1033 3. grouping (e.g. %'f)-
1034-
1035 Only a limited subset of printf(3) syntax is supported.-
1036-
1037 TODO:-
1038 support %e %g etc. rather than just %f-
1039-
1040 NOTES:-
1041 1. This function sets the global variables:-
1042 padding_width, padding_alignment, grouping,-
1043 format_str_prefix, format_str_suffix-
1044 2. The function aborts on any errors. */-
1045static void-
1046parse_format_string (char const *fmt)-
1047{-
1048 size_t i;-
1049 size_t prefix_len = 0;-
1050 size_t suffix_pos;-
1051 long int pad = 0;-
1052 char *endptr = NULL;-
1053 bool zero_padding = false;-
1054-
1055 for (i = 0; !(fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
fmt[i] == '%'Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 33 times by 1 test
Evaluated by:
  • numfmt
fmt[i + 1] != '%'Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-39
1056 {-
1057 if (!fmt[i])
!fmt[i]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 32 times by 1 test
Evaluated by:
  • numfmt
2-32
1058 die (EXIT_FAILURE, 0,
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"format %s has no %% directive\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "format %s has no %% directive" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "format %s has no %% directive" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
2
1059 _("format %s has no %% directive"), quote (fmt));
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"format %s has no %% directive\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "format %s has no %% directive" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "format %s has no %% directive" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
2
1060 prefix_len++;-
1061 }
executed 32 times by 1 test: end of block
Executed by:
  • numfmt
32
1062-
1063 i++;-
1064 while (true)-
1065 {-
1066 size_t skip = strspn (fmt + i, " ");-
1067 i += skip;-
1068 if (fmt[i] == '\'')
fmt[i] == '\''Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 45 times by 1 test
Evaluated by:
  • numfmt
6-45
1069 {-
1070 grouping = 1;-
1071 i++;-
1072 }
executed 6 times by 1 test: end of block
Executed by:
  • numfmt
6
1073 else if (fmt[i] == '0')
fmt[i] == '0'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 41 times by 1 test
Evaluated by:
  • numfmt
4-41
1074 {-
1075 zero_padding = true;-
1076 i++;-
1077 }
executed 4 times by 1 test: end of block
Executed by:
  • numfmt
4
1078 else if (! skip)
! skipDescription
TRUEevaluated 38 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
3-38
1079 break;
executed 38 times by 1 test: break;
Executed by:
  • numfmt
38
1080 }
executed 13 times by 1 test: end of block
Executed by:
  • numfmt
13
1081-
1082 errno = 0;-
1083 pad = strtol (fmt + i, &endptr, 10);-
1084 if (errno == ERANGE)
(*__errno_location ()) == 34Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 37 times by 1 test
Evaluated by:
  • numfmt
1-37
1085 die (EXIT_FAILURE, 0,
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid format %s (width overflow)\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid format %s (width overflow)" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid format %s (width overflow)" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
1
1086 _("invalid format %s (width overflow)"), quote (fmt));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid format %s (width overflow)\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid format %s (width overflow)" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid format %s (width overflow)" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
1
1087-
1088 if (endptr != (fmt + i) && pad != 0)
endptr != (fmt + i)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 20 times by 1 test
Evaluated by:
  • numfmt
pad != 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-20
1089 {-
1090 if (debug && padding_width && !(zero_padding && pad > 0))
debugDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 16 times by 1 test
Evaluated by:
  • numfmt
padding_widthDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
zero_paddingDescription
TRUEnever evaluated
FALSEnever evaluated
pad > 0Description
TRUEnever evaluated
FALSEnever evaluated
0-16
1091 error (0, 0, _("--format padding overriding --padding"));
never executed: error (0, 0, dcgettext (((void *)0), "--format padding overriding --padding" , 5) );
0
1092-
1093 if (pad < 0)
pad < 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
6-11
1094 {-
1095 padding_alignment = MBS_ALIGN_LEFT;-
1096 padding_width = -pad;-
1097 }
executed 6 times by 1 test: end of block
Executed by:
  • numfmt
6
1098 else-
1099 {-
1100 if (zero_padding)
zero_paddingDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 7 times by 1 test
Evaluated by:
  • numfmt
4-7
1101 zero_padding_width = pad;
executed 4 times by 1 test: zero_padding_width = pad;
Executed by:
  • numfmt
4
1102 else-
1103 padding_width = pad;
executed 7 times by 1 test: padding_width = pad;
Executed by:
  • numfmt
7
1104 }-
1105-
1106 }-
1107 i = endptr - fmt;-
1108-
1109 if (fmt[i] == '\0')
fmt[i] == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 36 times by 1 test
Evaluated by:
  • numfmt
1-36
1110 die (EXIT_FAILURE, 0, _("format %s ends in %%"), quote (fmt));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"format %s ends in %%\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "format %s ends in %%" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "format %s ends in %%" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • numfmt
1
1111-
1112 if (fmt[i] == '.')
fmt[i] == '.'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 27 times by 1 test
Evaluated by:
  • numfmt
9-27
1113 {-
1114 i++;-
1115 errno = 0;-
1116 user_precision = strtol (fmt + i, &endptr, 10);-
1117 if (errno == ERANGE || user_precision < 0 || SIZE_MAX < user_precision
(*__errno_location ()) == 34Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
user_precision < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
(1844674407370...user_precisionDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
0-9
1118 || isblank (fmt[i]) || fmt[i] == '+')
((*__ctype_b_l...int) _ISblank)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 7 times by 1 test
Evaluated by:
  • numfmt
fmt[i] == '+'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 6 times by 1 test
Evaluated by:
  • numfmt
1-7
1119 {-
1120 /* Note we disallow negative user_precision to be-
1121 consistent with printf(1). POSIX states that-
1122 negative precision is only supported (and ignored)-
1123 when used with '.*f'. glibc at least will malform-
1124 output when passed a direct negative precision. */-
1125 die (EXIT_FAILURE, 0,-
1126 _("invalid precision in format %s"), quote (fmt));-
1127 }
never executed: end of block
0
1128 i = endptr - fmt;-
1129 }
executed 6 times by 1 test: end of block
Executed by:
  • numfmt
6
1130-
1131 if (fmt[i] != 'f')
fmt[i] != 'f'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 31 times by 1 test
Evaluated by:
  • numfmt
2-31
1132 die (EXIT_FAILURE, 0, _("invalid format %s,"
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid format %s,\" \" directive must be %%[0]['][-][N][.][N]f\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, d....][N]f" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid format %s," " directive must be %%[0]['][-][N][.][N]f" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
2
1133 " directive must be %%[0]['][-][N][.][N]f"),
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid format %s,\" \" directive must be %%[0]['][-][N][.][N]f\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, d....][N]f" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid format %s," " directive must be %%[0]['][-][N][.][N]f" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
2
1134 quote (fmt));
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid format %s,\" \" directive must be %%[0]['][-][N][.][N]f\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, d....][N]f" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid format %s," " directive must be %%[0]['][-][N][.][N]f" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
2
1135 i++;-
1136 suffix_pos = i;-
1137-
1138 for (; fmt[i] != '\0'; i += (fmt[i] == '%') + 1)
fmt[i] != '\0'Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 30 times by 1 test
Evaluated by:
  • numfmt
24-30
1139 if (fmt[i] == '%' && fmt[i + 1] != '%')
fmt[i] == '%'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 22 times by 1 test
Evaluated by:
  • numfmt
fmt[i + 1] != '%'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-22
1140 die (EXIT_FAILURE, 0, _("format %s has too many %% directives"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"format %s has too many %% directives\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "format %s has too many %% directives" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "format %s has too many %% directives" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
1
1141 quote (fmt));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"format %s has too many %% directives\", 5), quote (fmt)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "format %s has too many %% directives" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "format %s has too many %% directives" , 5) , quote (fmt)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
1
1142-
1143 if (prefix_len)
prefix_lenDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 19 times by 1 test
Evaluated by:
  • numfmt
11-19
1144 format_str_prefix = xstrndup (fmt, prefix_len);
executed 11 times by 1 test: format_str_prefix = xstrndup (fmt, prefix_len);
Executed by:
  • numfmt
11
1145 if (fmt[suffix_pos] != '\0')
fmt[suffix_pos] != '\0'Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 19 times by 1 test
Evaluated by:
  • numfmt
11-19
1146 format_str_suffix = xstrdup (fmt + suffix_pos);
executed 11 times by 1 test: format_str_suffix = xstrdup (fmt + suffix_pos);
Executed by:
  • numfmt
11
1147-
1148 devmsg ("format String:\n input: %s\n grouping: %s\n"
executed 2 times by 1 test: fprintf ( stderr , "format String:\n input: %s\n grouping: %s\n" " padding width: %ld\n alignment: %s\n" " prefix: %s\n suffix: %s\n", quote_n (0, fmt), (grouping) ? "yes" : "no", padding_width, (padding_alignment == MBS_ALIGN_LEFT) ? "Left" : "Right", quote_n (1, format_str_prefix ? format_str_prefix : ""), quote_n (2, format_str_suffix ? format_str_suffix : ""));
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 28 times by 1 test
Evaluated by:
  • numfmt
2-28
1149 " padding width: %ld\n alignment: %s\n"-
1150 " prefix: %s\n suffix: %s\n",-
1151 quote_n (0, fmt), (grouping) ? "yes" : "no",-
1152 padding_width,-
1153 (padding_alignment == MBS_ALIGN_LEFT) ? "Left" : "Right",-
1154 quote_n (1, format_str_prefix ? format_str_prefix : ""),-
1155 quote_n (2, format_str_suffix ? format_str_suffix : ""));-
1156}
executed 30 times by 1 test: end of block
Executed by:
  • numfmt
30
1157-
1158/* Parse a numeric value (with optional suffix) from a string.-
1159 Returns a long double value, with input precision.-
1160-
1161 If there's an error converting the string to value - exits with-
1162 an error.-
1163-
1164 If there are any trailing characters after the number-
1165 (besides a valid suffix) - exits with an error. */-
1166static enum simple_strtod_error-
1167parse_human_number (const char *str, long double /*output */ *value,-
1168 size_t *precision)-
1169{-
1170 char *ptr = NULL;-
1171-
1172 enum simple_strtod_error e =-
1173 simple_strtod_human (str, &ptr, value, precision, scale_from);-
1174 if (e != SSE_OK && e != SSE_OK_PRECISION_LOSS)
e != SSE_OKDescription
TRUEevaluated 99 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 436 times by 1 test
Evaluated by:
  • numfmt
e != SSE_OK_PRECISION_LOSSDescription
TRUEevaluated 82 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
17-436
1175 {-
1176 simple_strtod_fatal (e, str);-
1177 return e;
executed 15 times by 1 test: return e;
Executed by:
  • numfmt
15
1178 }-
1179-
1180 if (ptr && *ptr != '\0')
ptrDescription
TRUEevaluated 453 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
*ptr != '\0'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 450 times by 1 test
Evaluated by:
  • numfmt
0-453
1181 {-
1182 if (inval_style != inval_ignore)
inval_style != inval_ignoreDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-3
1183 error (conv_exit_code, 0, _("invalid suffix in input %s: %s"),
executed 3 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "invalid suffix in input %s: %s" , 5) , quote_n (0, str), quote_n (1, ptr));
Executed by:
  • numfmt
3
1184 quote_n (0, str), quote_n (1, ptr));
executed 3 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "invalid suffix in input %s: %s" , 5) , quote_n (0, str), quote_n (1, ptr));
Executed by:
  • numfmt
3
1185 e = SSE_INVALID_SUFFIX;-
1186 }
executed 1 time by 1 test: end of block
Executed by:
  • numfmt
1
1187 return e;
executed 451 times by 1 test: return e;
Executed by:
  • numfmt
451
1188}-
1189-
1190-
1191/* Print the given VAL, using the requested representation.-
1192 The number is printed to STDOUT, with padding and alignment. */-
1193static int-
1194prepare_padded_number (const long double val, size_t precision)-
1195{-
1196 /* Generate Output. */-
1197 char buf[128];-
1198-
1199 size_t precision_used = user_precision == -1 ? precision : user_precision;
user_precision == -1Description
TRUEevaluated 444 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 6 times by 1 test
Evaluated by:
  • numfmt
6-444
1200-
1201 /* Can't reliably print too-large values without auto-scaling. */-
1202 unsigned int x;-
1203 expld (val, 10, &x);-
1204-
1205 if (scale_to == scale_none
scale_to == scale_noneDescription
TRUEevaluated 167 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 283 times by 1 test
Evaluated by:
  • numfmt
167-283
1206 && x + precision_used > MAX_UNSCALED_DIGITS)
x + precision_...NSCALED_DIGITSDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 155 times by 1 test
Evaluated by:
  • numfmt
12-155
1207 {-
1208 if (inval_style != inval_ignore)
inval_style != inval_ignoreDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-12
1209 {-
1210 if (precision_used)
precision_usedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
1-11
1211 error (conv_exit_code, 0,
executed 1 time by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value/precision too large to be printed: '%Lg/%" "l" "u" "'" " (consider using --to)" , 5) , val, (uintmax_t)precision_used);
Executed by:
  • numfmt
1
1212 _("value/precision too large to be printed: '%Lg/%"PRIuMAX"'"
executed 1 time by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value/precision too large to be printed: '%Lg/%" "l" "u" "'" " (consider using --to)" , 5) , val, (uintmax_t)precision_used);
Executed by:
  • numfmt
1
1213 " (consider using --to)"), val, (uintmax_t)precision_used);
executed 1 time by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value/precision too large to be printed: '%Lg/%" "l" "u" "'" " (consider using --to)" , 5) , val, (uintmax_t)precision_used);
Executed by:
  • numfmt
1
1214 else-
1215 error (conv_exit_code, 0,
executed 11 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value too large to be printed: '%Lg'" " (consider using --to)" , 5) , val);
Executed by:
  • numfmt
11
1216 _("value too large to be printed: '%Lg'"
executed 11 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value too large to be printed: '%Lg'" " (consider using --to)" , 5) , val);
Executed by:
  • numfmt
11
1217 " (consider using --to)"), val);
executed 11 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value too large to be printed: '%Lg'" " (consider using --to)" , 5) , val);
Executed by:
  • numfmt
11
1218 }-
1219 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • numfmt
1
1220 }-
1221-
1222 if (x > MAX_ACCEPTABLE_DIGITS - 1)
x > MAX_ACCEPTABLE_DIGITS - 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 436 times by 1 test
Evaluated by:
  • numfmt
2-436
1223 {-
1224 if (inval_style != inval_ignore)
inval_style != inval_ignoreDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-2
1225 error (conv_exit_code, 0, _("value too large to be printed: '%Lg'"
executed 2 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value too large to be printed: '%Lg'" " (cannot handle values > 999Y)" , 5) , val);
Executed by:
  • numfmt
2
1226 " (cannot handle values > 999Y)"), val);
executed 2 times by 1 test: error (conv_exit_code, 0, dcgettext (((void *)0), "value too large to be printed: '%Lg'" " (cannot handle values > 999Y)" , 5) , val);
Executed by:
  • numfmt
2
1227 return 0;
never executed: return 0;
0
1228 }-
1229-
1230 double_to_human (val, precision_used, buf, sizeof (buf),-
1231 scale_to, grouping, round_style);-
1232 if (suffix)
suffixDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 414 times by 1 test
Evaluated by:
  • numfmt
22-414
1233 strncat (buf, suffix, sizeof (buf) - strlen (buf) -1);
executed 22 times by 1 test: strncat (buf, suffix, sizeof (buf) - strlen (buf) -1);
Executed by:
  • numfmt
22
1234-
1235 devmsg ("formatting output:\n value: %Lf\n humanized: %s\n",
executed 11 times by 1 test: fprintf ( stderr , "formatting output:\n value: %Lf\n humanized: %s\n", val, quote (buf));
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 425 times by 1 test
Evaluated by:
  • numfmt
11-425
1236 val, quote (buf));-
1237-
1238 if (padding_width && strlen (buf) < padding_width)
padding_widthDescription
TRUEevaluated 105 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 331 times by 1 test
Evaluated by:
  • numfmt
strlen (buf) < padding_widthDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 74 times by 1 test
Evaluated by:
  • numfmt
31-331
1239 {-
1240 size_t w = padding_width;-
1241 mbsalign (buf, padding_buffer, padding_buffer_size, &w,-
1242 padding_alignment, MBA_UNIBYTE_ONLY);-
1243-
1244 devmsg (" After padding: %s\n", quote (padding_buffer));
executed 2 times by 1 test: fprintf ( stderr , " After padding: %s\n", quote (padding_buffer));
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 29 times by 1 test
Evaluated by:
  • numfmt
2-29
1245 }
executed 31 times by 1 test: end of block
Executed by:
  • numfmt
31
1246 else-
1247 {-
1248 setup_padding_buffer (strlen (buf) + 1);-
1249 strcpy (padding_buffer, buf);-
1250 }
executed 405 times by 1 test: end of block
Executed by:
  • numfmt
405
1251-
1252 return 1;
executed 436 times by 1 test: return 1;
Executed by:
  • numfmt
436
1253}-
1254-
1255static void-
1256print_padded_number (void)-
1257{-
1258 if (format_str_prefix)
format_str_prefixDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 425 times by 1 test
Evaluated by:
  • numfmt
11-425
1259 fputs (format_str_prefix, stdout);
executed 11 times by 1 test: fputs_unlocked (format_str_prefix, stdout );
Executed by:
  • numfmt
11
1260-
1261 fputs (padding_buffer, stdout);-
1262-
1263 if (format_str_suffix)
format_str_suffixDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 425 times by 1 test
Evaluated by:
  • numfmt
11-425
1264 fputs (format_str_suffix, stdout);
executed 11 times by 1 test: fputs_unlocked (format_str_suffix, stdout );
Executed by:
  • numfmt
11
1265}
executed 436 times by 1 test: end of block
Executed by:
  • numfmt
436
1266-
1267/* Converts the TEXT number string to the requested representation,-
1268 and handles automatic suffix addition. */-
1269static int-
1270process_suffixed_number (char *text, long double *result,-
1271 size_t *precision, long int field)-
1272{-
1273 if (suffix && strlen (text) > strlen (suffix))
suffixDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 510 times by 1 test
Evaluated by:
  • numfmt
strlen (text) ...trlen (suffix)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
4-510
1274 {-
1275 char *possible_suffix = text + strlen (text) - strlen (suffix);-
1276-
1277 if (STREQ (suffix, possible_suffix))
never executed: __result = (((const unsigned char *) (const char *) ( suffix ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( possible_suffix ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
( __extension_...)))); }) == 0)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 12 times by 1 test
Evaluated by:
  • numfmt
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-12
1278 {-
1279 /* trim suffix, ONLY if it's at the end of the text. */-
1280 *possible_suffix = '\0';-
1281 devmsg ("trimming suffix %s\n", quote (suffix));
executed 1 time by 1 test: fprintf ( stderr , "trimming suffix %s\n", quote (suffix));
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
1-8
1282 }
executed 9 times by 1 test: end of block
Executed by:
  • numfmt
9
1283 else-
1284 devmsg ("no valid suffix found\n");
executed 1 time by 1 test: fprintf ( stderr , "no valid suffix found\n");
Executed by:
  • numfmt
executed 12 times by 1 test: end of block
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 11 times by 1 test
Evaluated by:
  • numfmt
1-12
1285 }-
1286-
1287 /* Skip white space - always. */-
1288 char *p = text;-
1289 while (*p && isblank (to_uchar (*p)))
*pDescription
TRUEevaluated 559 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
((*__ctype_b_l...int) _ISblank)Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 534 times by 1 test
Evaluated by:
  • numfmt
1-559
1290 ++p;
executed 25 times by 1 test: ++p;
Executed by:
  • numfmt
25
1291 const unsigned int skip_count = text - p;-
1292-
1293 /* setup auto-padding. */-
1294 if (auto_padding)
auto_paddingDescription
TRUEevaluated 497 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 38 times by 1 test
Evaluated by:
  • numfmt
38-497
1295 {-
1296 if (skip_count > 0 || field > 1)
skip_count > 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 488 times by 1 test
Evaluated by:
  • numfmt
field > 1Description
TRUEevaluated 74 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 414 times by 1 test
Evaluated by:
  • numfmt
9-488
1297 {-
1298 padding_width = strlen (text);-
1299 setup_padding_buffer (padding_width);-
1300 }
executed 83 times by 1 test: end of block
Executed by:
  • numfmt
83
1301 else-
1302 {-
1303 padding_width = 0;-
1304 }
executed 414 times by 1 test: end of block
Executed by:
  • numfmt
414
1305 devmsg ("setting Auto-Padding to %ld characters\n", padding_width);
executed 9 times by 1 test: fprintf ( stderr , "setting Auto-Padding to %ld characters\n", padding_width);
Executed by:
  • numfmt
dev_debugDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 488 times by 1 test
Evaluated by:
  • numfmt
9-488
1306 }
executed 497 times by 1 test: end of block
Executed by:
  • numfmt
497
1307-
1308 long double val = 0;-
1309 enum simple_strtod_error e = parse_human_number (p, &val, precision);-
1310 if (e == SSE_OK_PRECISION_LOSS && debug)
e == SSE_OK_PRECISION_LOSSDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 449 times by 1 test
Evaluated by:
  • numfmt
debugDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 15 times by 1 test
Evaluated by:
  • numfmt
2-449
1311 error (0, 0, _("large input value %s: possible precision loss"),
executed 2 times by 1 test: error (0, 0, dcgettext (((void *)0), "large input value %s: possible precision loss" , 5) , quote (p));
Executed by:
  • numfmt
2
1312 quote (p));
executed 2 times by 1 test: error (0, 0, dcgettext (((void *)0), "large input value %s: possible precision loss" , 5) , quote (p));
Executed by:
  • numfmt
2
1313-
1314 if (from_unit_size != 1 || to_unit_size != 1)
from_unit_size != 1Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 458 times by 1 test
Evaluated by:
  • numfmt
to_unit_size != 1Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 405 times by 1 test
Evaluated by:
  • numfmt
8-458
1315 val = (val * from_unit_size) / to_unit_size;
executed 61 times by 1 test: val = (val * from_unit_size) / to_unit_size;
Executed by:
  • numfmt
61
1316-
1317 *result = val;-
1318-
1319 return (e == SSE_OK || e == SSE_OK_PRECISION_LOSS);
executed 466 times by 1 test: return (e == SSE_OK || e == SSE_OK_PRECISION_LOSS);
Executed by:
  • numfmt
466
1320}-
1321-
1322/* Return a pointer to the beginning of the next field in line.-
1323 The line pointer is moved to the end of the next field. */-
1324static char*-
1325next_field (char **line)-
1326{-
1327 char *field_start = *line;-
1328 char *field_end = field_start;-
1329-
1330 if (delimiter != DELIMITER_DEFAULT)
delimiter != DELIMITER_DEFAULTDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 597 times by 1 test
Evaluated by:
  • numfmt
29-597
1331 {-
1332 if (*field_start != delimiter)
*field_start != delimiterDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-28
1333 {-
1334 while (*field_end && *field_end != delimiter)
*field_endDescription
TRUEevaluated 102 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 14 times by 1 test
Evaluated by:
  • numfmt
*field_end != delimiterDescription
TRUEevaluated 88 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 14 times by 1 test
Evaluated by:
  • numfmt
14-102
1335 ++field_end;
executed 88 times by 1 test: ++field_end;
Executed by:
  • numfmt
88
1336 }
executed 28 times by 1 test: end of block
Executed by:
  • numfmt
28
1337 /* else empty field */-
1338 }
executed 29 times by 1 test: end of block
Executed by:
  • numfmt
29
1339 else-
1340 {-
1341 /* keep any space prefix in the returned field */-
1342 while (*field_end && field_sep (*field_end))
*field_endDescription
TRUEevaluated 620 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
field_sep (*field_end)Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 595 times by 1 test
Evaluated by:
  • numfmt
2-620
1343 ++field_end;
executed 25 times by 1 test: ++field_end;
Executed by:
  • numfmt
25
1344-
1345 while (*field_end && ! field_sep (*field_end))
*field_endDescription
TRUEevaluated 3134 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 468 times by 1 test
Evaluated by:
  • numfmt
! field_sep (*field_end)Description
TRUEevaluated 3005 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 129 times by 1 test
Evaluated by:
  • numfmt
129-3134
1346 ++field_end;
executed 3005 times by 1 test: ++field_end;
Executed by:
  • numfmt
3005
1347 }
executed 597 times by 1 test: end of block
Executed by:
  • numfmt
597
1348-
1349 *line = field_end;-
1350 return field_start;
executed 626 times by 1 test: return field_start;
Executed by:
  • numfmt
626
1351}-
1352-
1353static bool _GL_ATTRIBUTE_PURE-
1354include_field (uintmax_t field)-
1355{-
1356 struct field_range_pair *p = frp;-
1357 if (!p)
!pDescription
TRUEevaluated 446 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 180 times by 1 test
Evaluated by:
  • numfmt
180-446
1358 return field == 1;
executed 446 times by 1 test: return field == 1;
Executed by:
  • numfmt
446
1359-
1360 while (p->lo != UINTMAX_MAX)
p->lo != (1844...73709551615UL)Description
TRUEevaluated 213 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 82 times by 1 test
Evaluated by:
  • numfmt
82-213
1361 {-
1362 if (p->lo <= field && p->hi >= field)
p->lo <= fieldDescription
TRUEevaluated 161 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 52 times by 1 test
Evaluated by:
  • numfmt
p->hi >= fieldDescription
TRUEevaluated 98 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 63 times by 1 test
Evaluated by:
  • numfmt
52-161
1363 return true;
executed 98 times by 1 test: return 1 ;
Executed by:
  • numfmt
98
1364 ++p;-
1365 }
executed 115 times by 1 test: end of block
Executed by:
  • numfmt
115
1366 return false;
executed 82 times by 1 test: return 0 ;
Executed by:
  • numfmt
82
1367}-
1368-
1369/* Convert and output the given field. If it is not included in the set-
1370 of fields to process just output the original */-
1371static bool-
1372process_field (char *text, uintmax_t field)-
1373{-
1374 long double val = 0;-
1375 size_t precision = 0;-
1376 bool valid_number = true;-
1377-
1378 if (include_field (field))
include_field (field)Description
TRUEevaluated 535 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 91 times by 1 test
Evaluated by:
  • numfmt
91-535
1379 {-
1380 valid_number =-
1381 process_suffixed_number (text, &val, &precision, field);-
1382-
1383 if (valid_number)
valid_numberDescription
TRUEevaluated 450 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 16 times by 1 test
Evaluated by:
  • numfmt
16-450
1384 valid_number = prepare_padded_number (val, precision);
executed 450 times by 1 test: valid_number = prepare_padded_number (val, precision);
Executed by:
  • numfmt
450
1385-
1386 if (valid_number)
valid_numberDescription
TRUEevaluated 436 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
17-436
1387 print_padded_number ();
executed 436 times by 1 test: print_padded_number ();
Executed by:
  • numfmt
436
1388 else-
1389 fputs (text, stdout);
executed 17 times by 1 test: fputs_unlocked (text, stdout );
Executed by:
  • numfmt
17
1390 }-
1391 else-
1392 fputs (text, stdout);
executed 91 times by 1 test: fputs_unlocked (text, stdout );
Executed by:
  • numfmt
91
1393-
1394 return valid_number;
executed 544 times by 1 test: return valid_number;
Executed by:
  • numfmt
544
1395}-
1396-
1397/* Convert number in a given line of text.-
1398 NEWLINE specifies whether to output a '\n' for this "line". */-
1399static int-
1400process_line (char *line, bool newline)-
1401{-
1402 char *next;-
1403 uintmax_t field = 0;-
1404 bool valid_number = true;-
1405-
1406 while (true) {-
1407 ++field;-
1408 next = next_field (&line);-
1409-
1410 if (*line != '\0')
*line != '\0'Description
TRUEevaluated 144 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 482 times by 1 test
Evaluated by:
  • numfmt
144-482
1411 {-
1412 /* nul terminate the current field string and process */-
1413 *line = '\0';-
1414-
1415 if (! process_field (next, field))
! process_field (next, field)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 141 times by 1 test
Evaluated by:
  • numfmt
2-141
1416 valid_number = false;
executed 2 times by 1 test: valid_number = 0 ;
Executed by:
  • numfmt
2
1417-
1418 fputc ((delimiter == DELIMITER_DEFAULT) ?-
1419 ' ' : delimiter, stdout);-
1420 ++line;-
1421 }
executed 143 times by 1 test: end of block
Executed by:
  • numfmt
143
1422 else-
1423 {-
1424 /* end of the line, process the last field and finish */-
1425 if (! process_field (next, field))
! process_field (next, field)Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 386 times by 1 test
Evaluated by:
  • numfmt
15-386
1426 valid_number = false;
executed 15 times by 1 test: valid_number = 0 ;
Executed by:
  • numfmt
15
1427-
1428 break;
executed 401 times by 1 test: break;
Executed by:
  • numfmt
401
1429 }-
1430 }-
1431-
1432 if (newline)
newlineDescription
TRUEevaluated 400 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-400
1433 putchar (line_delim);
executed 400 times by 1 test: putchar_unlocked (line_delim);
Executed by:
  • numfmt
400
1434-
1435 return valid_number;
executed 401 times by 1 test: return valid_number;
Executed by:
  • numfmt
401
1436}-
1437-
1438int-
1439main (int argc, char **argv)-
1440{-
1441 int valid_numbers = 1;-
1442 bool locale_ok;-
1443-
1444 initialize_main (&argc, &argv);-
1445 set_program_name (argv[0]);-
1446 locale_ok = !!setlocale (LC_ALL, "");-
1447 bindtextdomain (PACKAGE, LOCALEDIR);-
1448 textdomain (PACKAGE);-
1449-
1450#if HAVE_FPSETPREC-
1451 /* Enabled extended precision if needed. */-
1452 fpsetprec (FP_PE);-
1453#endif-
1454-
1455 decimal_point = nl_langinfo (RADIXCHAR);-
1456 if (decimal_point == NULL || strlen (decimal_point) == 0)
decimal_point == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 501 times by 1 test
Evaluated by:
  • numfmt
strlen (decimal_point) == 0Description
TRUEnever evaluated
FALSEevaluated 501 times by 1 test
Evaluated by:
  • numfmt
0-501
1457 decimal_point = ".";
never executed: decimal_point = ".";
0
1458 decimal_point_length = strlen (decimal_point);-
1459-
1460 atexit (close_stdout);-
1461-
1462 while (true)-
1463 {-
1464 int c = getopt_long (argc, argv, "d:z", longopts, NULL);-
1465-
1466 if (c == -1)
c == -1Description
TRUEevaluated 447 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 782 times by 1 test
Evaluated by:
  • numfmt
447-782
1467 break;
executed 447 times by 1 test: break;
Executed by:
  • numfmt
447
1468-
1469 switch (c)-
1470 {-
1471 case FROM_OPTION:
executed 183 times by 1 test: case FROM_OPTION:
Executed by:
  • numfmt
183
1472 scale_from = XARGMATCH ("--from", optarg,-
1473 scale_from_args, scale_from_types);-
1474 break;
executed 182 times by 1 test: break;
Executed by:
  • numfmt
182
1475-
1476 case FROM_UNIT_OPTION:
executed 15 times by 1 test: case FROM_UNIT_OPTION:
Executed by:
  • numfmt
15
1477 from_unit_size = unit_to_umax (optarg);-
1478 break;
executed 8 times by 1 test: break;
Executed by:
  • numfmt
8
1479-
1480 case TO_OPTION:
executed 264 times by 1 test: case TO_OPTION:
Executed by:
  • numfmt
264
1481 scale_to =-
1482 XARGMATCH ("--to", optarg, scale_to_args, scale_to_types);-
1483 break;
executed 263 times by 1 test: break;
Executed by:
  • numfmt
263
1484-
1485 case TO_UNIT_OPTION:
executed 30 times by 1 test: case TO_UNIT_OPTION:
Executed by:
  • numfmt
30
1486 to_unit_size = unit_to_umax (optarg);-
1487 break;
executed 28 times by 1 test: break;
Executed by:
  • numfmt
28
1488-
1489 case ROUND_OPTION:
executed 48 times by 1 test: case ROUND_OPTION:
Executed by:
  • numfmt
48
1490 round_style = XARGMATCH ("--round", optarg, round_args, round_types);-
1491 break;
executed 47 times by 1 test: break;
Executed by:
  • numfmt
47
1492-
1493 case GROUPING_OPTION:
executed 6 times by 1 test: case GROUPING_OPTION:
Executed by:
  • numfmt
6
1494 grouping = 1;-
1495 break;
executed 6 times by 1 test: break;
Executed by:
  • numfmt
6
1496-
1497 case PADDING_OPTION:
executed 17 times by 1 test: case PADDING_OPTION:
Executed by:
  • numfmt
17
1498 if (xstrtol (optarg, NULL, 10, &padding_width, "") != LONGINT_OK
xstrtol (optar... != LONGINT_OKDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 15 times by 1 test
Evaluated by:
  • numfmt
2-15
1499 || padding_width == 0)
padding_width == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 14 times by 1 test
Evaluated by:
  • numfmt
1-14
1500 die (EXIT_FAILURE, 0, _("invalid padding value %s"),
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid padding value %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid padding value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid padding value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
3
1501 quote (optarg));
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid padding value %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid padding value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid padding value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
3
1502 if (padding_width < 0)
padding_width < 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 10 times by 1 test
Evaluated by:
  • numfmt
4-10
1503 {-
1504 padding_alignment = MBS_ALIGN_LEFT;-
1505 padding_width = -padding_width;-
1506 }
executed 4 times by 1 test: end of block
Executed by:
  • numfmt
4
1507 /* TODO: We probably want to apply a specific --padding-
1508 to --header lines too. */-
1509 break;
executed 14 times by 1 test: break;
Executed by:
  • numfmt
14
1510-
1511 case FIELD_OPTION:
executed 57 times by 1 test: case FIELD_OPTION:
Executed by:
  • numfmt
57
1512 if (n_frp)
n_frpDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 52 times by 1 test
Evaluated by:
  • numfmt
5-52
1513 die (EXIT_FAILURE, 0, _("multiple field specifications"));
executed 5 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"multiple field specifications\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "multiple field specifications" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "multiple field specifications" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • numfmt
5
1514 set_fields (optarg, SETFLD_ALLOW_DASH);-
1515 break;
executed 43 times by 1 test: break;
Executed by:
  • numfmt
43
1516-
1517 case 'd':
executed 17 times by 1 test: case 'd':
Executed by:
  • numfmt
17
1518 /* Interpret -d '' to mean 'use the NUL byte as the delimiter.' */-
1519 if (optarg[0] != '\0' && optarg[1] != '\0')
optarg[0] != '\0'Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
optarg[1] != '\0'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 12 times by 1 test
Evaluated by:
  • numfmt
2-15
1520 die (EXIT_FAILURE, 0,
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"the delimiter must be a single character\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "the delimiter must be a single character" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "the delimiter must be a single character" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
3
1521 _("the delimiter must be a single character"));
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"the delimiter must be a single character\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "the delimiter must be a single character" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "the delimiter must be a single character" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
3
1522 delimiter = optarg[0];-
1523 break;
executed 14 times by 1 test: break;
Executed by:
  • numfmt
14
1524-
1525 case 'z':
executed 6 times by 1 test: case 'z':
Executed by:
  • numfmt
6
1526 line_delim = '\0';-
1527 break;
executed 6 times by 1 test: break;
Executed by:
  • numfmt
6
1528-
1529 case SUFFIX_OPTION:
executed 26 times by 1 test: case SUFFIX_OPTION:
Executed by:
  • numfmt
26
1530 suffix = optarg;-
1531 break;
executed 26 times by 1 test: break;
Executed by:
  • numfmt
26
1532-
1533 case DEBUG_OPTION:
executed 12 times by 1 test: case DEBUG_OPTION:
Executed by:
  • numfmt
12
1534 debug = true;-
1535 break;
executed 12 times by 1 test: break;
Executed by:
  • numfmt
12
1536-
1537 case DEV_DEBUG_OPTION:
executed 11 times by 1 test: case DEV_DEBUG_OPTION:
Executed by:
  • numfmt
11
1538 dev_debug = true;-
1539 debug = true;-
1540 break;
executed 11 times by 1 test: break;
Executed by:
  • numfmt
11
1541-
1542 case HEADER_OPTION:
executed 10 times by 1 test: case HEADER_OPTION:
Executed by:
  • numfmt
10
1543 if (optarg)
optargDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
4-6
1544 {-
1545 if (xstrtoumax (optarg, NULL, 10, &header, "") != LONGINT_OK
xstrtoumax (op... != LONGINT_OKDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
2-4
1546 || header == 0)
header == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
1-3
1547 die (EXIT_FAILURE, 0, _("invalid header value %s"),
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid header value %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid header value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid header value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
3
1548 quote (optarg));
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid header value %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid header value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid header value %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • numfmt
3
1549 }
executed 3 times by 1 test: end of block
Executed by:
  • numfmt
3
1550 else-
1551 {-
1552 header = 1;-
1553 }
executed 4 times by 1 test: end of block
Executed by:
  • numfmt
4
1554 break;
executed 7 times by 1 test: break;
Executed by:
  • numfmt
7
1555-
1556 case FORMAT_OPTION:
executed 42 times by 1 test: case FORMAT_OPTION:
Executed by:
  • numfmt
42
1557 format_str = optarg;-
1558 break;
executed 42 times by 1 test: break;
Executed by:
  • numfmt
42
1559-
1560 case INVALID_OPTION:
executed 20 times by 1 test: case INVALID_OPTION:
Executed by:
  • numfmt
20
1561 inval_style = XARGMATCH ("--invalid", optarg,-
1562 inval_args, inval_types);-
1563 break;
executed 19 times by 1 test: break;
Executed by:
  • numfmt
19
1564-
1565 case_GETOPT_HELP_CHAR;
never executed: break;
executed 10 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • numfmt
0-10
1566 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • numfmt
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • numfmt
0-4
1567-
1568 default:
executed 4 times by 1 test: default:
Executed by:
  • numfmt
4
1569 usage (EXIT_FAILURE);-
1570 }
never executed: end of block
0
1571 }-
1572-
1573 if (format_str != NULL && grouping)
format_str != ((void *)0)Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 406 times by 1 test
Evaluated by:
  • numfmt
groupingDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 40 times by 1 test
Evaluated by:
  • numfmt
1-406
1574 die (EXIT_FAILURE, 0, _("--grouping cannot be combined with --format"));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"--grouping cannot be combined with --format\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "--grouping cannot be combined with --format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "--grouping cannot be combined with --format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • numfmt
1
1575-
1576 if (debug && ! locale_ok)
debugDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 424 times by 1 test
Evaluated by:
  • numfmt
! locale_okDescription
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • numfmt
0-424
1577 error (0, 0, _("failed to set locale"));
never executed: error (0, 0, dcgettext (((void *)0), "failed to set locale" , 5) );
0
1578-
1579 /* Warn about no-op. */-
1580 if (debug && scale_from == scale_none && scale_to == scale_none
debugDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 424 times by 1 test
Evaluated by:
  • numfmt
scale_from == scale_noneDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
scale_to == scale_noneDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
4-424
1581 && !grouping && (padding_width == 0) && (format_str == NULL))
!groupingDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
(padding_width == 0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
(format_str == ((void *)0) )Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 3 times by 1 test
Evaluated by:
  • numfmt
1-9
1582 error (0, 0, _("no conversion option specified"));
executed 5 times by 1 test: error (0, 0, dcgettext (((void *)0), "no conversion option specified" , 5) );
Executed by:
  • numfmt
5
1583-
1584 if (format_str)
format_strDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 406 times by 1 test
Evaluated by:
  • numfmt
40-406
1585 parse_format_string (format_str);
executed 40 times by 1 test: parse_format_string (format_str);
Executed by:
  • numfmt
40
1586-
1587 if (grouping)
groupingDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 426 times by 1 test
Evaluated by:
  • numfmt
10-426
1588 {-
1589 if (scale_to != scale_none)
scale_to != scale_noneDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
2-8
1590 die (EXIT_FAILURE, 0, _("grouping cannot be combined with --to"));
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"grouping cannot be combined with --to\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "grouping cannot be combined with --to" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "grouping cannot be combined with --to" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • numfmt
2
1591 if (debug && (strlen (nl_langinfo (THOUSEP)) == 0))
debugDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
(strlen ( rpl_...OUSEP )) == 0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • numfmt
FALSEnever evaluated
0-4
1592 error (0, 0, _("grouping has no effect in this locale"));
executed 4 times by 1 test: error (0, 0, dcgettext (((void *)0), "grouping has no effect in this locale" , 5) );
Executed by:
  • numfmt
4
1593 }
executed 8 times by 1 test: end of block
Executed by:
  • numfmt
8
1594-
1595-
1596 setup_padding_buffer (padding_width);-
1597 auto_padding = (padding_width == 0 && delimiter == DELIMITER_DEFAULT);
padding_width == 0Description
TRUEevaluated 409 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 25 times by 1 test
Evaluated by:
  • numfmt
delimiter == DELIMITER_DEFAULTDescription
TRUEevaluated 395 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 14 times by 1 test
Evaluated by:
  • numfmt
14-409
1598-
1599 if (inval_style != inval_abort)
inval_style != inval_abortDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 415 times by 1 test
Evaluated by:
  • numfmt
19-415
1600 conv_exit_code = 0;
executed 19 times by 1 test: conv_exit_code = 0;
Executed by:
  • numfmt
19
1601-
1602 if (argc > optind)
argc > optindDescription
TRUEevaluated 417 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
17-417
1603 {-
1604 if (debug && header)
debugDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 397 times by 1 test
Evaluated by:
  • numfmt
headerDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 19 times by 1 test
Evaluated by:
  • numfmt
1-397
1605 error (0, 0, _("--header ignored with command-line input"));
executed 1 time by 1 test: error (0, 0, dcgettext (((void *)0), "--header ignored with command-line input" , 5) );
Executed by:
  • numfmt
1
1606-
1607 for (; optind < argc; optind++)
optind < argcDescription
TRUEevaluated 452 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 335 times by 1 test
Evaluated by:
  • numfmt
335-452
1608 valid_numbers &= process_line (argv[optind], true);
executed 452 times by 1 test: valid_numbers &= process_line (argv[optind], 1 );
Executed by:
  • numfmt
452
1609 }
executed 335 times by 1 test: end of block
Executed by:
  • numfmt
335
1610 else-
1611 {-
1612 char *line = NULL;-
1613 size_t line_allocated = 0;-
1614 ssize_t len;-
1615-
1616 while (header-- && getdelim (&line, &line_allocated,
header--Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 16 times by 1 test
Evaluated by:
  • numfmt
getdelim (&lin...m, stdin ) > 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-16
1617 line_delim, stdin) > 0)
getdelim (&lin...m, stdin ) > 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-8
1618 fputs (line, stdout);
executed 8 times by 1 test: fputs_unlocked (line, stdout );
Executed by:
  • numfmt
8
1619-
1620 while ((len = getdelim (&line, &line_allocated,
(len = getdeli..., stdin )) > 0Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
17-31
1621 line_delim, stdin)) > 0)
(len = getdeli..., stdin )) > 0Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
17-31
1622 {-
1623 bool newline = line[len - 1] == line_delim;-
1624 if (newline)
newlineDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
1-30
1625 line[len - 1] = '\0';
executed 30 times by 1 test: line[len - 1] = '\0';
Executed by:
  • numfmt
30
1626 valid_numbers &= process_line (line, newline);-
1627 }
executed 31 times by 1 test: end of block
Executed by:
  • numfmt
31
1628-
1629 IF_LINT (free (line));-
1630-
1631 if (ferror (stdin))
ferror_unlocked ( stdin )Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
0-17
1632 error (0, errno, _("error reading input"));
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "error reading input" , 5) );
0
1633 }
executed 17 times by 1 test: end of block
Executed by:
  • numfmt
17
1634-
1635#ifdef lint-
1636 free (padding_buffer);-
1637 free (format_str_prefix);-
1638 free (format_str_suffix);-
1639 reset_fields ();-
1640#endif-
1641-
1642 if (debug && !valid_numbers)
debugDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 330 times by 1 test
Evaluated by:
  • numfmt
!valid_numbersDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 21 times by 1 test
Evaluated by:
  • numfmt
1-330
1643 error (0, 0, _("failed to convert some of the input numbers"));
executed 1 time by 1 test: error (0, 0, dcgettext (((void *)0), "failed to convert some of the input numbers" , 5) );
Executed by:
  • numfmt
1
1644-
1645 int exit_status = EXIT_SUCCESS;-
1646 if (!valid_numbers
!valid_numbersDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 335 times by 1 test
Evaluated by:
  • numfmt
17-335
1647 && inval_style != inval_warn && inval_style != inval_ignore)
inval_style != inval_warnDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 1 time by 1 test
Evaluated by:
  • numfmt
inval_style != inval_ignoreDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • numfmt
FALSEevaluated 2 times by 1 test
Evaluated by:
  • numfmt
1-16
1648 exit_status = EXIT_CONVERSION_WARNINGS;
executed 14 times by 1 test: exit_status = EXIT_CONVERSION_WARNINGS;
Executed by:
  • numfmt
14
1649-
1650 return exit_status;
executed 352 times by 1 test: return exit_status;
Executed by:
  • numfmt
352
1651}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2