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,
PrintSeg( *bl );
#endif
aOutline.push( *bl );
aLines.erase( bl );
bl = aLines.erase( bl );
}
continue;
......@@ -982,7 +982,7 @@ void IDF3::GetOutline( std::list<IDF_SEGMENT*>& aLines,
printSeg( *bl );
#endif
aOutline.push( *bl );
aLines.erase( bl );
bl = aLines.erase( bl );
}
continue;
......
......@@ -377,7 +377,7 @@ void BOARD_OUTLINE::readOutlines( std::ifstream& aBoardFile, IDF3::IDF_VERSION a
}
// verify winding of previous outline
if( ( loopidx = 0 && !op->IsCCW() )
if( ( loopidx == 0 && !op->IsCCW() )
|| ( loopidx > 0 && op->IsCCW() ) )
{
ostringstream ostr;
......@@ -2232,10 +2232,11 @@ PLACE_OUTLINE::PLACE_OUTLINE( IDF3_BOARD* aParent )
setParent( aParent );
outlineType = OTLN_PLACE;
single = true;
thickness = 0.0;
thickness = -1.0;
side = LYR_INVALID;
}
bool PLACE_OUTLINE::SetSide( IDF3::IDF_LAYER aSide )
{
#ifndef DISABLE_IDF_OWNERSHIP
......@@ -2424,22 +2425,13 @@ void PLACE_OUTLINE::readData( std::ifstream& aBoardFile, const std::string& aHea
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
if( !GetIDFString( iline, token, quoted, idx ) )
if( GetIDFString( iline, token, quoted, idx ) )
{
ostringstream ostr;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
ostr << "* violation: no height specified\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
std::stringstream teststr;
teststr << token;
teststr >> thickness;
if( teststr.fail() )
{
ostringstream ostr;
......@@ -2482,6 +2474,25 @@ void PLACE_OUTLINE::readData( std::ifstream& aBoardFile, const std::string& aHea
if( thickness < 0.0 )
thickness = 0.0;
}
else
{
// for OTLN_PLACE, thickness may be omitted, but is required for OTLN_PLACE_KEEPOUT
if( outlineType == OTLN_PLACE_KEEPOUT )
{
ostringstream ostr;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
ostr << "* violation: missing thickness\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
thickness = -1.0;
}
}
else
{
......@@ -2574,12 +2585,20 @@ void PLACE_OUTLINE::writeData( std::ofstream& aBoardFile )
break;
}
// thickness is optional for OTLN_PLACE, but mandatory for OTLN_PLACE_KEEPOUT
if( thickness < 0.0 && outlineType == OTLN_PLACE_KEEPOUT)
{
aBoardFile << "\n";
}
else
{
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
writeOutlines( aBoardFile );
......
......@@ -498,7 +498,6 @@ private:
protected:
IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM/BOTH ONLY] (IDF spec)
double height; // Max Height (IDF spec)
public:
PLACE_OUTLINE( IDF3_BOARD* aParent );
......
......@@ -1050,9 +1050,7 @@ bool IDF3_COMPONENT::DelDrill( double aDia, double aXpos, double aYpos )
{
val = true;
delete *itS;
drills.erase( itS );
itS = drills.begin();
itE = drills.end();
itS = drills.erase( itS );
continue;
}
++itS;
......@@ -1341,6 +1339,7 @@ IDF3_BOARD::IDF3_BOARD( IDF3::CAD_TYPE aCadType )
brdFileVersion = 0;
libFileVersion = 0;
iRefDes = 0;
unit = UNIT_MM;
// unlike other outlines which are created as necessary,
// the board outline always exists and its parent must
......@@ -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 )
{
delete op;
ostringstream ostr;
ostr << "invalid IDF file\n";
ostr << "* Violation of specification. Non-unique ID in OTHER_OUTLINE '";
ostr << op->GetOutlineIdentifier() << "'\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* pos: " << pos;
delete op;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
......@@ -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 << "* line: '" << iline << "'\n";
ostr << "* pos: " << pos;
delete pout;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
......@@ -2504,6 +2503,7 @@ void IDF3_BOARD::readLibSection( std::ifstream& aLibFile, IDF3::FILE_STATE& aLib
ostr << "* Expecting .ELECTRICAL or .MECHANICAL, got '" << token << "'\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* pos: " << pos;
delete pout;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
......@@ -3429,10 +3429,6 @@ bool IDF3_BOARD::DelBoardDrill( double aDia, double aXpos, double aYpos )
switch( keyo )
{
case UNOWNED:
ostr << "UNOWNED";
break;
case ECAD:
ostr << "ECAD";
break;
......
......@@ -178,6 +178,8 @@ VRML_LAYER::VRML_LAYER()
fix = false;
Fault = false;
idx = 0;
hidx = 0;
eidx = 0;
ord = 0;
glcmd = 0;
pholes = NULL;
......
......@@ -100,7 +100,6 @@ private:
bool fix; // when true, no more vertices may be added by the user
int idx; // vertex index (number of contained 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<std::list<int>*> contours; // lists of vertices for each contour
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