From f9c7eae63a9142852d4788a3a3625eb3d0d79802 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Tue, 16 Feb 2021 18:37:57 -0500 Subject: [PATCH] Avoid null access in NGSPICE::AllPlots --- eeschema/sim/ngspice.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index e7b1053aa5..3578ee00b9 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -78,17 +78,21 @@ vector NGSPICE::AllPlots() const char** allPlots = m_ngSpice_AllVecs( currentPlot ); int noOfPlots = 0; + vector retVal; if( allPlots != nullptr ) + { for( char** plot = allPlots; *plot != nullptr; plot++ ) noOfPlots++; - vector retVal( noOfPlots ); - for( int i = 0; i < noOfPlots; i++, allPlots++ ) - { - string vec = *allPlots; - retVal.at( i ) = vec; + retVal.reserve( noOfPlots ); + for( int i = 0; i < noOfPlots; i++, allPlots++ ) + { + string vec = *allPlots; + retVal.at( i ) = vec; + } } + return retVal; }