Fix relative return with nullptr condition

Previous fix for CVE munged return conditions for gerber files in some
cases.  This restores the proper order where a nullptr will return 0,0
in the relative case and the current coordinate in others

Also fixes incorrect scale factor for inches/mils conversion to mm
This commit is contained in:
Seth Hillbrand 2022-02-09 12:07:18 -08:00
parent d75329b6f1
commit a8c275ae5d
1 changed files with 8 additions and 4 deletions

View File

@ -62,7 +62,7 @@ int scaletoIU( double aCoord, bool isMetric )
if( isMetric ) // gerber are units in mm
ret = KiROUND( aCoord * GERB_IU_PER_MM );
else // gerber are units in inches
ret = KiROUND( aCoord * GERB_IU_PER_MM * 0.0254 );
ret = KiROUND( aCoord * GERB_IU_PER_MM * 25.4 );
return ret;
}
@ -78,7 +78,8 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& aText, bool aExcellonMode )
// Reserve the anticipated length plus an optional sign and decimal
line.reserve( std::max( m_FmtLen.x, m_FmtLen.y ) + 3 );
if( m_Relative )
// Set up return value for case where aText == nullptr
if( !m_Relative )
pos = m_CurrentPos;
if( aText == nullptr )
@ -142,11 +143,11 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& aText, bool aExcellonMode )
if( type_coord == 'X' )
{
pos.x += current_coord;
pos.x = current_coord;
}
else if( type_coord == 'Y' )
{
pos.y += current_coord;
pos.y = current_coord;
}
else if( type_coord == 'A' )
{
@ -155,6 +156,9 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& aText, bool aExcellonMode )
}
}
if( m_Relative )
pos += m_CurrentPos;
m_CurrentPos = pos;
return pos;
}