From f22ef685f5da0149f52b1cde69a10b616a7853b8 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 30 Mar 2016 19:34:36 -0400 Subject: [PATCH] Static analysis related fixes --- src/AppFrame.cpp | 4 +-- src/audio/AudioThread.cpp | 6 ++-- src/audio/AudioThread.h | 1 + src/demod/DemodulatorInstance.cpp | 41 ++++++++++++++++----------- src/demod/DemodulatorWorkerThread.cpp | 2 +- src/sdr/SDRPostThread.cpp | 4 ++- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 829d34b..a09f068 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -1610,7 +1610,7 @@ bool AppFrame::loadSession(std::string fileName) { DataNode *demodTypeNode = demod->hasAnother("type")?demod->getNext("type"):nullptr; - if (demodTypeNode->element()->getDataType() == DATA_INT) { + if (demodTypeNode && demodTypeNode->element()->getDataType() == DATA_INT) { int legacyType = *demodTypeNode; int legacyStereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0; switch (legacyType) { // legacy demod ID @@ -1632,7 +1632,7 @@ bool AppFrame::loadSession(std::string fileName) { case 16: type = "I/Q"; break; default: type = "FM"; break; } - } else if (demodTypeNode->element()->getDataType() == DATA_STRING) { + } else if (demodTypeNode && demodTypeNode->element()->getDataType() == DATA_STRING) { demodTypeNode->element()->get(type); } diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index ec107f1..2a02a03 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -20,11 +20,13 @@ AudioThread::AudioThread() : IOThread(), outputDevice.store(-1); gain.store(1.0); - boundThreads.store(new std::vector); + vBoundThreads = new std::vector; + boundThreads.store(vBoundThreads); } AudioThread::~AudioThread() { - delete boundThreads.load(); + boundThreads.store(nullptr); + delete vBoundThreads; } void AudioThread::bindThread(AudioThread *other) { diff --git a/src/audio/AudioThread.h b/src/audio/AudioThread.h index 7af40b3..5712288 100644 --- a/src/audio/AudioThread.h +++ b/src/audio/AudioThread.h @@ -100,5 +100,6 @@ public: static void deviceCleanup(); static void setDeviceSampleRate(int deviceId, int sampleRate); std::atomic *> boundThreads; + std::vector *vBoundThreads; }; diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 32e8232..0a1595a 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -137,17 +137,23 @@ bool DemodulatorInstance::isTerminated() { switch (cmd.cmd) { case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED: - t_Audio->join(); - audioTerminated = true; - delete t_Audio; + if (t_Audio) { + t_Audio->join(); + audioTerminated = true; + delete t_Audio; + t_Audio = nullptr; + } break; case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED: -#ifdef __APPLE__ - pthread_join(t_Demod, NULL); -#else - t_Demod->join(); - delete t_Demod; -#endif + if (t_Demod) { + #ifdef __APPLE__ + pthread_join(t_Demod, nullptr); + #else + t_Demod->join(); + delete t_Demod; + #endif + t_Demod = nullptr; + } #if ENABLE_DIGITAL_LAB if (activeOutput) { closeOutput(); @@ -156,13 +162,16 @@ bool DemodulatorInstance::isTerminated() { demodTerminated = true; break; case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED: -#ifdef __APPLE__ - pthread_join(t_PreDemod, NULL); -#else - t_PreDemod->join(); - delete t_PreDemod; -#endif - preDemodTerminated = true; + if (t_PreDemod) { + #ifdef __APPLE__ + pthread_join(t_PreDemod, NULL); + #else + t_PreDemod->join(); + delete t_PreDemod; + #endif + preDemodTerminated = true; + t_PreDemod = nullptr; + } break; default: break; diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 492b439..dd43aaf 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -84,7 +84,7 @@ void DemodulatorWorkerThread::run() { float As = 60.0f; // stop-band attenuation [dB] - if (result.sampleRate && result.bandwidth) { + if (cModem && result.sampleRate && result.bandwidth) { result.bandwidth = cModem->checkSampleRate(result.bandwidth, makeDemod?demodCommand.audioSampleRate:filterCommand.audioSampleRate); result.iqResampleRatio = (double) (result.bandwidth) / (double) result.sampleRate; result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As); diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index ef02c87..fe6f62c 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -184,7 +184,9 @@ void SDRPostThread::run() { } } - data_in->decRefCount(); + if (data_in) { + data_in->decRefCount(); + } bool doUpdate = false; for (size_t j = 0; j < nRunDemods; j++) {