Coverity fixes and code cleaning.

(cherry picked from commit 4e99812145)
This commit is contained in:
Wayne Stambaugh 2023-03-04 13:02:05 -05:00
parent d6ff5f0239
commit 9e1fd16329
7 changed files with 55 additions and 21 deletions

View File

@ -2,7 +2,7 @@
* This file is part of libeval, a simple math expression evaluator
*
* Copyright (C) 2017 Michael Geselbracht, mgeselbracht3@gmail.com
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019-2023 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
@ -356,10 +356,11 @@ void COMPILER::newString( const wxString& aString )
m_parseFinished = false;
}
T_TOKEN COMPILER::getToken()
{
T_TOKEN rv;
rv.value.str = nullptr;
rv.value = defaultTokenValue;
bool done = false;

View File

@ -1160,6 +1160,9 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onDifferentialCheckbox( wxCommandEvent
if( isIbisLoaded() )
{
SIM_MODEL_KIBIS* modelkibis = dynamic_cast<SIM_MODEL_KIBIS*>( &curModel() );
wxCHECK( modelkibis, /* void */ );
bool diff = m_differentialCheckbox->GetValue() && modelkibis->CanDifferential();
modelkibis->SwitchSingleEndedDiff( diff );
}

View File

@ -1079,6 +1079,9 @@ bool SIM_MODEL::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
continue;
const SIM_MODEL* baseModel = dynamic_cast<const SIM_MODEL*>( m_baseModel );
wxCHECK( baseModel, false );
std::string baseValue = baseModel->m_params[ii].value;
if( param.value == baseValue )
@ -1734,6 +1737,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
if( spiceTypeInfo.m_Text == wxT( "DC" ) && tokenizer.CountTokens() == 1 )
{
wxCHECK( valueField, /* void */ );
valueField->SetText( tokenizer.GetNextToken() );
modelFromValueField = false;
}

View File

@ -52,6 +52,7 @@
#include "pcbnew_scripting_helpers.h"
PCBNEW_JOBS_HANDLER::PCBNEW_JOBS_HANDLER()
{
Register( "step",
@ -183,10 +184,10 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
{
plotOpts.SetDXFPlotUnits( DXF_UNITS::INCHES );
}
plotOpts.SetPlotFrameRef( aDxfJob->m_plotBorderTitleBlocks );
plotOpts.SetPlotValue( aDxfJob->m_plotFootprintValues );
plotOpts.SetPlotReference( aDxfJob->m_plotRefDes );
plotOpts.SetLayerSelection( aDxfJob->m_printMaskLayer );
DXF_PLOTTER* plotter = (DXF_PLOTTER*) StartPlotBoard(
@ -353,6 +354,7 @@ void PCBNEW_JOBS_HANDLER::populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS&
aPlotOpts.SetPlotReference( aJob->m_plotRefDes );
aPlotOpts.SetSubtractMaskFromSilk( aJob->m_subtractSolderMaskFromSilk );
// Always disable plot pad holes
aPlotOpts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
@ -409,6 +411,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
static DRILL_PRECISION precisionListForInches( 2, 4 );
static DRILL_PRECISION precisionListForMetric( 3, 3 );
int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
{
JOB_EXPORT_PCB_DRILL* aDrillJob = dynamic_cast<JOB_EXPORT_PCB_DRILL*>( aJob );
@ -422,6 +425,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
BOARD* brd = LoadBoard( aDrillJob->m_filename );
std::unique_ptr<GENDRILL_WRITER_BASE> drillWriter;
if( aDrillJob->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::EXCELLON )
{
drillWriter = std::make_unique<EXCELLON_WRITER>( brd );
@ -432,13 +436,14 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
}
VECTOR2I offset;
if( aDrillJob->m_drillOrigin == JOB_EXPORT_PCB_DRILL::DRILL_ORIGIN::ABSOLUTE )
offset = VECTOR2I( 0, 0 );
else
offset = brd->GetDesignSettings().GetAuxOrigin();
PLOT_FORMAT mapFormat = PLOT_FORMAT::PDF;
switch( aDrillJob->m_mapFormat )
{
case JOB_EXPORT_PCB_DRILL::MAP_FORMAT::POSTSCRIPT: mapFormat = PLOT_FORMAT::POST; break;
@ -470,27 +475,36 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
}
DRILL_PRECISION precision;
if( aDrillJob->m_drillUnits == JOB_EXPORT_PCB_DRILL::DRILL_UNITS::INCHES )
precision = precisionListForInches;
else
precision = precisionListForMetric;
EXCELLON_WRITER* excellonWriter = dynamic_cast<EXCELLON_WRITER*>( drillWriter.get() );
if( excellonWriter == nullptr )
return CLI::EXIT_CODES::ERR_UNKNOWN;
excellonWriter->SetFormat( aDrillJob->m_drillUnits
== JOB_EXPORT_PCB_DRILL::DRILL_UNITS::MILLIMETERS,
zeroFmt, precision.m_Lhs, precision.m_Rhs );
excellonWriter->SetOptions( aDrillJob->m_excellonMirrorY, aDrillJob->m_excellonMinimalHeader,
offset, aDrillJob->m_excellonCombinePTHNPTH );
zeroFmt, precision.m_Lhs, precision.m_Rhs );
excellonWriter->SetOptions( aDrillJob->m_excellonMirrorY,
aDrillJob->m_excellonMinimalHeader,
offset, aDrillJob->m_excellonCombinePTHNPTH );
excellonWriter->SetRouteModeForOvalHoles( aDrillJob->m_excellonOvalDrillRoute );
excellonWriter->SetMapFileFormat( mapFormat );
excellonWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
aDrillJob->m_generateMap, nullptr );
aDrillJob->m_generateMap, nullptr );
}
else if( aDrillJob->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::GERBER )
{
GERBER_WRITER* gerberWriter = dynamic_cast<GERBER_WRITER*>( drillWriter.get() );
if( gerberWriter == nullptr )
return CLI::EXIT_CODES::ERR_UNKNOWN;
// Set gerber precision: only 5 or 6 digits for mantissa are allowed
// (SetFormat() accept 5 or 6, and any other value set the precision to 5)
// the integer part precision is always 4, and units always mm
@ -499,7 +513,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
gerberWriter->SetMapFileFormat( mapFormat );
gerberWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
aDrillJob->m_generateMap, nullptr );
aDrillJob->m_generateMap, nullptr );
}
return CLI::EXIT_CODES::OK;
@ -533,7 +547,8 @@ int PCBNEW_JOBS_HANDLER::JobExportPos( JOB* aJob )
aPosJob->m_outputFile = fn.GetFullName();
}
if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::ASCII || aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::CSV )
if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::ASCII
|| aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::CSV )
{
FILE* file = nullptr;
file = wxFopen( aPosJob->m_outputFile, wxS( "wt" ) );
@ -549,12 +564,13 @@ int PCBNEW_JOBS_HANDLER::JobExportPos( JOB* aJob )
bool backSide = aPosJob->m_side == JOB_EXPORT_PCB_POS::SIDE::BACK
|| aPosJob->m_side == JOB_EXPORT_PCB_POS::SIDE::BOTH;
PLACE_FILE_EXPORTER exporter( brd, aPosJob->m_units == JOB_EXPORT_PCB_POS::UNITS::MILLIMETERS,
aPosJob->m_smdOnly, aPosJob->m_excludeFootprintsWithTh,
frontSide, backSide,
aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::CSV,
aPosJob->m_useDrillPlaceFileOrigin,
aPosJob->m_negateBottomX );
PLACE_FILE_EXPORTER exporter( brd,
aPosJob->m_units == JOB_EXPORT_PCB_POS::UNITS::MILLIMETERS,
aPosJob->m_smdOnly, aPosJob->m_excludeFootprintsWithTh,
frontSide, backSide,
aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::CSV,
aPosJob->m_useDrillPlaceFileOrigin,
aPosJob->m_negateBottomX );
data = exporter.GenPositionData();
fputs( data.c_str(), file );
@ -722,6 +738,9 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR
FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aFootprint->Clone() );
if( fp == nullptr )
return CLI::EXIT_CODES::ERR_UNKNOWN;
fp->SetLink( niluuid );
fp->SetFlags( IS_NEW );
fp->SetParent( brd.get() );
@ -760,4 +779,4 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR
return CLI::EXIT_CODES::OK;
}
}

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2016 CERN
* Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 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
@ -232,6 +232,8 @@ bool PNS_PCBNEW_RULE_RESOLVER::IsNetTieExclusion( const PNS::ITEM* aItem,
const VECTOR2I& aCollisionPos,
const PNS::ITEM* aCollidingItem )
{
wxCHECK( aItem && aCollidingItem, false );
std::shared_ptr<DRC_ENGINE> drcEngine = m_board->GetDesignSettings().m_DRCEngine;
BOARD_ITEM* collidingItem = aCollidingItem->Parent();

View File

@ -256,6 +256,7 @@ struct NODE::DEFAULT_OBSTACLE_VISITOR : public OBSTACLE_VISITOR
obs.m_item = aCandidate;
obs.m_head = m_item;
obs.m_distFirst = INT_MAX;
obs.m_maxFanoutWidth = 0;
m_tab.push_back( obs );
m_matchCount++;
@ -323,6 +324,7 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask,
return OPT_OBSTACLE();
OBSTACLE nearest;
nearest.m_head = nullptr;
nearest.m_item = nullptr;
nearest.m_distFirst = INT_MAX;
nearest.m_maxFanoutWidth = 0;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 KiCad Developers, see AUTHORS.TXT for contributors.
* Copyright (C) 2018, 2023 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
@ -74,8 +74,11 @@ BOOST_AUTO_TEST_CASE( TabCheck )
VECTOR2I( 1000, 1000 ), VECTOR2I( 0, 0 ), EDA_ANGLE::m_Angle0, false,
VECTOR2I( 0, 0 ), 0 );
BOOST_CHECK_MESSAGE( output1.x == output2.x, "Incorrect tab size for \n\t'" << text1.ToStdString() << "' and\n\t'" << text2.ToStdString() << "'" );
BOOST_CHECK_MESSAGE( output1.x == output2.x, "Incorrect tab size for \n\t'" <<
text1.ToStdString() << "' and\n\t'" << text2.ToStdString() << "'" );
}
delete font;
}