From dcdaee4c639ece4fb8409b2198610fb713274ce8 Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo Date: Tue, 17 Feb 2015 09:56:45 -0500 Subject: [PATCH] Pcbnew IDF and VRML exporter Coverity scan error fixes. --- pcbnew/exporters/export_vrml.cpp | 14 +++++++++----- utils/idftools/idf_parser.cpp | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp index 2674a3cd2a..07e6a94df9 100644 --- a/pcbnew/exporters/export_vrml.cpp +++ b/pcbnew/exporters/export_vrml.cpp @@ -185,7 +185,11 @@ public: colors[ VRML_COLOR_TIN ] = VRML_COLOR( .749, .756, .761, .749, .756, .761, 0, 0, 0, 0.8, 0, 0.8 ); - precision = 5; + plainPCB = false; + SetScale( 1.0 ); + SetOffset( 0.0, 0.0 ); + s_text_layer = F_Cu; + s_text_width = 1; } VRML_COLOR& GetColor( VRML_COLOR_INDEX aIndex ) @@ -889,11 +893,11 @@ static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb ) const CPOLYGONS_LIST& poly = zone->GetFilledPolysList(); int nvert = poly.GetCornersCount(); int i = 0; + bool cutout = false; while( i < nvert ) { int seg = vl->NewContour(); - bool first = true; if( seg < 0 ) break; @@ -914,10 +918,10 @@ static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb ) // KiCad ensures that the first polygon is the outline // and all others are holes - vl->EnsureWinding( seg, first ? false : true ); + vl->EnsureWinding( seg, cutout ); - if( first ) - first = false; + if( !cutout ) + cutout = true; ++i; } diff --git a/utils/idftools/idf_parser.cpp b/utils/idftools/idf_parser.cpp index abf21b721d..68a45d7f7c 100644 --- a/utils/idftools/idf_parser.cpp +++ b/utils/idftools/idf_parser.cpp @@ -2425,12 +2425,18 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib while( !FetchIDFLine( aLibFile, iline, isComment, pos ) && aLibFile.good() ); if( !aLibFile.good() && !aLibFile.eof() ) + { + delete pout; throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "problems reading library section" ) ); + } // no data was read; this only happens at eof() if( iline.empty() ) + { + delete pout; return; + } if( isComment ) { @@ -2448,6 +2454,7 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib ostr << "* Violation of specification: quoted string where .ELECTRICAL or .MECHANICAL expected\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* pos: " << pos; + delete pout; throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } @@ -2509,6 +2516,8 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib } } + delete pout; + if( !aLibFile.eof() ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "problems reading IDF library file" ) );