Skip to content

Commit

Permalink
config: avoid calling labs() on too-large data type
Browse files Browse the repository at this point in the history
The `labs()` function operates, as the initial `l` suggests, on `long`
parameters. However, in `config.c` we tried to use it on values of type
`intmax_t`.

This problem was found by GCC v9.x.

To fix it, let's just "unroll" the function (i.e. negate the value if it
is negative).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
dscho authored and gitster committed Jun 13, 2019
1 parent 4fa42df commit 9dae4fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,9 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
errno = EINVAL;
return 0;
}
uval = labs(val);
uval = val < 0 ? -val : val;
uval *= factor;
if (uval > max || labs(val) > uval) {
if (uval > max || (val < 0 ? -val : val) > uval) {
errno = ERANGE;
return 0;
}
Expand Down

0 comments on commit 9dae4fe

Please sign in to comment.