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
This commit is contained in:
Cirilo Bernardo 2015-02-16 12:45:37 -05:00 committed by Wayne Stambaugh
parent f2edf02b35
commit 1acfbb0ddd
6 changed files with 85 additions and 70 deletions

View File

@ -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;

View File

@ -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,64 +2425,74 @@ 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;
std::stringstream teststr;
teststr << token;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
ostr << "* violation: no height specified\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
teststr >> thickness;
if( teststr.fail() )
{
ostringstream ostr;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
ostr << "* violation: invalid height\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
if( thickness < 0.0 )
{
ostringstream ostr;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
ostr << "* violation: thickness < 0\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
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 )
{
ostringstream ostr;
ostr << "\n* BUG: invalid UNIT type: " << unit;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
if( thickness < 0.0 )
thickness = 0.0;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
std::stringstream teststr;
teststr << token;
teststr >> thickness;
if( teststr.fail() )
else
{
ostringstream ostr;
// 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: invalid height\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
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() ) );
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
thickness = -1.0;
}
if( thickness < 0.0 )
{
ostringstream ostr;
ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
ostr << "* violation: thickness < 0\n";
ostr << "* line: '" << iline << "'\n";
ostr << "* file position: " << pos;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
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 )
{
ostringstream ostr;
ostr << "\n* BUG: invalid UNIT type: " << unit;
throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
}
if( thickness < 0.0 )
thickness = 0.0;
}
else
{
@ -2574,12 +2585,20 @@ void PLACE_OUTLINE::writeData( std::ofstream& aBoardFile )
break;
}
aBoardFile << " ";
if( unit != UNIT_THOU )
aBoardFile << setiosflags(ios::fixed) << setprecision(5) << thickness << "\n";
// thickness is optional for OTLN_PLACE, but mandatory for OTLN_PLACE_KEEPOUT
if( thickness < 0.0 && outlineType == OTLN_PLACE_KEEPOUT)
{
aBoardFile << "\n";
}
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
writeOutlines( aBoardFile );

View File

@ -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 );

View File

@ -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;

View File

@ -178,6 +178,8 @@ VRML_LAYER::VRML_LAYER()
fix = false;
Fault = false;
idx = 0;
hidx = 0;
eidx = 0;
ord = 0;
glcmd = 0;
pholes = NULL;

View File

@ -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