1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 05:11:49 -05:00

AirspyHF: prevent segfault with wrong sample rate index is out of bounds

This commit is contained in:
f4exb 2018-02-18 06:23:49 +01:00
parent ffbc08841e
commit 01bbb65f84

View File

@ -163,9 +163,17 @@ bool AirspyHFInput::start()
return false; return false;
} }
m_airspyHFThread->setSamplerate(m_sampleRates[m_settings.m_devSampleRateIndex]); int sampleRateIndex = m_settings.m_devSampleRateIndex;
m_airspyHFThread->setLog2Decimation(m_settings.m_log2Decim);
if (m_settings.m_devSampleRateIndex >= m_sampleRates.size()) {
sampleRateIndex = m_sampleRates.size() - 1;
}
if (sampleRateIndex >= 0) {
m_airspyHFThread->setSamplerate(m_sampleRates[sampleRateIndex]);
}
m_airspyHFThread->setLog2Decimation(m_settings.m_log2Decim);
m_airspyHFThread->startWork(); m_airspyHFThread->startWork();
mutexLocker.unlock(); mutexLocker.unlock();
@ -239,8 +247,21 @@ const QString& AirspyHFInput::getDeviceDescription() const
int AirspyHFInput::getSampleRate() const int AirspyHFInput::getSampleRate() const
{ {
int rate = m_sampleRates[m_settings.m_devSampleRateIndex]; int sampleRateIndex = m_settings.m_devSampleRateIndex;
if (m_settings.m_devSampleRateIndex >= m_sampleRates.size()) {
sampleRateIndex = m_sampleRates.size() - 1;
}
if (sampleRateIndex >= 0)
{
int rate = m_sampleRates[sampleRateIndex];
return (rate / (1<<m_settings.m_log2Decim)); return (rate / (1<<m_settings.m_log2Decim));
}
else
{
return 0;
}
} }
quint64 AirspyHFInput::getCenterFrequency() const quint64 AirspyHFInput::getCenterFrequency() const
@ -359,7 +380,7 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
sampleRateIndex = m_sampleRates.size() - 1; sampleRateIndex = m_sampleRates.size() - 1;
} }
if (m_dev != 0) if ((m_dev != 0) && (sampleRateIndex >= 0))
{ {
rc = (airspyhf_error) airspyhf_set_samplerate(m_dev, sampleRateIndex); rc = (airspyhf_error) airspyhf_set_samplerate(m_dev, sampleRateIndex);
@ -412,7 +433,7 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency; deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency;
qint64 f_img = deviceCenterFrequency; qint64 f_img = deviceCenterFrequency;
if (m_dev != 0) if ((m_dev != 0) && (sampleRateIndex >= 0))
{ {
quint32 devSampleRate = m_sampleRates[sampleRateIndex]; quint32 devSampleRate = m_sampleRates[sampleRateIndex];
setDeviceCenterFrequency(deviceCenterFrequency, settings); setDeviceCenterFrequency(deviceCenterFrequency, settings);