Skip to content

Commit a034042

Browse files
committed
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 <[email protected]>
1 parent e213867 commit a034042

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,9 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
869869
errno = EINVAL;
870870
return 0;
871871
}
872-
uval = labs(val);
872+
uval = val < 0 ? -val : val;
873873
uval *= factor;
874-
if (uval > max || labs(val) > uval) {
874+
if (uval > max || (val < 0 ? -val : val) > uval) {
875875
errno = ERANGE;
876876
return 0;
877877
}

0 commit comments

Comments
 (0)