[Libreoffice] [PATCH] fix for crash in math.cxx for std::numeric_limits<int>::min

Stephan Bergmann sbergman at redhat.com
Tue Dec 13 00:29:33 PST 2011


On 12/13/2011 12:15 AM, Markus Mohrhard wrote:
> diff --git a/sal/rtl/source/math.cxx b/sal/rtl/source/math.cxx
> index 947f733..d118dde 100644
> --- a/sal/rtl/source/math.cxx
> +++ b/sal/rtl/source/math.cxx
> @@ -59,7 +59,7 @@ static double getN10Exp( int nExp )
>  {
>      if ( nExp < 0 )
>      {
> -        if ( -nExp <= n10Count )
> +        if ( -nExp <= n10Count && -nExp > 0 )

I think you should add a comment here, to make it clear what the---at a 
cursory glance strange looking---check is good for.  (Strictly speaking, 
"-nExp" incurs undefined behaviour if its correct numerical value cannot 
be represented as an int, of course.  But we assume "graceful" 
two's-complement behaviour all over the place, anyway.)

Stephan

>              return n10s[1][-nExp-1];
>          else
>              return pow( 10.0, static_cast<double>( nExp ) );


More information about the LibreOffice mailing list