Browse Source

PCB_GRID_HELPER::BestSnapAnchor() fix overflow due to use of int.

GRID_HELPER::GetVisibleGrid() needs double, does not work with int (overflow).
Fixes #15389
https://gitlab.com/kicad/code/kicad/-/issues/15389
newinvert
jean-pierre charras 2 years ago
parent
commit
7fe80abdff
  1. 6
      common/tool/grid_helper.cpp
  2. 2
      include/tool/grid_helper.h
  3. 6
      pcbnew/tools/pcb_grid_helper.cpp

6
common/tool/grid_helper.cpp

@ -56,11 +56,9 @@ VECTOR2I GRID_HELPER::GetGrid() const
}
VECTOR2I GRID_HELPER::GetVisibleGrid() const
VECTOR2D GRID_HELPER::GetVisibleGrid() const
{
VECTOR2D size = m_toolMgr->GetView()->GetGAL()->GetVisibleGridSize();
return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
return m_toolMgr->GetView()->GetGAL()->GetVisibleGridSize();
}

2
include/tool/grid_helper.h

@ -40,7 +40,7 @@ public:
virtual ~GRID_HELPER();
VECTOR2I GetGrid() const;
VECTOR2I GetVisibleGrid() const;
VECTOR2D GetVisibleGrid() const;
VECTOR2I GetOrigin() const;
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );

6
pcbnew/tools/pcb_grid_helper.cpp

@ -286,8 +286,10 @@ VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& a
// see https://gitlab.com/kicad/code/kicad/-/issues/5638
// see https://gitlab.com/kicad/code/kicad/-/issues/7125
// see https://gitlab.com/kicad/code/kicad/-/issues/12303
int snapScale = KiROUND( snapSize / m_toolMgr->GetView()->GetGAL()->GetWorldScale() );
int snapRange = m_enableGrid ? std::min( snapScale, GetVisibleGrid().x ) : snapScale;
double snapScale = snapSize / m_toolMgr->GetView()->GetGAL()->GetWorldScale();
// warning: GetVisibleGrid().x sometimes returns a value > INT_MAX. Intermediate calculation
// needs double.
int snapRange = KiROUND( m_enableGrid ? std::min( snapScale, GetVisibleGrid().x ) : snapScale );
int snapDist = snapRange;
//Respect limits of coordinates representation

Loading…
Cancel
Save