Coverity issue fixes.

This commit is contained in:
Wayne Stambaugh 2021-07-06 13:32:34 -04:00
parent 0be91c5b7d
commit 9d348d7e6d
5 changed files with 85 additions and 80 deletions

View File

@ -115,8 +115,6 @@ wxString ENV_VAR::LookUpEnvVarHelp( const wxString& aEnvVar )
template<>
OPT<double> ENV_VAR::GetEnvVar( const wxString& aEnvVarName )
{
OPT<double> optValue = NULLOPT;
wxString env;
if( wxGetEnv( aEnvVarName, &env ) )
@ -124,12 +122,10 @@ OPT<double> ENV_VAR::GetEnvVar( const wxString& aEnvVarName )
double value;
if( env.ToDouble( &value ) )
{
optValue = value;
}
return value;
}
return optValue;
return NULLOPT;
}

View File

@ -1,20 +1,21 @@
/*
This file is part of libeval, a simple math expression evaluator
Copyright (C) 2017 Michael Geselbracht, mgeselbracht3@gmail.com
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) 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 <kicad_string.h>
@ -176,6 +177,7 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
retval.token = ENDS;
retval.value.dValue = 0;
retval.value.valid = false;
if( m_token.token == nullptr )
return retval;
@ -213,8 +215,10 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
// Ensure that the systems decimal separator is used
for( int i = strlen( m_token.token ); i; i-- )
{
if( isDecimalSeparator( m_token.token[ i - 1 ] ) )
m_token.token[ i - 1 ] = m_localeDecimalSeparator;
}
};
// Lamda: Get unit for current token.
@ -250,13 +254,15 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
return Unit::Inch;
}
if( sizeLeft >= 3 && ch == 'm' && cptr[ 1 ] == 'i' && cptr[ 2 ] == 'l' && !isalnum( cptr[ 3 ] ))
if( sizeLeft >= 3 && ch == 'm' && cptr[ 1 ] == 'i' && cptr[ 2 ] == 'l'
&& !isalnum( cptr[ 3 ] ) )
{
m_token.pos += 3;
return Unit::Mil;
}
if( sizeLeft >= 4 && ch == 't' && cptr[ 1 ] == 'h' && cptr[ 2 ] == 'o' && cptr[ 3 ] == 'u' && !isalnum( cptr[ 4 ] ))
if( sizeLeft >= 4 && ch == 't' && cptr[ 1 ] == 'h' && cptr[ 2 ] == 'o'
&& cptr[ 3 ] == 'u' && !isalnum( cptr[ 4 ] ) )
{
m_token.pos += 4;
return Unit::Mil;
@ -300,6 +306,7 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
// The factor is assigned to the terminal UNIT. The actual
// conversion is done within a parser action.
retval.token = UNIT;
if( m_defaultUnits == Unit::MM )
{
switch( convertFrom )
@ -368,9 +375,13 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
case ';': retval.token = SEMCOL; break;
default: m_parseError = true; break; /* invalid character */
}
m_token.pos++;
}
if( !m_parseError )
retval.value.valid = true;
return retval;
}

View File

@ -934,15 +934,18 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
{
SCHEMATIC* schematic = Schematic();
// SCH_SYMOL object has no context outside a schematic.
wxCHECK( schematic, false );
for( int i = 0; i < MANDATORY_FIELDS; ++i )
{
if( token->IsSameAs( m_fields[ i ].GetCanonicalName().Upper() ) )
{
if( i == REFERENCE_FIELD && schematic )
if( i == REFERENCE_FIELD )
*token = GetRef( &schematic->CurrentSheet(), true );
else if( i == VALUE_FIELD && schematic )
else if( i == VALUE_FIELD )
*token = GetValue( &schematic->CurrentSheet(), true );
else if( i == FOOTPRINT_FIELD && schematic )
else if( i == FOOTPRINT_FIELD )
*token = GetFootprint( &schematic->CurrentSheet(), true );
else
*token = m_fields[ i ].GetShownText( aDepth + 1 );
@ -978,10 +981,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
{
wxString footprint;
if( schematic )
footprint = GetFootprint( &schematic->CurrentSheet(), true );
else
footprint = m_fields[ FOOTPRINT_FIELD ].GetShownText();
wxArrayString parts = wxSplit( footprint, ':' );
@ -992,10 +992,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
{
wxString footprint;
if( schematic )
footprint = GetFootprint( &schematic->CurrentSheet(), true );
else
footprint = m_fields[ FOOTPRINT_FIELD ].GetShownText();
wxArrayString parts = wxSplit( footprint, ':' );
@ -1006,10 +1003,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
{
int unit;
if( schematic )
unit = GetUnitSelection( &schematic->CurrentSheet() );
else
unit = GetUnit();
*token = LIB_SYMBOL::SubReference( unit );
return true;

View File

@ -882,11 +882,11 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream
// only write a rotation if it is >= 0.1 deg
if( std::abs( rot[3] ) > 0.0001745 )
{
(*aOutputFile) << " rotation " << std::setprecision( 5 );
(*aOutputFile) << " rotation " << aOutputFile->precision( 5 );
(*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
}
(*aOutputFile) << " translation " << std::setprecision( m_precision );
(*aOutputFile) << " translation " << aOutputFile->precision( m_precision );
(*aOutputFile) << trans.x << " ";
(*aOutputFile) << trans.y << " ";
(*aOutputFile) << trans.z << "\n";
@ -938,7 +938,7 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream
++sM;
}
std::setprecision( old_precision );
aOutputFile->precision( old_precision );
}

View File

@ -236,8 +236,6 @@ static bool InvalidMatchesExpected( BOARD& aBoard, const PCB_MARKER& aMarker,
auto reporter = std::static_pointer_cast<DRC_ITEM>( aMarker.GetRCItem() );
const FOOTPRINT* item_a = dynamic_cast<FOOTPRINT*>( aBoard.GetItem( reporter->GetMainItemID() ) );
BOOST_CHECK( item_a != nullptr );
// This one is more than just a mismatch!
if( reporter->GetAuxItemID() != niluuid )
{
@ -245,6 +243,12 @@ static bool InvalidMatchesExpected( BOARD& aBoard, const PCB_MARKER& aMarker,
return false;
}
if( item_a == nullptr )
{
BOOST_ERROR( "Could not get board DRC item." );
return false;
}
if( item_a->GetReference() != aInvalid.m_refdes )
return false;