Avoid null access in NGSPICE::AllPlots

This commit is contained in:
Marek Roszko 2021-02-16 18:37:57 -05:00
parent 2370ca1b0e
commit f9c7eae63a
1 changed files with 9 additions and 5 deletions

View File

@ -78,17 +78,21 @@ vector<string> NGSPICE::AllPlots() const
char** allPlots = m_ngSpice_AllVecs( currentPlot ); char** allPlots = m_ngSpice_AllVecs( currentPlot );
int noOfPlots = 0; int noOfPlots = 0;
vector<string> retVal;
if( allPlots != nullptr ) if( allPlots != nullptr )
{
for( char** plot = allPlots; *plot != nullptr; plot++ ) for( char** plot = allPlots; *plot != nullptr; plot++ )
noOfPlots++; noOfPlots++;
vector<string> retVal( noOfPlots ); retVal.reserve( noOfPlots );
for( int i = 0; i < noOfPlots; i++, allPlots++ ) for( int i = 0; i < noOfPlots; i++, allPlots++ )
{ {
string vec = *allPlots; string vec = *allPlots;
retVal.at( i ) = vec; retVal.at( i ) = vec;
}
} }
return retVal; return retVal;
} }