]> granicus.if.org Git - postgresql/commit
Improve handling of INT_MIN / -1 and related cases.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Nov 2012 02:22:00 +0000 (21:22 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Nov 2012 02:22:00 +0000 (21:22 -0500)
commit3352e25e85b28ee1f21e0a759c0c49e399cb032a
tree426ee412dc0990ca7cf236830a84a221edcf8a81
parent8728fdce97e2012cb3715ddc294ab9e54967ef7c
Improve handling of INT_MIN / -1 and related cases.

Some platforms throw an exception for this division, rather than returning
a necessarily-overflowed result.  Since we were testing for overflow after
the fact, an exception isn't nice.  We can avoid the problem by treating
division by -1 as negation.

Add some regression tests so that we'll find out if any compilers try to
optimize away the overflow check conditions.

Back-patch of commit 1f7cb5c30983752ff8de833de30afcaee63536d0.

Per discussion with Xi Wang, though this is different from the patch he
submitted.
src/backend/utils/adt/int.c
src/backend/utils/adt/int8.c
src/test/regress/expected/int2.out
src/test/regress/expected/int4.out
src/test/regress/expected/int8-exp-three-digits.out
src/test/regress/expected/int8.out
src/test/regress/sql/int2.sql
src/test/regress/sql/int4.sql
src/test/regress/sql/int8.sql