Run some sanity checks on fp-info-cache files.
Fixes: lp:1803989 * https://bugs.launchpad.net/kicad/+bug/1803989
This commit is contained in:
parent
984d3f04ab
commit
c016861962
|
@ -371,30 +371,31 @@ void FOOTPRINT_LIST_IMPL::WriteCacheToFile( wxTextFile* aCacheFile )
|
||||||
|
|
||||||
void FOOTPRINT_LIST_IMPL::ReadCacheFromFile( wxTextFile* aCacheFile )
|
void FOOTPRINT_LIST_IMPL::ReadCacheFromFile( wxTextFile* aCacheFile )
|
||||||
{
|
{
|
||||||
|
m_list_timestamp = 0;
|
||||||
|
m_list.clear();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_list.clear();
|
|
||||||
|
|
||||||
if( aCacheFile->Exists() )
|
if( aCacheFile->Exists() )
|
||||||
aCacheFile->Open();
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
aCacheFile->GetFirstLine().ToLongLong( &m_list_timestamp );
|
|
||||||
|
|
||||||
while( aCacheFile->GetCurrentLine() + 6 < aCacheFile->GetLineCount() )
|
|
||||||
{
|
{
|
||||||
wxString libNickname = aCacheFile->GetNextLine();
|
aCacheFile->Open();
|
||||||
wxString name = aCacheFile->GetNextLine();
|
|
||||||
wxString description = aCacheFile->GetNextLine();
|
|
||||||
wxString keywords = aCacheFile->GetNextLine();
|
|
||||||
int orderNum = wxAtoi( aCacheFile->GetNextLine() );
|
|
||||||
unsigned int padCount = (unsigned) wxAtoi( aCacheFile->GetNextLine() );
|
|
||||||
unsigned int uniquePadCount = (unsigned) wxAtoi( aCacheFile->GetNextLine() );
|
|
||||||
|
|
||||||
auto* fpinfo = new FOOTPRINT_INFO_IMPL( libNickname, name, description, keywords,
|
aCacheFile->GetFirstLine().ToLongLong( &m_list_timestamp );
|
||||||
orderNum, padCount, uniquePadCount );
|
|
||||||
m_list.emplace_back( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
|
while( aCacheFile->GetCurrentLine() + 6 < aCacheFile->GetLineCount() )
|
||||||
|
{
|
||||||
|
wxString libNickname = aCacheFile->GetNextLine();
|
||||||
|
wxString name = aCacheFile->GetNextLine();
|
||||||
|
wxString description = aCacheFile->GetNextLine();
|
||||||
|
wxString keywords = aCacheFile->GetNextLine();
|
||||||
|
int orderNum = wxAtoi( aCacheFile->GetNextLine() );
|
||||||
|
unsigned int padCount = (unsigned) wxAtoi( aCacheFile->GetNextLine() );
|
||||||
|
unsigned int uniquePadCount = (unsigned) wxAtoi( aCacheFile->GetNextLine() );
|
||||||
|
|
||||||
|
auto* fpinfo = new FOOTPRINT_INFO_IMPL( libNickname, name, description, keywords,
|
||||||
|
orderNum, padCount, uniquePadCount );
|
||||||
|
m_list.emplace_back( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( ... )
|
catch( ... )
|
||||||
|
@ -403,6 +404,10 @@ void FOOTPRINT_LIST_IMPL::ReadCacheFromFile( wxTextFile* aCacheFile )
|
||||||
m_list_timestamp = 0;
|
m_list_timestamp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sanity check: an empty list is very unlikely to be correct.
|
||||||
|
if( m_list.size() == 0 )
|
||||||
|
m_list_timestamp = 0;
|
||||||
|
|
||||||
if( aCacheFile->IsOpened() )
|
if( aCacheFile->IsOpened() )
|
||||||
aCacheFile->Close();
|
aCacheFile->Close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue