Commit 1acfbb0d authored by Cirilo Bernardo's avatar Cirilo Bernardo Committed by Wayne Stambaugh

Coverity scan IDF fixes.

* Fix resource leak in idf_parser.cpp
* Fix logically dead code in idf_parser.cpp
* Fix use after free bug in idf_parser.cpp
* Fix unitialized scalar value in idf_parser.cpp
* Fix logically dead code in idf_outlines.cpp
* Fix unitialized scalar value in idf_outlines.cpp
* Fix invalid iterator in idf_common.cpp
* Fix unitialized scalar value in vrml_layer.cpp
parent f2edf02b
...@@ -950,7 +950,7 @@ void IDF3::GetOutline( std::list<IDF_SEGMENT*>& aLines, ...@@ -950,7 +950,7 @@ void IDF3::GetOutline( std::list<IDF_SEGMENT*>& aLines,
PrintSeg( *bl ); PrintSeg( *bl );
#endif #endif
aOutline.push( *bl ); aOutline.push( *bl );
aLines.erase( bl ); bl = aLines.erase( bl );
} }
continue; continue;
...@@ -982,7 +982,7 @@ void IDF3::GetOutline( std::list<IDF_SEGMENT*>& aLines, ...@@ -982,7 +982,7 @@ void IDF3::GetOutline( std::list<IDF_SEGMENT*>& aLines,
printSeg( *bl ); printSeg( *bl );
#endif #endif
aOutline.push( *bl ); aOutline.push( *bl );
aLines.erase( bl ); bl = aLines.erase( bl );
} }
continue; continue;
......
...@@ -377,7 +377,7 @@ void BOARD_OUTLINE::readOutlines( std::ifstream& aBoardFile, IDF3::IDF_VERSION a ...@@ -377,7 +377,7 @@ void BOARD_OUTLINE::readOutlines( std::ifstream& aBoardFile, IDF3::IDF_VERSION a
} }
// verify winding of previous outline // verify winding of previous outline
if( ( loopidx = 0 && !op->IsCCW() ) if( ( loopidx == 0 && !op->IsCCW() )
|| ( loopidx > 0 && op->IsCCW() ) ) || ( loopidx > 0 && op->IsCCW() ) )
{ {
ostringstream ostr; ostringstream ostr;
...@@ -2232,10 +2232,11 @@ PLACE_OUTLINE::PLACE_OUTLINE( IDF3_BOARD* aParent ) ...@@ -2232,10 +2232,11 @@ PLACE_OUTLINE::PLACE_OUTLINE( IDF3_BOARD* aParent )
setParent( aParent ); setParent( aParent );
outlineType = OTLN_PLACE; outlineType = OTLN_PLACE;
single = true; single = true;
thickness = 0.0; thickness = -1.0;
side = LYR_INVALID; side = LYR_INVALID;
} }
bool PLACE_OUTLINE::SetSide( IDF3::IDF_LAYER aSide ) bool PLACE_OUTLINE::SetSide( IDF3::IDF_LAYER aSide )
{ {
#ifndef DISABLE_IDF_OWNERSHIP #ifndef DISABLE_IDF_OWNERSHIP
...@@ -2424,64 +2425,74 @@ void PLACE_OUTLINE::readData( std::ifstream& aBoardFile, const std::string& aHea ...@@ -2424,64 +2425,74 @@ void PLACE_OUTLINE::readData( std::ifstream& aBoardFile, const std::string& aHea
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
} }
if( !GetIDFString( iline, token, quoted, idx ) ) if( GetIDFString( iline, token, quoted, idx ) )
{ {
ostringstream ostr; std::stringstream teststr;
teststr << token;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n"; teststr >> thickness;
ostr << "* violation: no height specified\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); if( teststr.fail() )
} {
ostringstream ostr;
std::stringstream teststr; ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
teststr << token; ostr << "* violation: invalid height\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
teststr >> thickness; throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
if( teststr.fail() ) }
{
ostringstream ostr;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n"; if( thickness < 0.0 )
ostr << "* violation: invalid height\n"; {
ostr << "* line: '" << iline << "'\n"; ostringstream ostr;
ostr << "* file position: " << pos;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
} ostr << "* violation: thickness < 0\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
if( thickness < 0.0 ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
{ }
ostringstream ostr;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n"; if( unit == UNIT_THOU )
ostr << "* violation: thickness < 0\n"; {
ostr << "* line: '" << iline << "'\n"; thickness *= IDF_THOU_TO_MM;
ostr << "* file position: " << pos; }
else if( ( aIdfVersion == IDF_V2 ) && ( unit == UNIT_TNM ) )
{
thickness *= IDF_TNM_TO_MM;
}
else if( unit != UNIT_MM )
{
ostringstream ostr;
ostr << "\n* BUG: invalid UNIT type: " << unit;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
} }
if( thickness < 0.0 )
thickness = 0.0;
if( unit == UNIT_THOU )
{
thickness *= IDF_THOU_TO_MM;
}
else if( ( aIdfVersion == IDF_V2 ) && ( unit == UNIT_TNM ) )
{
thickness *= IDF_TNM_TO_MM;
} }
else if( unit != UNIT_MM ) else
{ {
ostringstream ostr; // for OTLN_PLACE, thickness may be omitted, but is required for OTLN_PLACE_KEEPOUT
ostr << "\n* BUG: invalid UNIT type: " << unit; if( outlineType == OTLN_PLACE_KEEPOUT )
{
ostringstream ostr;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
} ostr << "* violation: missing thickness\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
if( thickness < 0.0 ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
thickness = 0.0; }
thickness = -1.0;
}
} }
else else
{ {
...@@ -2574,12 +2585,20 @@ void PLACE_OUTLINE::writeData( std::ofstream& aBoardFile ) ...@@ -2574,12 +2585,20 @@ void PLACE_OUTLINE::writeData( std::ofstream& aBoardFile )
break; break;
} }
aBoardFile << " "; // thickness is optional for OTLN_PLACE, but mandatory for OTLN_PLACE_KEEPOUT
if( thickness < 0.0 && outlineType == OTLN_PLACE_KEEPOUT)
if( unit != UNIT_THOU ) {
aBoardFile << setiosflags(ios::fixed) << setprecision(5) << thickness << "\n"; aBoardFile << "\n";
}
else else
aBoardFile << setiosflags(ios::fixed) << setprecision(1) << (thickness / IDF_THOU_TO_MM) << "\n"; {
aBoardFile << " ";
if( unit != UNIT_THOU )
aBoardFile << setiosflags(ios::fixed) << setprecision(5) << thickness << "\n";
else
aBoardFile << setiosflags(ios::fixed) << setprecision(1) << (thickness / IDF_THOU_TO_MM) << "\n";
}
// write RECORD 3 // write RECORD 3
writeOutlines( aBoardFile ); writeOutlines( aBoardFile );
......
...@@ -498,7 +498,6 @@ private: ...@@ -498,7 +498,6 @@ private:
protected: protected:
IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM/BOTH ONLY] (IDF spec) IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM/BOTH ONLY] (IDF spec)
double height; // Max Height (IDF spec)
public: public:
PLACE_OUTLINE( IDF3_BOARD* aParent ); PLACE_OUTLINE( IDF3_BOARD* aParent );
......
...@@ -1050,9 +1050,7 @@ bool IDF3_COMPONENT::DelDrill( double aDia, double aXpos, double aYpos ) ...@@ -1050,9 +1050,7 @@ bool IDF3_COMPONENT::DelDrill( double aDia, double aXpos, double aYpos )
{ {
val = true; val = true;
delete *itS; delete *itS;
drills.erase( itS ); itS = drills.erase( itS );
itS = drills.begin();
itE = drills.end();
continue; continue;
} }
++itS; ++itS;
...@@ -1341,6 +1339,7 @@ IDF3_BOARD::IDF3_BOARD( IDF3::CAD_TYPE aCadType ) ...@@ -1341,6 +1339,7 @@ IDF3_BOARD::IDF3_BOARD( IDF3::CAD_TYPE aCadType )
brdFileVersion = 0; brdFileVersion = 0;
libFileVersion = 0; libFileVersion = 0;
iRefDes = 0; iRefDes = 0;
unit = UNIT_MM;
// unlike other outlines which are created as necessary, // unlike other outlines which are created as necessary,
// the board outline always exists and its parent must // the board outline always exists and its parent must
...@@ -2002,14 +2001,13 @@ void IDF3_BOARD::readBrdSection( std::ifstream& aBoardFile, IDF3::FILE_STATE& aB ...@@ -2002,14 +2001,13 @@ void IDF3_BOARD::readBrdSection( std::ifstream& aBoardFile, IDF3::FILE_STATE& aB
if( olnOther.insert( pair<string, OTHER_OUTLINE*>(op->GetOutlineIdentifier(), op) ).second == false ) if( olnOther.insert( pair<string, OTHER_OUTLINE*>(op->GetOutlineIdentifier(), op) ).second == false )
{ {
delete op;
ostringstream ostr; ostringstream ostr;
ostr << "invalid IDF file\n"; ostr << "invalid IDF file\n";
ostr << "* Violation of specification. Non-unique ID in OTHER_OUTLINE '"; ostr << "* Violation of specification. Non-unique ID in OTHER_OUTLINE '";
ostr << op->GetOutlineIdentifier() << "'\n"; ostr << op->GetOutlineIdentifier() << "'\n";
ostr << "* line: '" << iline << "'\n"; ostr << "* line: '" << iline << "'\n";
ostr << "* pos: " << pos; ostr << "* pos: " << pos;
delete op;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
} }
...@@ -2491,6 +2489,7 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib ...@@ -2491,6 +2489,7 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib
ostr << "* Violation of specification: multiple outlines have the same GEOM and PART name\n"; ostr << "* Violation of specification: multiple outlines have the same GEOM and PART name\n";
ostr << "* line: '" << iline << "'\n"; ostr << "* line: '" << iline << "'\n";
ostr << "* pos: " << pos; ostr << "* pos: " << pos;
delete pout;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
} }
...@@ -2504,6 +2503,7 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib ...@@ -2504,6 +2503,7 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib
ostr << "* Expecting .ELECTRICAL or .MECHANICAL, got '" << token << "'\n"; ostr << "* Expecting .ELECTRICAL or .MECHANICAL, got '" << token << "'\n";
ostr << "* line: '" << iline << "'\n"; ostr << "* line: '" << iline << "'\n";
ostr << "* pos: " << pos; ostr << "* pos: " << pos;
delete pout;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
} }
...@@ -3429,10 +3429,6 @@ bool IDF3_BOARD::DelBoardDrill( double aDia, double aXpos, double aYpos ) ...@@ -3429,10 +3429,6 @@ bool IDF3_BOARD::DelBoardDrill( double aDia, double aXpos, double aYpos )
switch( keyo ) switch( keyo )
{ {
case UNOWNED:
ostr << "UNOWNED";
break;
case ECAD: case ECAD:
ostr << "ECAD"; ostr << "ECAD";
break; break;
......
...@@ -178,6 +178,8 @@ VRML_LAYER::VRML_LAYER() ...@@ -178,6 +178,8 @@ VRML_LAYER::VRML_LAYER()
fix = false; fix = false;
Fault = false; Fault = false;
idx = 0; idx = 0;
hidx = 0;
eidx = 0;
ord = 0; ord = 0;
glcmd = 0; glcmd = 0;
pholes = NULL; pholes = NULL;
......
...@@ -100,7 +100,6 @@ private: ...@@ -100,7 +100,6 @@ private:
bool fix; // when true, no more vertices may be added by the user bool fix; // when true, no more vertices may be added by the user
int idx; // vertex index (number of contained vertices) int idx; // vertex index (number of contained vertices)
int ord; // vertex order (number of ordered vertices) int ord; // vertex order (number of ordered vertices)
unsigned int idxout; // outline index to first point in 3D outline
std::vector<VERTEX_3D*> vertices; // vertices of all contours std::vector<VERTEX_3D*> vertices; // vertices of all contours
std::vector<std::list<int>*> contours; // lists of vertices for each contour std::vector<std::list<int>*> contours; // lists of vertices for each contour
std::vector<bool>pth; // indicates whether a 'contour' is a PTH or not std::vector<bool>pth; // indicates whether a 'contour' is a PTH or not
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment