On Sun Apr 04 21:29:15 2010, SPROUT wrote:
Show quoted text> On Sun Mar 21 21:44:05 2010, TONYC wrote:
> > The following command produces a seg fault:
> >
> > tony@mars:~$ perl -Mbigrat -e 'sqrt(2)'
> > Segmentation fault
> >
> > while:
> >
> > tony@mars:~$ perl -Mbigrat -e 'sqrt(2.0)'
> >
> > doesn't. This has been reported as a bug in perl
> >
> >
http://rt.perl.org/rt3/Ticket/Display.html?id=73534
> > Bigrat segfaults on irrational numbers
> >
> > but from what I can see this is a problem in bignum or Math-BigInt,
> my
> > notes from [perl #72534]:
> >
> > The problem seems to be that a Math::BigInt object (from the value
> 2)
> > is being passed Math::BigFloat::bsqrt().
> >
> > Line 2097 of Math::BigFloat then attempts to copy the mantissa (_m)
> > but since $x isn't a Math::BigFloat it passes undef to the _copy()
> > method.
> >
> > So x at Math::BigInt::FastCalc line 117 is an undef SV, the SvRV()
> > call returns NULL, and av_len() segfaults or fails the assertion.
>
> The problem seems to be in &Math::BigInt::objectify. It doesn’t try to
> convert the number
> object into the right class if $upgrade is defined. The attached patch
> changes it to make sure
> it belongs to the calling class or to the $upgrade class.
>
> Here is a ‘one’-liner to trigger the same bug without bigrat:
>
> perl -Ilib -MMath::BigInt=upgrade,Math::BigFloat
> -MMath::BigFloat=upgrade,Math::BigMouse
> -le '@Math::BigMouse::ISA = Math::BigFloat; print sqrt Math::BigInt-
> >new(2)'
>
> And here it is as a test. I’m not sure which file it should go in:
>
> use Math::BigInt upgrade => 'Math::BigFloat';
> use Math::BigFloat upgrade => 'Math::BigMouse';
> no warnings 'once';
> @Math::BigMouse::ISA = 'Math::BigFloat';
> sqrt Math::BigInt->new(2);
> pass('sqrt on a big int does not segv if there are two levels of
> upgrade classes');
Applied to perl.git/blead as 45029d2.