MCPcopy Index your code
hub / github.com/git/git / git_parse_signed

Function git_parse_signed

parse.c:18–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
19{
20 if (value && *value) {
21 char *end;
22 intmax_t val;
23 intmax_t factor;
24
25 if (max < 0)
26 BUG("max must be a positive integer");
27
28 errno = 0;
29 val = strtoimax(value, &end, 0);
30 if (errno == ERANGE)
31 return 0;
32 if (end == value) {
33 errno = EINVAL;
34 return 0;
35 }
36 factor = get_unit_factor(end);
37 if (!factor) {
38 errno = EINVAL;
39 return 0;
40 }
41 if ((val < 0 && (-max - 1) / factor > val) ||
42 (val > 0 && max / factor < val)) {
43 errno = ERANGE;
44 return 0;
45 }
46 val *= factor;
47 *ret = val;
48 return 1;
49 }
50 errno = EINVAL;
51 return 0;
52}
53
54int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max)
55{

Callers 4

do_get_valueFunction · 0.85
git_parse_intFunction · 0.85
git_parse_int64Function · 0.85
git_parse_ssize_tFunction · 0.85

Calls 1

get_unit_factorFunction · 0.85

Tested by

no test coverage detected