Fix buffer overrun.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/15187
This commit is contained in:
parent
c0a5be4e9f
commit
2e89c735c0
|
@ -826,19 +826,15 @@ TRACE* SIM_PLOT_TAB::AddTrace( const wxString& aVectorName, int aType )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SIM_PLOT_TAB::SetTraceData( TRACE* trace, unsigned int aPoints, const double* aX,
|
void SIM_PLOT_TAB::SetTraceData( TRACE* trace, std::vector<double>& aX, std::vector<double>& aY )
|
||||||
const double* aY )
|
|
||||||
{
|
{
|
||||||
std::vector<double> x( aX, aX + aPoints );
|
|
||||||
std::vector<double> y( aY, aY + aPoints );
|
|
||||||
|
|
||||||
if( dynamic_cast<LOG_SCALE<mpScaleXLog>*>( m_axis_x ) )
|
if( dynamic_cast<LOG_SCALE<mpScaleXLog>*>( m_axis_x ) )
|
||||||
{
|
{
|
||||||
// log( 0 ) is not valid.
|
// log( 0 ) is not valid.
|
||||||
if( x.size() > 0 && x[0] == 0 )
|
if( aX.size() > 0 && aX[0] == 0 )
|
||||||
{
|
{
|
||||||
x.erase( x.begin() );
|
aX.erase( aX.begin() );
|
||||||
y.erase( y.begin() );
|
aY.erase( aY.begin() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -846,21 +842,21 @@ void SIM_PLOT_TAB::SetTraceData( TRACE* trace, unsigned int aPoints, const doubl
|
||||||
{
|
{
|
||||||
if( trace->GetType() & SPT_AC_PHASE )
|
if( trace->GetType() & SPT_AC_PHASE )
|
||||||
{
|
{
|
||||||
for( unsigned int i = 0; i < aPoints; i++ )
|
for( double& pt : aY )
|
||||||
y[i] = y[i] * 180.0 / M_PI; // convert to degrees
|
pt = pt * 180.0 / M_PI; // convert to degrees
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for( unsigned int i = 0; i < aPoints; i++ )
|
for( double& pt : aY )
|
||||||
{
|
{
|
||||||
// log( 0 ) is not valid.
|
// log( 0 ) is not valid.
|
||||||
if( y[i] != 0 )
|
if( pt != 0 )
|
||||||
y[i] = 20 * log( y[i] ) / log( 10.0 ); // convert to dB
|
pt = 20 * log( pt ) / log( 10.0 ); // convert to dB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trace->SetData( x, y );
|
trace->SetData( aX, aY );
|
||||||
|
|
||||||
if( ( trace->GetType() & SPT_AC_PHASE ) || ( trace->GetType() & SPT_CURRENT ) )
|
if( ( trace->GetType() & SPT_AC_PHASE ) || ( trace->GetType() & SPT_CURRENT ) )
|
||||||
trace->SetScale( m_axis_x, m_axis_y2 );
|
trace->SetScale( m_axis_x, m_axis_y2 );
|
||||||
|
|
|
@ -321,7 +321,7 @@ public:
|
||||||
|
|
||||||
TRACE* AddTrace( const wxString& aVectorName, int aType );
|
TRACE* AddTrace( const wxString& aVectorName, int aType );
|
||||||
|
|
||||||
void SetTraceData( TRACE* aTrace, unsigned int aPoints, const double* aX, const double* aY );
|
void SetTraceData( TRACE* aTrace, std::vector<double>& aX, std::vector<double>& aY );
|
||||||
|
|
||||||
bool DeleteTrace( const wxString& aVectorName, int aTraceType );
|
bool DeleteTrace( const wxString& aVectorName, int aTraceType );
|
||||||
void DeleteTrace( TRACE* aTrace );
|
void DeleteTrace( TRACE* aTrace );
|
||||||
|
|
|
@ -1621,7 +1621,7 @@ void SIMULATOR_PANEL::updateTrace( const wxString& aVectorName, int aTraceType,
|
||||||
std::vector<double> sub_y( data_y.begin() + offset,
|
std::vector<double> sub_y( data_y.begin() + offset,
|
||||||
data_y.begin() + offset + inner );
|
data_y.begin() + offset + inner );
|
||||||
|
|
||||||
aPlotTab->SetTraceData( trace, inner, sub_x.data(), sub_y.data() );
|
aPlotTab->SetTraceData( trace, sub_x, sub_y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1632,7 +1632,7 @@ void SIMULATOR_PANEL::updateTrace( const wxString& aVectorName, int aTraceType,
|
||||||
else if( TRACE* trace = aPlotTab->AddTrace( aVectorName, aTraceType ) )
|
else if( TRACE* trace = aPlotTab->AddTrace( aVectorName, aTraceType ) )
|
||||||
{
|
{
|
||||||
if( data_y.size() >= size )
|
if( data_y.size() >= size )
|
||||||
aPlotTab->SetTraceData( trace, size, data_x.data(), data_y.data() );
|
aPlotTab->SetTraceData( trace, data_x, data_y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue