Re: BUG #5592: list of integer undefined behaviors

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #5592: list of integer undefined behaviors
Дата
Msg-id 6689.1280802798@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: BUG #5592: list of integer undefined behaviors  (Greg Stark <gsstark@mit.edu>)
Ответы Re: BUG #5592: list of integer undefined behaviors  (Greg Stark <gsstark@mit.edu>)
Список pgsql-bugs
Greg Stark <gsstark@mit.edu> writes:
> On Mon, Aug 2, 2010 at 7:16 PM, John Regehr <regehr@cs.utah.edu> wrote:
>> <nabstime.c, (1193:21)> : Op: -, Reason : Signed Subtraction Overflow,
>> BINARY OPERATION: left (int32): 2147483644 right (int32): -2147483648
>>
>> <nabstime.c, (1194:21)> : Op: -, Reason : Signed Subtraction Overflow,
>> BINARY OPERATION: left (int32): 2147483644 right (int32): -2147483648

> These seem to imply that tinterval can contain a start point greater
> than its end point.

On closer investigation, the problem is just that you can't fit the
difference INT_MAX minus INT_MIN into an int :-(.

The particular values cited appear to be NOEND_ABSTIME and
NOSTART_ABSTIME, ie "infinity" and "-infinity" in the abstime datatype,
so this is coming from tinterval comparisons involving this value
in the regression tests:

INSERT INTO TINTERVAL_TBL (f1)
   VALUES ('["-infinity" "infinity"]');

Although this is the worst case, you could easily get overflows from
intervals with ordinary endpoints that are sufficiently far apart.

Since this is a nearly-dead legacy datatype, I can't get excited about
spending a lot of time on it.  What I suggest we do is do the difference
calculation in int64 arithmetic instead of int32.

Another complaint that could be leveled against this code is that
infinity and minus infinity behave way too much like ordinary mortal
timestamps.  It would be very easy to select finite timestamps
a, b, c such that this code thinks [a b] is a longer interval than
[c infinity], which is surprising to say the least.  However, I can't
get excited about fixing that for abstime/tinterval.  It might be
something to consider if anyone ever reimplements this type in a way
that isn't going to fall over in 2038.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #5592: list of integer undefined behaviors
Следующее
От: Greg Stark
Дата:
Сообщение: Re: BUG #5592: list of integer undefined behaviors