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

Function git_parse_unsigned

parse.c:54–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max)
55{
56 if (value && *value) {
57 char *end;
58 uintmax_t val;
59 uintmax_t factor;
60
61 /* negative values would be accepted by strtoumax */
62 if (strchr(value, '-')) {
63 errno = EINVAL;
64 return 0;
65 }
66 errno = 0;
67 val = strtoumax(value, &end, 0);
68 if (errno == ERANGE)
69 return 0;
70 if (end == value) {
71 errno = EINVAL;
72 return 0;
73 }
74 factor = get_unit_factor(end);
75 if (!factor) {
76 errno = EINVAL;
77 return 0;
78 }
79 if (unsigned_mult_overflows(factor, val) ||
80 factor * val > max) {
81 errno = ERANGE;
82 return 0;
83 }
84 val *= factor;
85 *ret = val;
86 return 1;
87 }
88 errno = EINVAL;
89 return 0;
90}
91
92int git_parse_int(const char *value, int *ret)
93{

Callers 5

do_get_valueFunction · 0.85
git_parse_uintFunction · 0.85
git_parse_ulongFunction · 0.85
cmd__synthesize__packFunction · 0.85
parse_max_memoryFunction · 0.85

Calls 1

get_unit_factorFunction · 0.85

Tested by 1

cmd__synthesize__packFunction · 0.68