OpenCoverage

xdectoint.c #2

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gl/lib/xdectoint.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* Convert decimal strings with bounds checking and exit on error.-
2-
3 Copyright (C) 2014-2018 Free Software Foundation, Inc.-
4-
5 This program is free software: you can redistribute it and/or modify-
6 it under the terms of the GNU General Public License as published by-
7 the Free Software Foundation; either version 3 of the License, or-
8 (at your option) any later version.-
9-
10 This program is distributed in the hope that it will be useful,-
11 but WITHOUT ANY WARRANTY; without even the implied warranty of-
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
13 GNU General Public License for more details.-
14-
15 You should have received a copy of the GNU General Public License-
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
17-
18#include <config.h>-
19-
20#include "xdectoint.h"-
21-
22#include <errno.h>-
23#include <inttypes.h>-
24#include <stdlib.h>-
25-
26#include "error.h"-
27#include "quote.h"-
28#include "xstrtol.h"-
29-
30/* Parse numeric string N_STR of base BASE, and return the value.-
31 Exit on parse error or if MIN or MAX are exceeded.-
32 Strings can have multiplicative SUFFIXES if specified.-
33 ERR is printed along with N_STR on error. */-
34-
35__xdectoint_t-
36__xnumtoint (const char *n_str, int base, __xdectoint_t min, __xdectoint_t max,-
37 const char *suffixes, const char *err, int err_exit)-
38{-
39 strtol_error s_err;-
40-
41 __xdectoint_t tnum;-
42 s_err = __xstrtol (n_str, NULL, base, &tnum, suffixes);-
43-
44 if (s_err == LONGINT_OK)
s_err == LONGINT_OKDescription
TRUEevaluated 4727 times by 13 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • fmt
  • fold
  • head
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
FALSEevaluated 96 times by 17 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • csplit
  • dir
  • fmt
  • fold
  • head
  • nl
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
  • vdir
96-4727
45 {-
46 if (tnum < min || max < tnum)
tnum < minDescription
TRUEevaluated 9 times by 2 tests
Evaluated by:
  • pr
  • split
FALSEevaluated 4718 times by 13 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • fmt
  • fold
  • head
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
max < tnumDescription
TRUEevaluated 5 times by 2 tests
Evaluated by:
  • fmt
  • split
FALSEevaluated 4713 times by 13 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • fmt
  • fold
  • head
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
5-4718
47 {-
48 s_err = LONGINT_OVERFLOW;-
49 /* Use have the INT range as a heuristic to distinguish-
50 type overflow rather than other min/max limits. */-
51 if (tnum > INT_MAX/2)
tnum > 0x7fffffff/2Description
TRUEevaluated 2 times by 2 tests
Evaluated by:
  • fmt
  • split
FALSEevaluated 12 times by 3 tests
Evaluated by:
  • fmt
  • pr
  • split
2-12
52 errno = EOVERFLOW;
executed 2 times by 2 tests: (*__errno_location ()) = 75 ;
Executed by:
  • fmt
  • split
2
53#if __xdectoint_signed-
54 else if (tnum < INT_MIN/2)-
55 errno = EOVERFLOW;-
56#endif-
57 else-
58 errno = ERANGE;
executed 12 times by 3 tests: (*__errno_location ()) = 34 ;
Executed by:
  • fmt
  • pr
  • split
12
59 }-
60 }
executed 4727 times by 13 tests: end of block
Executed by:
  • b2sum
  • base32
  • base64
  • fmt
  • fold
  • head
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
4727
61 else if (s_err == LONGINT_OVERFLOW)
s_err == LONGINT_OVERFLOWDescription
TRUEevaluated 10 times by 4 tests
Evaluated by:
  • pr
  • split
  • tail
  • truncate
FALSEevaluated 86 times by 17 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • csplit
  • dir
  • fmt
  • fold
  • head
  • nl
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
  • vdir
10-86
62 errno = EOVERFLOW;
executed 10 times by 4 tests: (*__errno_location ()) = 75 ;
Executed by:
  • pr
  • split
  • tail
  • truncate
10
63 else if (s_err == LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW)
s_err == LONGI..._WITH_OVERFLOWDescription
TRUEnever evaluated
FALSEevaluated 86 times by 17 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • csplit
  • dir
  • fmt
  • fold
  • head
  • nl
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
  • vdir
0-86
64 errno = 0; /* Don't show ERANGE errors for invalid numbers. */
never executed: (*__errno_location ()) = 0;
0
65-
66 if (s_err != LONGINT_OK)
s_err != LONGINT_OKDescription
TRUEevaluated 110 times by 17 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • csplit
  • dir
  • fmt
  • fold
  • head
  • nl
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
  • vdir
FALSEevaluated 4713 times by 13 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • fmt
  • fold
  • head
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
110-4713
67 {-
68 /* EINVAL error message is redundant in this context. */-
69 error (err_exit ? err_exit : EXIT_FAILURE, errno == EINVAL ? 0 : errno,-
70 "%s: %s", err, quote (n_str));-
71 }
never executed: end of block
0
72-
73 return tnum;
executed 4713 times by 13 tests: return tnum;
Executed by:
  • b2sum
  • base32
  • base64
  • fmt
  • fold
  • head
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
4713
74}-
75-
76/* Parse decimal string N_STR, and return the value.-
77 Exit on parse error or if MIN or MAX are exceeded.-
78 Strings can have multiplicative SUFFIXES if specified.-
79 ERR is printed along with N_STR on error. */-
80-
81__xdectoint_t-
82__xdectoint (const char *n_str, __xdectoint_t min, __xdectoint_t max,-
83 const char *suffixes, const char *err, int err_exit)-
84{-
85 return __xnumtoint (n_str, 10, min, max, suffixes, err, err_exit);
executed 4808 times by 15 tests: return xnumtoumax (n_str, 10, min, max, suffixes, err, err_exit);
Executed by:
  • b2sum
  • base32
  • base64
  • csplit
  • fmt
  • fold
  • head
  • nl
  • nproc
  • pr
  • shred
  • shuf
  • split
  • tail
  • truncate
4808
86}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2