From 52da7f931b84a9d5645447e31409e97b2c3f9ecb Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 17 Jan 2020 17:53:43 -0800 Subject: [PATCH] pcbnew: Check before reading/writing cache The open/create calls can fail so we need to account for this before using the result that assumes success. (cherry picked from commit 88729de68553427c7f2ca2d32cad46f959b8cc3c) --- pcbnew/footprint_info_impl.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp index 6ec1cf4ed2..bf0dc963a0 100644 --- a/pcbnew/footprint_info_impl.cpp +++ b/pcbnew/footprint_info_impl.cpp @@ -343,12 +343,15 @@ void FOOTPRINT_LIST_IMPL::WriteCacheToFile( wxTextFile* aCacheFile ) { if( aCacheFile->Exists() ) { - aCacheFile->Open(); + if( !aCacheFile->Open() ) + return; + aCacheFile->Clear(); } else { - aCacheFile->Create(); + if( !aCacheFile->Create() ) + return; } aCacheFile->AddLine( wxString::Format( "%lld", m_list_timestamp ) ); @@ -376,10 +379,8 @@ void FOOTPRINT_LIST_IMPL::ReadCacheFromFile( wxTextFile* aCacheFile ) try { - if( aCacheFile->Exists() ) + if( aCacheFile->Exists() && aCacheFile->Open() ) { - aCacheFile->Open(); - aCacheFile->GetFirstLine().ToLongLong( &m_list_timestamp ); while( aCacheFile->GetCurrentLine() + 6 < aCacheFile->GetLineCount() )