File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -296,7 +296,12 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
296
296
297
297
if (GIST_LEAF (entry ))
298
298
{ /* all leafs contains orig trgm */
299
- float4 tmpsml = cnt_sml (qtrg , key , * recheck );
299
+ /*
300
+ * Prevent gcc optimizing the tmpsml variable using volatile
301
+ * keyword. Otherwise comparison of nlimit and tmpsml may give
302
+ * wrong results.
303
+ */
304
+ float4 volatile tmpsml = cnt_sml (qtrg , key , * recheck );
300
305
301
306
/* strange bug at freebsd 5.2.1 and gcc 3.3.3 */
302
307
res = (* (int * ) & tmpsml == * (int * ) & nlimit || tmpsml > nlimit );
@@ -471,7 +476,13 @@ gtrgm_distance(PG_FUNCTION_ARGS)
471
476
* recheck = strategy == SubwordDistanceStrategyNumber ;
472
477
if (GIST_LEAF (entry ))
473
478
{ /* all leafs contains orig trgm */
474
- res = 1.0 - cnt_sml (qtrg , key , * recheck );
479
+ /*
480
+ * Prevent gcc optimizing the sml variable using volatile
481
+ * keyword. Otherwise res can differ from the
482
+ * subword_similarity_dist_op() function.
483
+ */
484
+ float4 volatile sml = cnt_sml (qtrg , key , * recheck );
485
+ res = 1.0 - sml ;
475
486
}
476
487
else if (ISALLTRUE (key ))
477
488
{ /* all leafs contains orig trgm */
Original file line number Diff line number Diff line change @@ -1157,4 +1157,4 @@ subword_similarity_dist_commutator_op(PG_FUNCTION_ARGS)
1157
1157
PG_FREE_IF_COPY (in1 , 0 );
1158
1158
PG_FREE_IF_COPY (in2 , 1 );
1159
1159
PG_RETURN_FLOAT4 (1.0 - res );
1160
- }
1160
+ }
You can’t perform that action at this time.
0 commit comments