Skip to content

Commit 5597fee

Browse files
committed
Avoid getting bit by roundoff error while checking $Safe::VERSION.
Per report from Mark Kirkwood.
1 parent e17766c commit 5597fee

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/pl/plperl/plperl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ENHANCEMENTS, OR MODIFICATIONS.
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.63 2004/11/23 00:21:17 tgl Exp $
36+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.64 2004/11/24 18:47:38 tgl Exp $
3737
*
3838
**********************************************************************/
3939

@@ -238,13 +238,18 @@ plperl_safe_init(void)
238238
;
239239

240240
SV *res;
241-
float safe_version;
241+
double safe_version;
242242

243243
res = eval_pv(safe_module, FALSE); /* TRUE = croak if failure */
244244

245245
safe_version = SvNV(res);
246246

247-
eval_pv((safe_version < 2.09 ? safe_bad : safe_ok), FALSE);
247+
/*
248+
* We actually want to reject safe_version < 2.09, but it's risky to
249+
* assume that floating-point comparisons are exact, so use a slightly
250+
* smaller comparison value.
251+
*/
252+
eval_pv((safe_version < 2.0899 ? safe_bad : safe_ok), FALSE);
248253

249254
plperl_safe_init_done = true;
250255
}

0 commit comments

Comments
 (0)