← Back to team overview

kicad-developers team mailing list archive

PATCH: fix to various 3D issues reported by coverity

 

This patch fixes a number of issues reported by the latest coverity scan;
however it does not include a fix for one issue (I have asked Mario to help
fix this remaining one):

** CID 143741:  Memory - corruptions  (OVERRUN)
/3d-viewer/common_ogl/cogl_att_list.cpp: 64 in COGL_ATT_LIST::
GetAttributesList(bool)()


Fixed issues related to the 3D merge:

** CID 143752:  Incorrect expression  (USELESS_CALL)
/3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp: 178
in DLG_SELECT_3DMODEL::TransferDataFromWindow()()

*** CID 143751:  Incorrect expression  (UNUSED_VALUE)
/plugins/3d/vrml/v1/vrml1_shapehints.cpp: 39
in WRL1SHAPEHINTS::WRL1SHAPEHINTS(NAMEREGISTER *)()

*** CID 143749:  Uninitialized members  (UNINIT_CTOR)
/plugins/3d/vrml/v1/vrml1_shapehints.cpp: 55
in WRL1SHAPEHINTS::WRL1SHAPEHINTS(NAMEREGISTER *, WRL1NODE *)()

*** CID 143748:  Uninitialized members  (UNINIT_CTOR)
/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp: 268
in C_OGL_3DMODEL::C_OGL_3DMODEL(const S3DMODEL &)()

*** CID 143747:  Uninitialized members  (UNINIT_CTOR)
/utils/idftools/dxf2idf.h: 35
in DXF2IDF::DXF2IDF()()

*** CID 143746:  Uninitialized members  (UNINIT_CTOR)
/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp: 45
in C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY(CINFO3D_VISU &, S3D_CACHE
*)()

*** CID 143745:  Uninitialized members  (UNINIT_CTOR)
/plugins/3d/vrml/wrlproc.cpp: 59
in WRLPROC::WRLPROC(LINE_READER *)()

*** CID 143744:  Uninitialized members  (UNINIT_CTOR)
/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp: 97
in C3D_MODEL_VIEWER::C3D_MODEL_VIEWER(wxWindow *, const int *)()

*** CID 143740:  Null pointer dereferences  (NULL_RETURNS)
/plugins/3d/vrml/x3d/x3d_appearance.cpp: 122
in X3DAPP::readFields(wxXmlNode *)()

*** CID 143739:  Memory - corruptions  (MISMATCHED_ITERATOR)
/3d-viewer/3d_cache/sg/scenegraph.cpp: 136
in SCENEGRAPH::unlinkNode(const SGNODE *, bool)()

/3d-viewer/3d_cache/sg/scenegraph.cpp: 137
in SCENEGRAPH::unlinkNode(const SGNODE *, bool)()

*** CID 143735:  Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/plugins/3d/vrml/wrlproc.cpp: 169
in WRLPROC::getRawLine()()

*** CID 143734:  Error handling issues  (CHECKED_RETURN)
/3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp: 178
in DLG_SELECT_3DMODEL::TransferDataFromWindow()()
=== modified file '3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp'
--- 3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp	2016-01-26 00:50:01 +0000
+++ 3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp	2016-04-07 00:39:18 +0000
@@ -175,7 +175,7 @@
     m_model->rotation.z = 0.0;
 
     m_model->offset = m_model->rotation;
-    m_model->filename.empty();
+    m_model->filename.clear();
 
     wxString fname = m_FileTree->GetFilePath();
 

=== modified file '3d-viewer/3d_cache/sg/scenegraph.cpp'
--- 3d-viewer/3d_cache/sg/scenegraph.cpp	2016-03-21 07:39:25 +0000
+++ 3d-viewer/3d_cache/sg/scenegraph.cpp	2016-04-07 01:12:56 +0000
@@ -133,8 +133,19 @@
     if( NULL == aNode )
         return;
 
