postgresql/src/backend
Tom Lane cbdb8b4c01 Fix float-to-integer coercions to handle edge cases correctly.
ftoi4 and its sibling coercion functions did their overflow checks in
a way that looked superficially plausible, but actually depended on an
assumption that the MIN and MAX comparison constants can be represented
exactly in the float4 or float8 domain.  That fails in ftoi4, ftoi8,
and dtoi8, resulting in a possibility that values near the MAX limit will
be wrongly converted (to negative values) when they need to be rejected.

Also, because we compared before rounding off the fractional part,
the other three functions threw errors for values that really ought
to get rounded to the min or max integer value.

Fix by doing rint() first (requiring an assumption that it handles
NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already),
and by comparing to values that should coerce to float exactly, namely
INTxx_MIN and -INTxx_MIN.  Also remove some random cosmetic discrepancies
between these six functions.

Per bug #15519 from Victor Petrovykh.  This should get back-patched,
but first let's see what the buildfarm thinks of it --- I'm not too
sure about portability of some of the regression test cases.

Patch by me; thanks to Andrew Gierth for analysis and discussion.

Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org
2018-11-23 20:57:11 -05:00
..
access Add WL_EXIT_ON_PM_DEATH pseudo-event. 2018-11-23 20:46:34 +13:00
bootstrap Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
catalog Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
commands Don't allow partitioned indexes in pg_global tablespace 2018-11-23 08:48:20 -03:00
executor Add WL_EXIT_ON_PM_DEATH pseudo-event. 2018-11-23 20:46:34 +13:00
foreign Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
jit Make TupleTableSlots extensible, finish split of existing slot type. 2018-11-16 16:35:15 -08:00
lib Rename rbtree.c functions to use "rbt" prefix not "rb" prefix. 2018-11-06 13:25:24 -05:00
libpq Add WL_EXIT_ON_PM_DEATH pseudo-event. 2018-11-23 20:46:34 +13:00
main Update copyright for 2018 2018-01-02 23:30:12 -05:00
nodes Revise attribute handling code on partition creation 2018-11-08 16:22:09 -03:00
optimizer Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
parser Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
partitioning Reduce unnecessary list construction in RelationBuildPartitionDesc. 2018-11-19 12:10:41 -05:00
po Translation updates 2018-06-25 12:37:18 +02:00
port Fix spelling errors and typos in comments 2018-11-02 13:56:52 +01:00
postmaster Silence compiler warnings 2018-11-23 13:01:05 -03:00
regex Clean up warnings from -Wimplicit-fallthrough. 2018-05-01 19:35:08 -04:00
replication Add WL_EXIT_ON_PM_DEATH pseudo-event. 2018-11-23 20:46:34 +13:00
rewrite Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
snowball Sync our Snowball stemmer dictionaries with current upstream. 2018-09-24 17:29:38 -04:00
statistics Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
storage Add WL_EXIT_ON_PM_DEATH pseudo-event. 2018-11-23 20:46:34 +13:00
tcop Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
tsearch Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
utils Fix float-to-integer coercions to handle edge cases correctly. 2018-11-23 20:57:11 -05:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Refactor dlopen() support 2018-09-06 11:33:04 +02:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2018-06-25 12:37:18 +02:00