Hello,

Advancing on the cclang compilation, I noticed this :
/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 }

So if I just follow the "pattern", here's an obvious patch :
diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx
index 3c86a7a..4e71b35 100644
--- a/tools/source/generic/poly.cxx
+++ b/tools/source/generic/poly.cxx
@@ -88,7 +88,7 @@ ImplPolygon::ImplPolygon( sal_uInt16 nInitSize, sal_Bool
bFlags  )
     if( bFlags )
     {
         mpFlagAry = new sal_uInt8[ nInitSize ];
-        memset( mpPointAry, 0, nInitSize );
+        memset( mpFlagAry, 0, nInitSize );
     }
     else
         mpFlagAry = NULL;

I suppose it's ok to push this fix on master but would it be useful to push
this on 3.5 branch too ?

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) 

Julien.

--
View this message in context: 
http://nabble.documentfoundation.org/REVIEW-Null-pointer-passed-as-an-argument-to-a-nonnull-parameter-in-tools-source-generic-poly-cxx-tp3751838p3751838.html
Sent from the Dev mailing list archive at Nabble.com.
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to