Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7c19d6

Browse files
committed
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, thenew version depends on pg_erand48() which returns a value in [0,1).The possibility of returning zero creates hazards of division by zeroor trying to compute log(0) at some call sites, and it might wellbreak third-party modules using anl_random_fract() too. So let'schange it to never return zero. Spotted by Coverity.Michael Paquier, cosmetically adjusted by me
1 parent8217370 commitd7c19d6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

‎src/backend/utils/misc/sampling.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,14 @@ sampler_random_init_state(long seed, SamplerRandomState randstate)
237237
double
238238
sampler_random_fract(SamplerRandomStaterandstate)
239239
{
240-
returnpg_erand48(randstate);
240+
doubleres;
241+
242+
/* pg_erand48 returns a value in [0.0 - 1.0), so we must reject 0 */
243+
do
244+
{
245+
res=pg_erand48(randstate);
246+
}while (res==0.0);
247+
returnres;
241248
}
242249

243250

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp