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


On 02/16/2012 09:43 PM, julien2412 wrote:
/home/julien/compile-libreoffice/libo/tools/source/generic/poly.cxx:91:9:
warning: Null pointer passed as an argument to a 'nonnull' parameter
         memset( mpPointAry, 0, nInitSize );
         ^       ~~~~~~~~~~
1 warning generated.

Here are the lines :
      78 ImplPolygon::ImplPolygon( sal_uInt16 nInitSize, sal_Bool bFlags  )
      79 {
      80     if ( nInitSize )
      81     {
      82         mpPointAry = (Point*)new
char[(sal_uIntPtr)nInitSize*sizeof(Point)];
      83         memset( mpPointAry, 0, (sal_uIntPtr)nInitSize*sizeof(Point)
);
      84     }
      85     else
      86         mpPointAry = NULL;
      87
      88     if( bFlags )
      89     {
      90         mpFlagAry = new sal_uInt8[ nInitSize ];
      91         memset( mpPointAry, 0, nInitSize );<<<<<  HERE
      92     }
      93     else
      94         mpFlagAry = NULL;
      95
      96     mnRefCount = 1;
      97     mnPoints = nInitSize;
      98 }

[...]

Cppcheck updated today doesn't detect this problem so I confirm fdo#39596
could be useful :-)
(could also be a cppcheck enhancement proposal, I didn't check if it had
already been proposed)

The irony is that, while it apparently found a genuine bug here, the compiler's reasoning might actually be wrong. I'm not 100% sure, but if C only requires that the first argument to memset must be non-null if the third argument is non-zero, then the compiler would obviously not be correct in flagging the above code.

Stephan

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.