[REVIEW] Null pointer passed as an argument to a 'nonnull' parameter in tools/source/generic/poly.cxx
Stephan Bergmann
sbergman at redhat.com
Thu Feb 16 23:57:42 PST 2012
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
More information about the LibreOffice
mailing list