pgsql: Make sampler_random_fract() actually obey its API contract.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make sampler_random_fract() actually obey its API contract.
Date: 2015-07-01 22:08:05
Message-ID: E1ZAQAo-0006Gi-02@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make sampler_random_fract() actually obey its API contract.

This function is documented to return a value in the range (0,1),
which is what its predecessor anl_random_fract() did. However, the
new version depends on pg_erand48() which returns a value in [0,1).
The possibility of returning zero creates hazards of division by zero
or trying to compute log(0) at some call sites, and it might well
break third-party modules using anl_random_fract() too. So let's
change it to never return zero. Spotted by Coverity.

Michael Paquier, cosmetically adjusted by me

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/cd7030ff085f5c378e837b392cb719cf23df9d0b

Modified Files
--------------
src/backend/utils/misc/sampling.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2015-07-01 22:55:48 pgsql: Don't leave pg_hba and pg_ident data lying around in running bac
Previous Message Fujii Masao 2015-07-01 01:56:02 pgsql: Make XLogFileCopy() look the same as in 9.4.