New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use integer; 0x80000000/-1; # coredump #8321
Comments
From @nwc10Created by @nwc10The code use integer; will coredump on (at least) x86 FreeBSD, with a floating point exception. Do we want to trap this overflow case before things go boom? Nicholas Clark Perl Info
|
From @smpetersOn Fri, Feb 10, 2006 at 03:06:24PM -0800, Nicholas Clark wrote:
Odd. On Linux, I get a Floating Point Exception with a core dump. I'll Ideally, though, they should all gag and puke similarly rather than each Steve Peters |
The RT System itself - Status changed from 'new' to 'open' |
From @andk
> Odd. On Linux, I get a Floating Point Exception with a core dump. I'll What? On my Debian his program just works. Only a few very old perls (e.g. perl-5.5.650@5042 or perl-5.8.0@19096; -- Summary of my perl5 (revision 5 version 8 subversion 7) configuration: Characteristics of this binary (from libperl): |
From @smpetersOn Fri, Feb 10, 2006 at 05:31:58PM -0600, Steve Peters wrote:
Here's the backtrace... #0 0x0811bffe in Perl_pp_i_divide () at pp.c:2431 |
From @smpetersOn Fri, Feb 10, 2006 at 10:07:41PM -0600, Steve Peters wrote:
This problem seems to actually have a fairly simple solution. If you steve@kirk:~/perl-current$ ./perl -Ilib -Minteger -wle'print Since C<use integer> wraps all numbers greater the Perl's IV_MAX, only hange 27155 by stevep@stevep-mccoy on 2006/02/11 06:14:02 Die when integer overflow condition is detected in division Affected files ... ... //depot/perl/pp.c#518 edit Differences ... ==== //depot/perl/pp.c#518 (text) ==== @@ -2423,12 +2423,16 @@ PP(pp_i_divide) |
From @obra
On Apple's shipped 5.8.1rc3 on OSX 10.3, the program results in "Abort trap" |
From @AbigailOn Fri, Feb 10, 2006 at 03:06:24PM -0800, Nicholas Clark wrote:
Interesting, on Linux I only get an error ("Floating point exception") Abigail |
From @nwc10On Sat, Feb 11, 2006 at 11:26:22PM +0100, Abigail wrote:
With 64 bits, do you get the exception with 0x8000000000000000/-1 ? On FreeBSD with the system's 64 bit perl I see: $ perl -le '$a = -1-(~0>>1); print $a; {use integer; print $a/-1}' (the same system that will coredump for the 32 bit equivalent) Nicholas Clark |
From @AbigailOn Sat, Feb 11, 2006 at 10:58:36PM +0000, Nicholas Clark wrote:
Nope.
Same here. Abigail |
From @ysthOn Fri, Feb 10, 2006 at 03:06:24PM -0800, Nicholas Clark wrote:
That should do whatever: (IV)( (IV)0x80000000/(IV)-1 ) does in C. Even if that's give an exception. But I highly doubt it |
From @smpetersOn Sat, Feb 11, 2006 at 08:01:35PM -0800, Yitzchak Scott-Thoennes wrote:
Actually, this problem is an inherent part of the Intel (and other) Steve Peters |
From @smpetersOn Sun, Feb 12, 2006 at 01:25:10AM +0100, Abigail wrote:
I also did not run into problems with the above on a Perl built with Steve Peters |
From @andk
> I also did not run into problems with the above on a Perl built with That also explains why all my perls have no problem, I always use 64bitint. -- |
From @nwc10On Sun, Feb 12, 2006 at 04:34:39AM -0800, Steve Peters via RT wrote:
Well, the most "interesting" thing to do would be to set up the signal handler Nicholas Clark |
From @ysthOn Sun, Feb 12, 2006 at 05:34:01AM -0600, Steve Peters wrote:
Can you point out what part of that you meant? I didn't know that |
From nick@ing-simmons.netPaul Johnson <paul@pjcj.net> writes:
Why is / singled out ? Why not INT_MIN * -1 |
From @nwc10On Sun, Feb 12, 2006 at 08:48:26PM +0000, Nick Ing-Simmons wrote:
I think only because we've not yet found a platform where that throws a Nicholas Clark |
From @ysthOn Sun, Feb 12, 2006 at 06:02:03PM +0000, Nicholas Clark wrote:
Hmm. Is it really worth the extra code? Maybe we should just return |
From @pjcjOn Sun, Feb 12, 2006 at 06:02:03PM +0000, Nicholas Clark wrote:
If I remember correctly, the C standard could be a little more clear on But it's not always the case that -INT_MIN cannot be represented anyway, My opinion on this is that by using "integer" you are asking for In any case, whatever solution we have for 0x80000000 / -1 should -- |
From @ysthOn Sun, Feb 12, 2006 at 01:13:17PM -0800, Yitzchak Scott-Thoennes wrote:
I mean s/INT/IV/g. How about: Inline Patch--- perl/pp.c 2006-02-10 22:14:58.000000000 -0800
+++ p/pp.c 2006-02-12 13:49:54.803859200 -0800
@@ -2430,9 +2430,12 @@
if (value == 0)
DIE(aTHX_ "Illegal division by zero");
num = POPi;
+
+ /* avoid FPE_INTOVF on some platforms */
if (num == IV_MIN && value == -1)
- DIE(aTHX_ "Integer overflow in division");
- value = num / value;
+ value = IV_MIN;
+ else
+ value = num / value;
PUSHi( value );
RETURN;
}
@@ -2447,7 +2450,11 @@
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms */
+ if (left == IV_MIN && right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
}
@@ -2464,7 +2471,11 @@
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % PERL_ABS(right) );
+ /* avoid FPE_INTOVF on some platforms */
+ if (left == IV_MIN && right == -1)
+ SETi( 0 );
+ else
+ SETi( left % PERL_ABS(right) );
RETURN;
}
}
@@ -2505,7 +2516,11 @@
}
}
#endif
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms */
+ if (left == IV_MIN && right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
} |
From @ysthOn Sun, Feb 12, 2006 at 01:57:53PM -0800, Yitzchak Scott-Thoennes wrote:
Hmmm, that does assume wrapping the way two's complement does. value = - num; instead? I'm afraid I don't know anything about non-two's complement |
From @ysthintovf.patch--- perl/pp.c 2006-02-10 22:14:58.000000000 -0800
+++ p/pp.c 2006-02-12 22:14:00.555113600 -0800
@@ -2430,9 +2430,12 @@
if (value == 0)
DIE(aTHX_ "Illegal division by zero");
num = POPi;
- if (num == IV_MIN && value == -1)
- DIE(aTHX_ "Integer overflow in division");
- value = num / value;
+
+ /* avoid FPE_INTOVF on some platforms when num is IV_MIN */
+ if (value == -1)
+ value = - num;
+ else
+ value = num / value;
PUSHi( value );
RETURN;
}
@@ -2447,7 +2450,11 @@
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
}
@@ -2464,7 +2471,11 @@
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % PERL_ABS(right) );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % PERL_ABS(right) );
RETURN;
}
}
@@ -2505,7 +2516,11 @@
}
}
#endif
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
}
--- perl/lib/integer.t 2006-02-11 06:21:35.000000000 -0800
+++ p/lib/integer.t 2006-02-12 23:46:51.435646400 -0800
@@ -7,7 +7,7 @@
use integer;
-use Test::More tests => 12;
+use Test::More tests => 15;
use Config;
my $x = 4.5;
@@ -55,10 +55,15 @@
# [perl #38485] use integer; 0x80000000/-1;
SKIP: {
my $ivsize = $Config{ivsize};
- skip "ivsize == $ivsize", 2 unless $ivsize == 4 || $ivsize == 8;
+ skip "ivsize == $ivsize", 4 unless $ivsize == 4 || $ivsize == 8;
my $iv_min = $ivsize == 4 ? -2147483648 : -9223372036854775808;
my $biff;
eval { $biff = $iv_min / -1 };
- like($@, qr/Integer overflow in division/, "Caught IV_MIN / -1");
+ is($@, '', 'IV_MIN / -1 succeeds');
+ is($biff, -$iv_min, 'IV_MIN / -1 == -IV_MIN');
+
+ eval { $biff = $iv_min % -1 };
+ is($@, '', 'IV_MIN % -1 succeeds');
+ is($biff, 0, 'IV_MIN % -1 == 0');
}
|
From @ysthOn Sun, Feb 12, 2006 at 06:02:03PM +0000, Nicholas Clark wrote:
I *really* don't like what we are doing now (DIE()'ing, even on systems If no one wants to implement the above, can the patch in http://nntp.perl.org/group/perl.perl5.porters/109652 be applied, which should avoid the exception altogether? |
From @rgsYitzchak Scott-Thoennes wrote:
OK, I thus applied it as #27205, thanks ! |
From @ysthOn Fri, Feb 17, 2006 at 09:52:10AM +0100, Rafael Garcia-Suarez wrote:
Remove the now-unused perldiag entry: Inline Patch--- perl/pod/perldiag.pod.orig 2006-02-13 09:30:30.000000000 -0800
+++ perl/pod/perldiag.pod 2006-02-19 12:03:33.015625000 -0800
@@ -1976,16 +1976,6 @@
internally--subject to loss of precision errors in subsequent
operations.
-=item Integer overflow in division
-
-(F) In the scope of the C<use integer;> pragma, division would have overflowed.
-This will happen if you attempt to divide the largest negative integer by -1,
-since the result cannot be represented as a signed integer on a two's complement
-system. This division is trapped as a Perl-level exception because on some
-architectures the integer divide operation will trigger a CPU exception
-causing program exit, rather than merely returning a mathematically wrong
-answer.
-
=item Integer overflow in format string for %s
(F) The indexes and widths specified in the format string of C<printf()> |
From @rgarciaOn 2/19/06, Yitzchak Scott-Thoennes <sthoenna@efn.org> wrote:
Right; done as #27237, thanks. |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#38485 (status was 'resolved')
Searchable as RT38485$
The text was updated successfully, but these errors were encountered: