config: avoid calling `labs()` on too-large data type
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 13 Jun 2019 11:49:47 +0000 (04:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Jun 2019 16:34:17 +0000 (09:34 -0700)
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>
config.c
index 296a6d9cc4110bd7fcef542ac9cc9cfe04d4f4d4..01c6e9df23c6a8f35fc70dcfc1275d4f3f9a1f2b 100644 (file)
--- a/config.c
+++ b/config.c
@@ -869,9 +869,9 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
                        errno = EINVAL;
                        return 0;
                }
                        errno = EINVAL;
                        return 0;
                }
-               uval = labs(val);
+               uval = val < 0 ? -val : val;
                uval *= factor;
                uval *= factor;
-               if (uval > max || labs(val) > uval) {
+               if (uval > max || (val < 0 ? -val : val) > uval) {
                        errno = ERANGE;
                        return 0;
                }
                        errno = ERANGE;
                        return 0;
                }