plpgsql FOR loop doesn't guard against strange step values

Поиск
Список
Период
Сортировка
I just noticed that when the BY option was added to plpgsql FOR loops,
no real error checking was done.  If you specify a zero step value,
you'll have an infinite loop.  If you specify a negative value, the
loop variable will increment in the "wrong direction" until integer
overflow occurs.  Neither of these behaviors seem desirable in the
least.

Another problem is that no check for overflow is done when incrementing
the loop variable, which means that an infinite loop is possible if the
step value is larger than the distance from the loop upper bound to
INT_MAX --- the loop variable could overflow before it is seen to be
greater than the upper bound, and after wrapping around to negative
it's still less than the upper bound, so the loop continues to run.

I suggest throwing an error for zero or negative step value, and
terminating the loop if the loop variable overflows.

Any objections?
        regards, tom lane


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

Предыдущее
От: Guillaume Lelarge
Дата:
Сообщение: Re: non-blocking CREATE INDEX in 8.2??
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: plpgsql FOR loop doesn't guard against strange step values