Coverity issue fixes.

Issues #331869, #331875, #332203, #332159, #332171, #332180, and #332648.
This commit is contained in:
Wayne Stambaugh 2021-07-08 08:33:08 -04:00
parent 49e6b80fc5
commit 65c7958293
7 changed files with 83 additions and 53 deletions

View File

@ -178,6 +178,7 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
retval.token = ENDS;
retval.value.dValue = 0;
retval.value.valid = false;
retval.value.text[0] = 0;
if( m_token.token == nullptr )
return retval;

View File

@ -1,22 +1,22 @@
/*
This file is part of libeval, a simple math expression evaluator
Copyright (C) 2017 Michael Geselbracht, mgeselbracht3@gmail.com
Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
* This file is part of libeval, a simple math expression evaluator
*
* Copyright (C) 2017 Michael Geselbracht, mgeselbracht3@gmail.com
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <memory>
#include <set>
@ -419,6 +419,7 @@ bool COMPILER::lexDefault( T_TOKEN& aToken )
wxString msg;
retval.value.str = nullptr;
retval.value.num = 0.0;
retval.token = G_ENDS;
if( m_tokenizer.Done() )
@ -561,7 +562,6 @@ bool COMPILER::lexDefault( T_TOKEN& aToken )
case '.': retval.token = G_STRUCT_REF; break;
case ',': retval.token = G_COMMA; break;
default:
reportError( CST_PARSE, wxString::Format( _( "Unrecognized character '%c'" ),
(char) ch ) );
@ -774,14 +774,14 @@ static std::vector<TREE_NODE*> squashParamList( TREE_NODE* root )
if( n )
{
args.push_back(n);
args.push_back( n );
}
}
std::reverse( args.begin(), args.end() );
for( size_t i = 0; i < args.size(); i++ )
libeval_dbg(10, "squash arg%d: %s\n", int( i ), *args[i]->value.str );
libeval_dbg( 10, "squash arg%d: %s\n", int( i ), *args[i]->value.str );
return args;
}
@ -866,12 +866,14 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
if( !vref )
{
msg.Printf( _( "Unrecognized item '%s'" ), itemName );
reportError( CST_CODEGEN, msg, node->leaf[0]->srcPos - (int) itemName.length() );
reportError( CST_CODEGEN, msg,
node->leaf[0]->srcPos - (int) itemName.length() );
}
else if( vref->GetType() == VT_PARSE_ERROR )
{
msg.Printf( _( "Unrecognized property '%s'" ), propName );
reportError( CST_CODEGEN, msg, node->leaf[1]->srcPos - (int) propName.length() );
reportError( CST_CODEGEN, msg,
node->leaf[1]->srcPos - (int) propName.length() );
}
node->leaf[0]->isVisited = true;
@ -894,7 +896,8 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
if( !vref )
{
msg.Printf( _( "Unrecognized item '%s'" ), itemName );
reportError( CST_CODEGEN, msg, node->leaf[0]->srcPos - (int) itemName.length() );
reportError( CST_CODEGEN, msg,
node->leaf[0]->srcPos - (int) itemName.length() );
}
wxString functionName = *node->leaf[1]->leaf[0]->value.str;
@ -967,7 +970,8 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
if( !vref )
{
msg.Printf( _( "Unrecognized item '%s'" ), itemName );
reportError( CST_CODEGEN, msg, node->leaf[0]->srcPos - (int) itemName.length() );
reportError( CST_CODEGEN, msg,
node->leaf[0]->srcPos - (int) itemName.length() );
}
msg.Printf( _( "Unrecognized property '%s'" ), propName );
@ -980,6 +984,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
node->isTerminal = true;
break;
}
break;
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -586,7 +586,10 @@ bool EESCHEMA_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
ret &= fromLegacy<bool>( aCfg, "RescueNeverShow", "system.never_show_rescue_dialog" );
// Legacy version stored this setting in eeschema, so move it to common if it exists
aCfg->Read( "MoveWarpsCursor", &Pgm().GetCommonSettings()->m_Input.warp_mouse_on_move );
bool tmp;
if( aCfg->Read( "MoveWarpsCursor", &tmp ) )
Pgm().GetCommonSettings()->m_Input.warp_mouse_on_move = tmp;
COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();

View File

@ -32,7 +32,9 @@ const int spiceSettingsSchemaVersion = 0;
SPICE_SIMULATOR_SETTINGS::SPICE_SIMULATOR_SETTINGS( JSON_SETTINGS* aParent,
const std::string& aPath ) :
NESTED_SETTINGS( "simulator", spiceSettingsSchemaVersion, aParent, aPath )
NESTED_SETTINGS( "simulator", spiceSettingsSchemaVersion, aParent, aPath ),
m_fixPassiveVals( false ),
m_fixIncludePaths( true )
{
m_params.emplace_back( new PARAM<wxString>( "workbook_filename", &m_workbookFilename, "" ) );
m_params.emplace_back( new PARAM<bool>( "fix_passive_vals", &m_fixPassiveVals, false ) );

View File

@ -2,6 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2020 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -46,6 +47,8 @@ COMPONENT_DRAGGER::~COMPONENT_DRAGGER()
bool COMPONENT_DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
{
assert( m_world );
m_currentNode = nullptr;
m_initialDraggedItems = aPrimitives;
m_p0 = aP;
@ -148,8 +151,11 @@ bool COMPONENT_DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
return true;
}
bool COMPONENT_DRAGGER::Drag( const VECTOR2I& aP )
{
assert( m_world );
m_world->KillChildren();
m_currentNode = m_world->Branch();
@ -234,6 +240,7 @@ bool COMPONENT_DRAGGER::Drag( const VECTOR2I& aP )
return true;
}
bool COMPONENT_DRAGGER::FixRoute()
{
NODE* node = CurrentNode();
@ -257,11 +264,13 @@ bool COMPONENT_DRAGGER::FixRoute()
return false;
}
NODE* COMPONENT_DRAGGER::CurrentNode() const
{
return m_currentNode ? m_currentNode : m_world;
}
const ITEM_SET COMPONENT_DRAGGER::Traces()
{
return m_draggedItems;

View File

@ -585,11 +585,12 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
{
bool valid_cw = false, valid_ccw = false;
VECTOR2I p_cw, p_ccw;
int dist_ccw, dist_cw;
int dist_ccw = 0, dist_cw = 0;
if( wr.statusCcw == WALKAROUND::ALMOST_DONE )
{
valid_ccw = cursorDistMinimum( l_ccw, aP, hugThresholdLength, dist_ccw, p_ccw );
if( valid_ccw )
{
int idx_ccw = l_ccw.Split( p_ccw );
@ -598,9 +599,11 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
PNS_DBG( Dbg(), AddLine, l_ccw, MAGENTA, 200000, "wh-result-ccw" );
}
}
if( wr.statusCw == WALKAROUND::ALMOST_DONE )
{
valid_cw = cursorDistMinimum( l_cw, aP, hugThresholdLength, dist_cw, p_cw );
if( valid_cw )
{
int idx_cw = l_cw.Split( p_cw );
@ -661,7 +664,6 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
OPTIMIZER::Optimize( &walkFull, effort, m_currentNode );
if( m_currentNode->CheckColliding( &walkFull ) )
{
return false;

View File

@ -54,9 +54,9 @@ NODE::NODE()
{
m_depth = 0;
m_root = this;
m_parent = NULL;
m_parent = nullptr;
m_maxClearance = 800000; // fixme: depends on how thick traces are.
m_ruleResolver = NULL;
m_ruleResolver = nullptr;
m_index = new INDEX;
#ifdef DEBUG
@ -97,6 +97,7 @@ NODE::~NODE()
delete m_index;
}
int NODE::GetClearance( const ITEM* aA, const ITEM* aB ) const
{
if( !m_ruleResolver )
@ -107,12 +108,12 @@ int NODE::GetClearance( const ITEM* aA, const ITEM* aB ) const
int NODE::GetHoleClearance( const ITEM* aA, const ITEM* aB ) const
{
{
if( !m_ruleResolver )
return 0;
return m_ruleResolver->HoleClearance( aA, aB );
}
}
int NODE::GetHoleToHoleClearance( const ITEM* aA, const ITEM* aB ) const
@ -171,8 +172,8 @@ void NODE::unlinkParent()
OBSTACLE_VISITOR::OBSTACLE_VISITOR( const ITEM* aItem ) :
m_item( aItem ),
m_node( NULL ),
m_override( NULL )
m_node( nullptr ),
m_override( nullptr )
{
}
@ -240,6 +241,7 @@ struct NODE::DEFAULT_OBSTACLE_VISITOR : public OBSTACLE_VISITOR
obs.m_item = aCandidate;
obs.m_head = m_item;
obs.m_distFirst = INT_MAX;
m_tab.push_back( obs );
m_matchCount++;
@ -262,7 +264,7 @@ int NODE::QueryColliding( const ITEM* aItem, NODE::OBSTACLES& aObstacles, int aK
#endif
visitor.SetCountLimit( aLimitCount );
visitor.SetWorld( this, NULL );
visitor.SetWorld( this, nullptr );
// first, look for colliding items in the local index
m_index->Query( aItem, m_maxClearance, visitor );
@ -297,11 +299,12 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask,
return OPT_OBSTACLE();
OBSTACLE nearest;
nearest.m_item = NULL;
nearest.m_item = nullptr;
nearest.m_distFirst = INT_MAX;
auto updateNearest =
[&]( const SHAPE_LINE_CHAIN::INTERSECTION& pt, ITEM* obstacle, const SHAPE_LINE_CHAIN& hull, bool isHole )
[&]( const SHAPE_LINE_CHAIN::INTERSECTION& pt, ITEM* obstacle,
const SHAPE_LINE_CHAIN& hull, bool isHole )
{
int dist = aLine->CLine().PathLength( pt.p, pt.index_their );
@ -347,6 +350,7 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask,
{
const VIA& via = aLine->Via();
// Don't use via.Drill(); it doesn't include the plating thickness
int viaHoleRadius = static_cast<const SHAPE_CIRCLE*>( via.Hole() )->GetRadius();
int viaClearance = GetClearance( obstacle.m_item, &via ) + via.Diameter() / 2;
@ -361,7 +365,7 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask,
intersectingPts.clear();
HullIntersection( obstacleHull, aLine->CLine(), intersectingPts );
// obstacleHull.Intersect( aLine->CLine(), intersectingPts, true );
// obstacleHull.Intersect( aLine->CLine(), intersectingPts, true );
for( const SHAPE_LINE_CHAIN::INTERSECTION& ip : intersectingPts )
updateNearest( ip, obstacle.m_item, obstacleHull, false );
@ -474,7 +478,7 @@ struct HIT_VISITOR : public OBSTACLE_VISITOR
const VECTOR2I& m_point;
HIT_VISITOR( ITEM_SET& aTab, const VECTOR2I& aPoint ) :
OBSTACLE_VISITOR( NULL ),
OBSTACLE_VISITOR( nullptr ),
m_items( aTab ),
m_point( aPoint )
{}
@ -504,14 +508,14 @@ const ITEM_SET NODE::HitTest( const VECTOR2I& aPoint ) const
// fixme: we treat a point as an infinitely small circle - this is inefficient.
SHAPE_CIRCLE s( aPoint, 0 );
HIT_VISITOR visitor( items, aPoint );
visitor.SetWorld( this, NULL );
visitor.SetWorld( this, nullptr );
m_index->Query( &s, m_maxClearance, visitor );
if( !isRoot() ) // fixme: could be made cleaner
{
ITEM_SET items_root;
visitor.SetWorld( m_root, NULL );
visitor.SetWorld( m_root, nullptr );
HIT_VISITOR visitor_root( items_root, aPoint );
m_root->m_index->Query( &s, m_maxClearance, visitor_root );
@ -687,7 +691,7 @@ void NODE::doRemove( ITEM* aItem )
// the item belongs to this particular branch: un-reference it
if( aItem->BelongsTo( this ) )
{
aItem->SetOwner( NULL );
aItem->SetOwner( nullptr );
m_root->m_garbageItems.insert( aItem );
}
}
@ -899,7 +903,7 @@ void NODE::followLine( LINKED_ITEM* aCurrent, bool aScanDirection, int& aPos, in
if( count && guard == p )
{
if( aPos >= 0 && aPos < aLimit )
aSegments[aPos] = NULL;
aSegments[aPos] = nullptr;
aGuardHit = true;
break;
@ -948,7 +952,7 @@ const LINE NODE::AssembleLine( LINKED_ITEM* aSeg, int* aOriginSegmentIndex,
int n = 0;
LINKED_ITEM* prev_seg = NULL;
LINKED_ITEM* prev_seg = nullptr;
bool originSet = false;
SHAPE_LINE_CHAIN& line = pl.Line();
@ -1068,9 +1072,13 @@ void NODE::FixupVirtualVias()
for( const auto& lnk : joint.second.LinkList() )
{
if( lnk.item->OfKind( ITEM::VIA_T ) )
{
n_vias++;
}
else if( lnk.item->OfKind( ITEM::SOLID_T ) )
{
n_solid++;
}
else if( const auto t = dyn_cast<PNS::SEGMENT*>( lnk.item ) )
{
int w = t->Width();
@ -1117,7 +1125,7 @@ JOINT* NODE::FindJoint( const VECTOR2I& aPos, int aLayer, int aNet )
}
if( f == end )
return NULL;
return nullptr;
while( f != end )
{
@ -1127,7 +1135,7 @@ JOINT* NODE::FindJoint( const VECTOR2I& aPos, int aLayer, int aNet )
++f;
}
return NULL;
return nullptr;
}
@ -1372,7 +1380,7 @@ void NODE::KillChildren()
}
void NODE::AllItemsInNet( int aNet, std::set<ITEM*>& aItems, int aKindMask)
void NODE::AllItemsInNet( int aNet, std::set<ITEM*>& aItems, int aKindMask )
{
INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( aNet );
@ -1552,7 +1560,7 @@ ITEM *NODE::FindItemByParent( const BOARD_ITEM* aParent )
}
}
return NULL;
return nullptr;
}
}