Date: prev next · Thread: first prev next last
2010 Archives by date, by thread · List index


On Sun, Nov 7, 2010 at 7:00 AM, julien <serval2412@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@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.