1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-06 09:56:12 +02:00

config: avoid calling `labs()` on too-large data type

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>
This commit is contained in:
Johannes Schindelin 2019-06-13 04:49:47 -07:00 committed by Junio C Hamano
parent 4fa42df972
commit 9dae4fe79f

View File

@ -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;
}