summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorTAKAI Kousuke <62541129+t-a-k@users.noreply.github.com>2022-02-09 22:42:56 +0900
committerHugo van der Sanden <hv@crypt.org>2022-02-13 13:59:58 +0000
commit7e511f6af1284c3490ebea9e18421d6179a77ba5 (patch)
treea3f3d6a257d01dbd41cf30ed24a4f845bff79a6e /t
parent10e9e4713b05ebd0779cfb639879f2e86da6ee35 (diff)
downloadperl-7e511f6af1284c3490ebea9e18421d6179a77ba5.tar.gz
sv.c: String "Inf" is now consistently converted to IV/UV
S_sv_2iuv_common() used to fail to set IV/UV slot on direct conversion from string "Inf" to IV/UV, so such conversion would return garbage on the memory. Now it will return the same result with two-staged conversions, string to NV first and then NV to IV/UV.
Diffstat (limited to 't')
-rw-r--r--t/op/infnan.t14
1 files changed, 14 insertions, 0 deletions
diff --git a/t/op/infnan.t b/t/op/infnan.t
index 7a2de7d79c..0f92c82705 100644
--- a/t/op/infnan.t
+++ b/t/op/infnan.t
@@ -562,4 +562,18 @@ cmp_ok('-1e-9999', '==', 0, "underflow to 0 (runtime) from neg");
}
}
+# "+Inf" should be converted to UV consistently
+{
+ my $uv_max = ~0;
+ my $x = 42; # Some arbitrary integer.
+ $x = ' Inf '; # Spaces will detect unwanted string/NV round-trip
+ is($x << 0, $uv_max, "' Inf ' converted to UV");
+ # Test twice just in case if SvUV is tricked by cached NV
+ is($x << 0, $uv_max, "second conversion of ' Inf ' to UV");
+ # Cached NV should be Inf even after conversion to UV returned UV_MAX
+ cmp_ok($x, '==', $PInf, "NV value of ' Inf ' after UV conversion");
+ # String value should not be changed
+ is($x, ' Inf ', "string shall be ' Inf ' after UV/NV conversion");
+}
+
done_testing();