Fix some Coverity issues.

This commit is contained in:
Jeff Young 2020-04-06 10:15:57 +01:00
parent 1027c2fb8d
commit 322ab60cc5
5 changed files with 51 additions and 60 deletions

View File

@ -176,6 +176,10 @@ void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal )
}
/*
* Flatten project and global templates into a single list. (Project templates take
* precedence.)
*/
void TEMPLATES::resolveTemplates()
{
m_resolved = m_project;
@ -201,7 +205,7 @@ void TEMPLATES::resolveTemplates()
void TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal )
{
// Ensure that the template fieldname does not match a fixed fieldname.
for( int i=0; i<MANDATORY_FIELDS; ++i )
for( int i = 0; i < MANDATORY_FIELDS; ++i )
{
if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
return;
@ -214,17 +218,12 @@ void TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool
{
if( temp.m_Name == aFieldName.m_Name )
{
// DBG( printf( "inserting template fieldname:'%s' at %d\n",
// TO_UTF8( aFieldName.m_Name ), i ); )
temp = aFieldName;
m_resolvedDirty = true;
return;
}
}
// DBG(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );)
// the name is legal and not previously added to the config container, append
// it and return its index within the container.
target.push_back( aFieldName );

View File

@ -138,6 +138,10 @@ private:
bool m_resolvedDirty;
public:
TEMPLATES() :
m_resolvedDirty( true )
{ }
/**
* Function Format
* serializes this object out as text into the given OUTPUTFORMATTER.

View File

@ -640,7 +640,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
else
{
m_rootSheet = aAppendToMe->GetRootSheet();
wxASSERT( m_rootSheet != NULL );
wxASSERT( m_rootSheet );
sheet = aAppendToMe;
loadHierarchy( sheet );
}
@ -1545,7 +1545,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
unit = 1;
// Set the file as modified so the user can be warned.
if( m_rootSheet && m_rootSheet->GetScreen() )
if( m_rootSheet->GetScreen() )
m_rootSheet->GetScreen()->SetModify();
}
@ -1559,7 +1559,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
convert = 1;
// Set the file as modified so the user can be warned.
if( m_rootSheet && m_rootSheet->GetScreen() )
if( m_rootSheet->GetScreen() )
m_rootSheet->GetScreen()->SetModify();
}

View File

@ -66,15 +66,17 @@ namespace KIGFX
{
SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() :
m_ShowUnit( 0 ),
m_ShowConvert( 0 )
{
m_ShowHiddenText = true;
m_ShowHiddenPins = true;
m_ShowPinsElectricalType = true;
m_ShowUmbilicals = true;
m_ShowDisabled = false;
}
m_ShowUnit( 0 ),
m_ShowConvert( 0 ),
m_ShowHiddenText( true ),
m_ShowHiddenPins( true ),
m_ShowPinsElectricalType( true ),
m_ShowDisabled( false ),
m_ShowUmbilicals( true ),
m_DefaultLineWidth( 0 ),
m_DefaultWireThickness( 0 ),
m_DefaultBusThickness( 0 )
{ }
void SCH_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings )

View File

@ -562,22 +562,21 @@ AARC6::AARC6( ALTIUM_PARSER& aReader )
APAD6::APAD6( ALTIUM_PARSER& aReader )
{
ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
if( recordtype != ALTIUM_RECORD::PAD )
{
THROW_IO_ERROR( "Pads6 stream has invalid recordtype" );
}
// Subrecord 1
size_t subrecord1 = aReader.ReadAndSetSubrecordLength();
if( subrecord1 == 0 )
{
THROW_IO_ERROR( "Pads6 stream has no subrecord1 data" );
}
name = aReader.ReadWxString();
if( aReader.GetRemainingSubrecordBytes() != 0 )
{
THROW_IO_ERROR( "Pads6 stream has invalid subrecord1 length" );
}
aReader.SkipSubrecord();
// Subrecord 2
@ -594,14 +593,14 @@ APAD6::APAD6( ALTIUM_PARSER& aReader )
// Subrecord 5
size_t subrecord5 = aReader.ReadAndSetSubrecordLength();
// TODO: exact minimum length we know?
if( subrecord5 < 120 )
{
// TODO: exact minimum length we know?
THROW_IO_ERROR(
"Pads6 stream subrecord has length < 120, which is unexpected" );
}
THROW_IO_ERROR( "Pads6 stream subrecord has length < 120, which is unexpected" );
layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
tolayer = ALTIUM_LAYER::UNKNOWN;
fromlayer = ALTIUM_LAYER::UNKNOWN;
uint8_t flags1 = aReader.Read<uint8_t>();
is_test_fab_top = ( flags1 & 0x80 ) != 0;
@ -639,6 +638,7 @@ APAD6::APAD6( ALTIUM_PARSER& aReader )
soldermaskexpansionmode = static_cast<ALTIUM_PAD_RULE>( aReader.Read<uint8_t>() );
aReader.Skip( 3 );
holerotation = aReader.Read<double>();
if( subrecord5 == 120 )
{
tolayer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
@ -649,6 +649,7 @@ APAD6::APAD6( ALTIUM_PARSER& aReader )
else if( subrecord5 == 171 )
{
}
aReader.SkipSubrecord();
// Subrecord 6
@ -658,19 +659,14 @@ APAD6::APAD6( ALTIUM_PARSER& aReader )
{ // TODO: detect type from something else than the size?
sizeAndShape = std::make_unique<APAD6_SIZE_AND_SHAPE>();
for( int i = 0; i < 29; i++ )
{
sizeAndShape->inner_size[i].x = aReader.ReadKicadUnitX();
}
for( int i = 0; i < 29; i++ )
{
sizeAndShape->inner_size[i].y = aReader.ReadKicadUnitY();
}
for( wxSize& size : sizeAndShape->inner_size )
size.x = aReader.ReadKicadUnitX();
for( int i = 0; i < 29; i++ )
{
sizeAndShape->inner_shape[i] = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
}
for( wxSize& size : sizeAndShape->inner_size )
size.y = aReader.ReadKicadUnitY();
for( ALTIUM_PAD_SHAPE& shape : sizeAndShape->inner_shape )
shape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
aReader.Skip( 1 );
@ -678,35 +674,25 @@ APAD6::APAD6( ALTIUM_PARSER& aReader )
sizeAndShape->slotsize = aReader.ReadKicadUnit();
sizeAndShape->slotrotation = aReader.Read<double>();
for( int i = 0; i < 32; i++ )
{
sizeAndShape->holeoffset[i].x = aReader.ReadKicadUnitX();
}
for( int i = 0; i < 32; i++ )
{
sizeAndShape->holeoffset[i].y = aReader.ReadKicadUnitY();
}
for( wxPoint& pt : sizeAndShape->holeoffset )
pt.x = aReader.ReadKicadUnitX();
for( wxPoint& pt : sizeAndShape->holeoffset )
pt.y = aReader.ReadKicadUnitY();
aReader.Skip( 1 );
for( int i = 0; i < 32; i++ )
{
sizeAndShape->alt_shape[i] =
static_cast<ALTIUM_PAD_SHAPE_ALT>( aReader.Read<uint8_t>() );
}
for( ALTIUM_PAD_SHAPE_ALT& shape : sizeAndShape->alt_shape )
shape = static_cast<ALTIUM_PAD_SHAPE_ALT>( aReader.Read<uint8_t>() );
for( int i = 0; i < 32; i++ )
{
sizeAndShape->cornerradius[i] = aReader.Read<uint8_t>();
}
for( uint8_t& radius : sizeAndShape->cornerradius )
radius = aReader.Read<uint8_t>();
}
aReader.SkipSubrecord();
if( aReader.HasParsingError() )
{
THROW_IO_ERROR( "Pads6 stream was not parsed correctly" );
}
}
AVIA6::AVIA6( ALTIUM_PARSER& aReader )