diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -870,8 +870,8 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max) return 0; } uval = val < 0 ? -val : val; - uval *= factor; - if (uval > max || (val < 0 ? -val : val) > uval) { + if (unsigned_mult_overflows(factor, uval) || + factor * uval > max) { errno = ERANGE; return 0; } @@ -888,21 +888,22 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max) if (value && *value) { char *end; uintmax_t val; - uintmax_t oldval; + uintmax_t factor = 1; errno = 0; val = strtoumax(value, &end, 0); if (errno == ERANGE) return 0; - oldval = val; - if (!parse_unit_factor(end, &val)) { + if (!parse_unit_factor(end, &factor)) { errno = EINVAL; return 0; } - if (val > max || oldval > val) { + if (unsigned_mult_overflows(factor, val) || + factor * val > max) { errno = ERANGE; return 0; } + val *= factor; *ret = val; return 1; } |