Divide-by-zero safety.

This commit is contained in:
Jeff Young 2021-06-24 11:09:03 +01:00
parent a8028e3bd1
commit 8502fd6877
7 changed files with 14 additions and 7 deletions

View File

@ -404,7 +404,8 @@ void SCH_EAGLE_PLUGIN::checkpoint()
{
if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
{
m_progressReporter->SetCurrentProgress(( (double) m_doneCount ) / m_totalCount );
m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
/ std::max( 1U, m_totalCount ) );
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );

View File

@ -86,7 +86,8 @@ void SCH_SEXPR_PARSER::checkpoint()
if( curLine > m_lastProgressLine + PROGRESS_DELTA )
{
m_progressReporter->SetCurrentProgress( ( (double) curLine ) / m_lineCount );
m_progressReporter->SetCurrentProgress( ( (double) curLine )
/ std::max( 1U, m_lineCount ) );
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );

View File

@ -619,7 +619,8 @@ void SCH_LEGACY_PLUGIN::checkpoint()
if( curLine > m_lastProgressLine + PROGRESS_DELTA )
{
m_progressReporter->SetCurrentProgress( ( (double) curLine ) / m_lineCount );
m_progressReporter->SetCurrentProgress( ( (double) curLine )
/ std::max( 1U, m_lineCount ) );
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );

View File

@ -321,7 +321,8 @@ void EAGLE_PLUGIN::checkpoint()
{
if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
{
m_progressReporter->SetCurrentProgress(( (double) m_doneCount ) / m_totalCount );
m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
/ std::max( 1U, m_totalCount ) );
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );

View File

@ -66,7 +66,8 @@ void FABMASTER::checkpoint()
{
if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
{
m_progressReporter->SetCurrentProgress(( (double) m_doneCount ) / m_totalCount );
m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
/ std::max( 1U, m_totalCount ) );
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );

View File

@ -115,7 +115,8 @@ void PCB_PARSER::checkpoint()
if( curLine > m_lastProgressLine + PROGRESS_DELTA )
{
m_progressReporter->SetCurrentProgress( ( (double) curLine ) / m_lineCount );
m_progressReporter->SetCurrentProgress( ( (double) curLine )
/ std::max( 1U, m_lineCount ) );
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );

View File

@ -206,7 +206,8 @@ void LEGACY_PLUGIN::checkpoint()
if( curLine > m_lastProgressLine + PROGRESS_DELTA )
{
m_progressReporter->SetCurrentProgress( ( (double) curLine ) / m_lineCount );
m_progressReporter->SetCurrentProgress( ( (double) curLine )
/ std::max( 1U, m_lineCount ) );
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );