Fix minor Coverity warnings. Small code cleaning in pcb_parser.cpp

This commit is contained in:
jean-pierre charras 2023-09-20 17:59:39 +02:00
parent b1ed0529d7
commit e152f97f35
4 changed files with 18 additions and 14 deletions

View File

@ -82,6 +82,7 @@ void VC_SETTINGS::Reset()
m_lastKeyboardCursorPositionValid = false; m_lastKeyboardCursorPositionValid = false;
m_lastKeyboardCursorPosition = { 0.0, 0.0 }; m_lastKeyboardCursorPosition = { 0.0, 0.0 };
m_lastKeyboardCursorCommand = ACTIONS::CURSOR_NONE; m_lastKeyboardCursorCommand = ACTIONS::CURSOR_NONE;
m_scrollReversePanH = false;
} }

View File

@ -5,7 +5,7 @@
// Maintainer: Davide Rondini // Maintainer: Davide Rondini
// Contributors: Jose Luis Blanco, Val Greene, Maciej Suminski, Tomasz Wlostowski // Contributors: Jose Luis Blanco, Val Greene, Maciej Suminski, Tomasz Wlostowski
// Created: 21/07/2003 // Created: 21/07/2003
// Last edit: 25/08/2016 // Last edit: 2023
// Copyright: (c) David Schalig, Davide Rondini // Copyright: (c) David Schalig, Davide Rondini
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -959,7 +959,7 @@ void mpScaleXLog::recalculateTicks( wxDC& dc, mpWindow& w )
// Half the number of ticks according to window size. // Half the number of ticks according to window size.
// The value 96 is used to have only 4 ticks when m_scrX is 268. // The value 96 is used to have only 4 ticks when m_scrX is 268.
// For each 96 device context units, is possible to add a new tick. // For each 96 device context units, is possible to add a new tick.
while( visibleDecades - 2 >= m_scrX / 96 ) while( visibleDecades - 2 >= m_scrX / 96.0 )
{ {
step *= 10.0; step *= 10.0;
visibleDecades = log( maxVvis / minVvis ) / log( step ); visibleDecades = log( maxVvis / minVvis ) / log( step );

View File

@ -1117,7 +1117,8 @@ int EE_SELECTION_TOOL::UnselectAll( const TOOL_EVENT& aEvent )
for( SCH_SHEET_PIN* pin : sheet->GetPins() ) for( SCH_SHEET_PIN* pin : sheet->GetPins() )
{ {
EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pin ); EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pin );
if( Selectable( item ) )
if( item && Selectable( item ) )
unselect( item ); unselect( item );
} }
} }

View File

@ -70,6 +70,15 @@
#include <wx/base64.h> #include <wx/base64.h>
#include <wx/mstream.h> #include <wx/mstream.h>
// We currently represent board units as integers. Any values that are
// larger or smaller than those board units represent undefined behavior for
// the system. We limit values to the largest usable
// i.e. std::numeric_limits<int>::max().
// However to avoid issues in comparisons, use a slightly smaller value
// Note also the usable limits are much smaller to avoid overflows in intermediate
// calculations.
constexpr double INT_LIMIT = std::numeric_limits<int>::max() - 10;
using namespace PCB_KEYS_T; using namespace PCB_KEYS_T;
@ -187,10 +196,7 @@ int PCB_PARSER::parseBoardUnits()
// N.B. we currently represent board units as integers. Any values that are // N.B. we currently represent board units as integers. Any values that are
// larger or smaller than those board units represent undefined behavior for // larger or smaller than those board units represent undefined behavior for
// the system. We limit values to the largest that is visible on the screen // the system. We limit values to the largest that is visible on the screen
// This is the diagonal distance of the full screen ~1.5m return KiROUND( Clamp<double>( -INT_LIMIT, retval, INT_LIMIT ) );
constexpr double int_limit =
std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
} }
@ -201,11 +207,7 @@ int PCB_PARSER::parseBoardUnits( const char* aExpected )
// N.B. we currently represent board units as integers. Any values that are // N.B. we currently represent board units as integers. Any values that are
// larger or smaller than those board units represent undefined behavior for // larger or smaller than those board units represent undefined behavior for
// the system. We limit values to the largest that is visible on the screen // the system. We limit values to the largest that is visible on the screen
constexpr double int_limit = std::numeric_limits<int>::max() * 0.7071; return KiROUND( Clamp<double>( -INT_LIMIT, retval, INT_LIMIT ) );
// Use here #KiROUND, not EKIROUND (see comments about them) when having a function as
// argument, because it will be called twice with #KIROUND.
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
} }