-    UNLINK_NODE( S3D::SGTYPE_TRANSFORM, SCENEGRAPH, aNode, m_Transforms, m_RTransforms, isChild );
-    UNLINK_NODE( S3D::SGTYPE_SHAPE, SGSHAPE, aNode, m_Shape, m_RShape, isChild );
+    switch( aNode->GetNodeType() )
+    {
+        case S3D::SGTYPE_TRANSFORM:
+            UNLINK_NODE( S3D::SGTYPE_TRANSFORM, SCENEGRAPH, aNode, m_Transforms, m_RTransforms, isChild );
+            break;
+
+        case S3D::SGTYPE_SHAPE:
+            UNLINK_NODE( S3D::SGTYPE_SHAPE, SGSHAPE, aNode, m_Shape, m_RShape, isChild );
+            break;
+
+        default:
+            break;
+    }
 
     #ifdef DEBUG
     do {

=== modified file '3d-viewer/3d_cache/sg/sg_helpers.h'
--- 3d-viewer/3d_cache/sg/sg_helpers.h	2016-03-14 01:30:59 +0000
+++ 3d-viewer/3d_cache/sg/sg_helpers.h	2016-04-07 01:18:39 +0000
@@ -82,8 +82,8 @@
             std::vector< aType* >::iterator eL; \
             if( isChild ) { \
                 oSL = &aOwnedList; \
-                sL =  aOwnedList.begin(); \
-                eL =  aOwnedList.end(); \
+                sL =  oSL->begin(); \
+                eL =  oSL->end(); \
                 while( sL != eL ) { \
                     if( (SGNODE*)*sL == aNode ) { \
                         oSL->erase( sL ); \
@@ -93,8 +93,8 @@
                 } \
             } else { \
                 oSL = &aRefList; \
-                sL =  aRefList.begin(); \
-                eL =  aRefList.end(); \
+                sL =  oSL->begin(); \
+                eL =  oSL->end(); \
                 while( sL != eL ) { \
                     if( (SGNODE*)*sL == aNode ) { \
                         delNodeRef( this ); \

=== modified file '3d-viewer/3d_model_viewer/c3d_model_viewer.cpp'
--- 3d-viewer/3d_model_viewer/c3d_model_viewer.cpp	2016-03-02 01:29:20 +0000
+++ 3d-viewer/3d_model_viewer/c3d_model_viewer.cpp	2016-04-07 01:25:59 +0000
@@ -91,6 +91,7 @@
     m_reload_is_needed = false;
     m_ogl_3dmodel = NULL;
     m_3d_model = NULL;
+    m_BiuTo3Dunits = 1.0;
 
     // Explicitly create a new rendering context instance for this canvas.
     m_glRC = new wxGLContext( this );

=== modified file '3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp'
--- 3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp	2015-12-08 07:31:57 +0000
+++ 3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp	2016-04-07 00:52:42 +0000
@@ -42,6 +42,7 @@
     m_ogl_disp_lists_layers.clear();
     m_triangles.clear();
     m_ogl_disp_list_board = 0;
+    m_ogl_circle_texture = 0;
 }
 
 

=== modified file '3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp'
--- 3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp	2016-04-05 10:32:22 +0000
+++ 3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp	2016-04-07 00:46:37 +0000
@@ -37,6 +37,7 @@
 {
     m_ogl_idx_list_opaque = 0;
     m_ogl_idx_list_transparent = 0;
+    m_ogl_idx_list_meshes = 0;
     m_nr_meshes = 0;
     m_meshs_bbox = NULL;
 

=== modified file 'plugins/3d/vrml/v1/vrml1_shapehints.cpp'
--- plugins/3d/vrml/v1/vrml1_shapehints.cpp	2016-02-23 00:20:34 +0000
+++ plugins/3d/vrml/v1/vrml1_shapehints.cpp	2016-04-07 00:44:25 +0000
@@ -36,7 +36,6 @@
 {
     m_order = ORD_UNKNOWN;
     m_Type = WRL1_SHAPEHINTS;
-    m_crease = 0.5;
     m_crease = 0.733;   // approx 42 degrees; this is larger than VRML spec.
     return;
 }
@@ -47,6 +46,7 @@
 {
     m_order = ORD_UNKNOWN;
     m_Type = WRL1_SHAPEHINTS;
+    m_crease = 0.733;   // approx 42 degrees; this is larger than VRML spec.
     m_Parent = aParent;
 
     if( NULL != m_Parent )

=== modified file 'plugins/3d/vrml/wrlproc.cpp'
--- plugins/3d/vrml/wrlproc.cpp	2016-04-05 10:32:22 +0000
+++ plugins/3d/vrml/wrlproc.cpp	2016-04-07 01:22:11 +0000
@@ -52,6 +52,7 @@
     m_eof = false;
     m_fileline = 0;
     m_bufpos = 0;
+    m_file = aLineReader;
 
     if( NULL == aLineReader )
     {
@@ -60,8 +61,6 @@
     }
 
     m_error.clear();
-    m_file = aLineReader;
-
     wxString tname = m_file->GetSource();
     m_filename = tname.ToUTF8();
     wxFileName fn( tname );
@@ -166,7 +165,7 @@
 
         while( sS != eS )
         {
-            if( '\xff' == ((*sS) & 0x80) )
+            if( ((*sS) & 0x80) )
             {
                 m_error = " non-ASCII character sequence in VRML1 file";
                 return false;

=== modified file 'plugins/3d/vrml/x3d/x3d_appearance.cpp'
--- plugins/3d/vrml/x3d/x3d_appearance.cpp	2016-02-23 00:20:34 +0000
+++ plugins/3d/vrml/x3d/x3d_appearance.cpp	2016-04-07 01:08:24 +0000
@@ -117,11 +117,11 @@
             m_MatName = prop->GetValue();
             m_Dict->AddName( m_MatName, this );
         }
-        if( pname == "USE" )
+        else if( pname == "USE" )
         {
             X3DNODE* np = m_Dict->FindName( prop->GetValue() );
 
-            if( np->GetNodeType() == X3D_APPEARANCE )
+            if( NULL != np && np->GetNodeType() == X3D_APPEARANCE )
             {
                 X3DAPP* ap = (X3DAPP*) np;
                 diffuseColor = ap->diffuseColor;

=== modified file 'utils/idftools/dxf2idf.cpp'
--- utils/idftools/dxf2idf.cpp	2016-04-05 17:56:01 +0000
+++ utils/idftools/dxf2idf.cpp	2016-04-07 00:49:55 +0000
@@ -280,7 +280,6 @@
 void DXF2IDF::addHeader( const DRW_Header* data )
 {
     std::map<std::string, DRW_Variant*>::const_iterator it;
-    m_scale = 1.0; // assume no scale factor
 
     for( it = data->vars.begin(); it != data->vars.end(); ++it )
     {

=== modified file 'utils/idftools/dxf2idf.h'
--- utils/idftools/dxf2idf.h	2016-04-05 17:56:01 +0000
+++ utils/idftools/dxf2idf.h	2016-04-07 00:49:12 +0000
@@ -38,6 +38,7 @@
     void insertArc( const IDF_POINT& aSegStart, const IDF_POINT& aSegEnd, double aBulge );
 
 public:
+    DXF2IDF() : m_scale( 1.0 ) {};
     ~DXF2IDF();
 
     bool ReadDxf( const std::string aFile );


Follow ups