Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

Fix stringified IV_MIN sometimes unintentionally treated as NV #22171

Open t-a-k opened 3 weeks ago

t-a-k commented 3 weeks ago

String representation of IV_MIN ("-9223372036854775808" in typical 64bit build) is expected to be treated as IV in numeric context, but current perl sometimes treat it as NV.

In !NV_PRESERVES_UV case (e.g. IV and NV are both 64-bit, as in typical x86_64 build), if such string is once referred in NV context (with sv_2nv_flags()), it will be unexpectedly treated as NV in subsequent numeric references:

$ perl -wle 'my $x = my $y = "-9223372036854775808"; my $z = $x + 1.23; print $x + 0; print $y + 0'
-9.22337203685478e+18
-9223372036854775808
$

This change will hopefully resolve this.