summaryrefslogtreecommitdiff
path: root/pp_sort.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-10-12 22:53:31 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-10-12 23:28:30 -0700
commitf3dab52a514ffb23bcde784e897bc8ff4c2018f2 (patch)
tree45c51bbc2acab5a8f5d757a3c76e4943bbdfa712 /pp_sort.c
parentd4c6760ad383a9419aef88be3abd479ebcfb6d36 (diff)
downloadperl-f3dab52a514ffb23bcde784e897bc8ff4c2018f2.tar.gz
[perl #94390] Optimised numeric sort should warn for nan
In this case: sort { $a <=> $b } ... the sort block is optimised away and implemented in C. That C implementation did not take into account that $a or $b might be nan, and therefore, without optimisation, would return undef, result- ing in a warning. The optimisation is supposed to be just that, and not change behaviour.
Diffstat (limited to 'pp_sort.c')
-rw-r--r--pp_sort.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/pp_sort.c b/pp_sort.c
index fafa00acf2..0ee42dcf38 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1874,6 +1874,14 @@ S_sv_ncmp(pTHX_ SV *const a, SV *const b)
PERL_ARGS_ASSERT_SV_NCMP;
+#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
+ if (Perl_isnan(right) || Perl_isnan(left)) {
+#else
+ if (nv1 != nv1 || nv2 != nv2) {
+#endif
+ if (ckWARN(WARN_UNINITIALIZED)) report_uninit(NULL);
+ return 0;
+ }
return nv1 < nv2 ? -1 : nv1 > nv2 ? 1 : 0;
}