[Libreoffice] Questions about ./sdext/source/minimizer/unodialog.cxx

Norbert Thiebaud nthiebaud at gmail.com
Sun Nov 7 10:33:32 PST 2010


On Sun, Nov 7, 2010 at 7:00 AM, julien <serval2412 at yahoo.fr> wrote:
> Hello,
>
> I'm currently running a cppcheck on the clone directory (i had try to launch
> cppcheck on the build/libreoffice... but it seemed it freezed).
> I've seen this issue :
> [./extensions/sdext/source/minimizer/unodialog.cxx:359]: (error) Division by
> zero
>
> I opened the file and saw this :
> sal_Int32 UnoDialog::getMapsFromPixels( sal_Int32 nPixels ) const
> {
>    double dMaps = 0;
>    try
>    {
>        sal_Int32 nMapWidth = 0;
>        const OUString sWidth( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
>        if ( mxDialogModelPropertySet->getPropertyValue( sWidth  ) >>=
> nMapWidth )
>        {
>            Reference< XWindow > xWindow( mxDialog, UNO_QUERY_THROW );
>            double pxWidth = xWindow->getPosSize().Width;
>            double mapRatio = ( pxWidth / nMapWidth ); ------- HERE IS THE
> DIVSION BY ZERO DETECTED BY CPPCHECK
>            dMaps = nPixels / mapRatio;
>        }
>    }
>    catch ( Exception& )
>    {
>    }
>    return static_cast< sal_Int32 >( dMaps );
> }
>
> Questions :
> - what's the use of nMapWidth since it's initialized to 0 and stays at this
> value ?
> - What's the use of making a right rotation of bits of 0 ?
> (mxDialogModelPropertySet->getPropertyValue( sWidth  ) >>= nMapWidth)

Ahh, welcome to the wonderful world of operator overload.
>>= is not a right shift but instead, here, nMapWith get populated with the property (uno) value, converted to a int32.

and the if() can only be true if that value is not 0
so here you have a false positive.

Norbert

> - what's the use of a catch with nothing in it except for hidding a bug ?
>
> _______________________________________________
> LibreOffice mailing list
> LibreOffice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/libreoffice
>


More information about the LibreOffice mailing list