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 committed by jean-pierre charras
parent 7b84e0a7d9
commit c79916b359
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 if( isMetric ) // gerber are units in mm
ret = KiROUND( aCoord * GERB_IU_PER_MM ); ret = KiROUND( aCoord * GERB_IU_PER_MM );
else // gerber are units in inches 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; return ret;
} }
@ -78,7 +78,8 @@ VECTOR2I GERBER_FILE_IMAGE::ReadXYCoord( char*& aText, bool aExcellonMode )
// Reserve the anticipated length plus an optional sign and decimal // Reserve the anticipated length plus an optional sign and decimal
line.reserve( std::max( m_FmtLen.x, m_FmtLen.y ) + 3 ); 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; pos = m_CurrentPos;
if( aText == nullptr ) if( aText == nullptr )
@ -142,11 +143,11 @@ VECTOR2I GERBER_FILE_IMAGE::ReadXYCoord( char*& aText, bool aExcellonMode )
if( type_coord == 'X' ) if( type_coord == 'X' )
{ {
pos.x += current_coord; pos.x = current_coord;
} }
else if( type_coord == 'Y' ) else if( type_coord == 'Y' )
{ {
pos.y += current_coord; pos.y = current_coord;
} }
else if( type_coord == 'A' ) else if( type_coord == 'A' )
{ {
@ -155,6 +156,9 @@ VECTOR2I GERBER_FILE_IMAGE::ReadXYCoord( char*& aText, bool aExcellonMode )
} }
} }
if( m_Relative )
pos += m_CurrentPos;
m_CurrentPos = pos; m_CurrentPos = pos;
return pos; return pos;
} }