Fabmaster: catch illegal parses up front
Parsing an empty string as double/int produces uninitialised data. That is likely to cause an undefined amout of chaos later on, so catch it explicitly with a wxCHECK. It's still something that shouldn't happen, and could still cause chaos, but it's at least deterministic. It also avoids putting gigantic numbers into things that don't expect them. For example normalising an angle of 1e303 is functionally an infinite loop. This happens at least in files with missing fields in rows, like in #19174's file, line 4: S!U2306!IC!!!!!!SOT_23_5!!!!!SGM2576/TT9107!!! The file is still broken, but now it loads. Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/19174
This commit is contained in:
@@ -86,6 +86,9 @@ void FABMASTER::checkpoint()
|
||||
|
||||
double FABMASTER::readDouble( const std::string& aStr ) const
|
||||
{
|
||||
// This is bad, but at least don't return uninitialized data
|
||||
wxCHECK_MSG( !aStr.empty(), 0.0, "Empty string passed to readDouble" );
|
||||
|
||||
std::istringstream istr( aStr );
|
||||
istr.imbue( std::locale::classic() );
|
||||
|
||||
@@ -97,6 +100,9 @@ double FABMASTER::readDouble( const std::string& aStr ) const
|
||||
|
||||
int FABMASTER::readInt( const std::string& aStr ) const
|
||||
{
|
||||
// This is bad, but at least don't return uninitialized data
|
||||
wxCHECK_MSG( !aStr.empty(), 0, "Empty string passed to readInt" );
|
||||
|
||||
std::istringstream istr( aStr );
|
||||
istr.imbue( std::locale::classic() );
|
||||
|
||||
@@ -108,7 +114,6 @@ int FABMASTER::readInt( const std::string& aStr ) const
|
||||
|
||||
bool FABMASTER::Read( const std::string& aFile )
|
||||
{
|
||||
|
||||
std::ifstream ifs( aFile, std::ios::in | std::ios::binary );
|
||||
|
||||
if( !ifs.is_open() )
|
||||
|
||||
Reference in New Issue
Block a user