64-bit integer subtraction bug on some platforms

Поиск
Список
Период
Сортировка
От Dean Rasheed
Тема 64-bit integer subtraction bug on some platforms
Дата
Msg-id CAEZATCUNK-AZSD0jVdgkk0N=NcAXBWeAEX-QU9AnJPensikmdQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: 64-bit integer subtraction bug on some platforms  (Laurenz Albe <laurenz.albe@cybertec.at>)
Список pgsql-hackers
One of the new tests in the infinite interval patch has revealed a bug
in our 64-bit integer subtraction code. Consider the following:

select 0::int8 - '-9223372036854775808'::int8;

This should overflow, since the correct result (+9223372036854775808)
is out of range. However, on platforms without integer overflow
builtins or 128-bit integers, pg_sub_s64_overflow() does the
following:

    if ((a < 0 && b > 0 && a < PG_INT64_MIN + b) ||
        (a > 0 && b < 0 && a > PG_INT64_MAX + b))
    {
        *result = 0x5EED;        /* to avoid spurious warnings */
        return true;
    }
    *result = a - b;
    return false;

which fails to spot the fact that overflow is also possible when a ==
0. So on such platforms, it returns the wrong result.

Patch attached.

Regards,
Dean

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: shveta malik
Дата:
Сообщение: Re: Synchronizing slots from primary to standby
Следующее
От: Dean Rasheed
Дата:
Сообщение: Re: Infinite Interval