From 8dfdc1086c5a8cc041f01dcdb5c5a6716151462f Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 4 Apr 2018 23:39:31 +0200 Subject: [PATCH] PVS-Studio static analysis corrections (4) --- plugins/channelrx/demodbfm/rdsparser.cpp | 4 +- .../channelrx/demoddatv/datvconstellation.h | 2 +- plugins/channelrx/demoddatv/datvdemod.cpp | 12 --- .../demoddatv/leansdr/convolutional.h | 20 ++--- plugins/channelrx/demoddatv/leansdr/dsp.h | 2 +- plugins/channelrx/demoddatv/leansdr/dvb.h | 8 +- plugins/channelrx/demoddatv/leansdr/sdr.h | 2 +- plugins/channelrx/demoddsd/dsddemod.cpp | 2 +- .../samplesink/sdrdaemonsink/udpsinkfec.cpp | 15 ++-- plugins/samplesink/sdrdaemonsink/udpsinkfec.h | 4 +- .../sdrdaemonsource/sdrdaemonsourcebuffer.h | 4 +- qrtplib/rtpsession.cpp | 83 ++++++++++--------- qrtplib/rtpsession.h | 2 +- qrtplib/rtpudptransmitter.cpp | 3 + sdrbase/resources/webapi/doc/html2/index.html | 2 +- swagger/sdrangel/code/html2/index.html | 2 +- .../sdrangel/code/qt5/client/SWGHelpers.cpp | 23 ++--- 17 files changed, 93 insertions(+), 97 deletions(-) diff --git a/plugins/channelrx/demodbfm/rdsparser.cpp b/plugins/channelrx/demodbfm/rdsparser.cpp index 6909e7e7e..faf267806 100644 --- a/plugins/channelrx/demodbfm/rdsparser.cpp +++ b/plugins/channelrx/demodbfm/rdsparser.cpp @@ -933,15 +933,15 @@ void RDSParser::decode_optional_content(int no_groups, unsigned long int *free_f for (int i = no_groups; i == 0; i--) { - ff_pointer = 12 + 16; + ff_pointer = 12 + 16 - 4; while(ff_pointer > 0) { - ff_pointer -= 4; m_g8_label_index = (free_format[i] & (0xf << ff_pointer)); content_length = optional_content_lengths[m_g8_label_index]; ff_pointer -= content_length; m_g8_content = (free_format[i] & (int(std::pow(2, content_length) - 1) << ff_pointer)); + ff_pointer -= 4; /* qDebug() << "RDSParser::decode_optional_content: TMC optional content (" << label_descriptions[m_g8_label_index].c_str() diff --git a/plugins/channelrx/demoddatv/datvconstellation.h b/plugins/channelrx/demoddatv/datvconstellation.h index 3004a7196..f3d21b32c 100644 --- a/plugins/channelrx/demoddatv/datvconstellation.h +++ b/plugins/channelrx/demoddatv/datvconstellation.h @@ -61,7 +61,7 @@ template struct datvconstellation: runnable while (in.readable() >= pixels_per_frame) { - if (!phase) + if ((!phase) && m_objDATVScreen) { m_objDATVScreen->resetImage(); diff --git a/plugins/channelrx/demoddatv/datvdemod.cpp b/plugins/channelrx/demoddatv/datvdemod.cpp index 1c653bd0f..94a228380 100644 --- a/plugins/channelrx/demoddatv/datvdemod.cpp +++ b/plugins/channelrx/demoddatv/datvdemod.cpp @@ -765,7 +765,6 @@ void DATVDemod::InitDATVFramework() void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused))) { - qint16 * ptrBufferToRelease=NULL; float fltI; float fltQ; leansdr::cf32 objIQ; @@ -859,18 +858,7 @@ void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVect } } - - //********** demodulation ********** - } - - if(ptrBufferToRelease!=NULL) - { - delete ptrBufferToRelease; - } - - - } void DATVDemod::start() diff --git a/plugins/channelrx/demoddatv/leansdr/convolutional.h b/plugins/channelrx/demoddatv/leansdr/convolutional.h index aa751dc06..f103fc420 100644 --- a/plugins/channelrx/demoddatv/leansdr/convolutional.h +++ b/plugins/channelrx/demoddatv/leansdr/convolutional.h @@ -137,10 +137,10 @@ struct deconvol_poly2 ++pin; \ } // Don't shift by more than the operand width - switch (sizeof(Thist) * 8) + switch (sizeof(Thist) /* 8*/) { #if 0 // Not needed yet - avoid compiler warnings - case 64: + case 8: LOOP(63); LOOP(62); LOOP(61); LOOP(60); LOOP(59); LOOP(58); LOOP(57); LOOP(56); LOOP(55); LOOP(54); LOOP(53); LOOP(52); @@ -151,7 +151,7 @@ struct deconvol_poly2 LOOP(35); LOOP(34); LOOP(33); LOOP(32); // Fall-through #endif - case 32: + case 4: LOOP(31) ; LOOP(30) @@ -185,7 +185,7 @@ struct deconvol_poly2 LOOP(16) ; // Fall-through - case 16: + case 2: LOOP(15) ; LOOP(14) @@ -203,7 +203,7 @@ struct deconvol_poly2 LOOP(8) ; // Fall-through - case 8: + case 1: LOOP(7) ; LOOP(6) @@ -227,24 +227,24 @@ struct deconvol_poly2 } #undef LOOP #endif - switch (sizeof(Thist) * 8) + switch (sizeof(Thist) /* 8*/) { #if 0 // Not needed yet - avoid compiler warnings - case 64: + case 8: *pout++ = wd >> 56; *pout++ = wd >> 48; *pout++ = wd >> 40; *pout++ = wd >> 32; // Fall-through #endif - case 32: + case 4: *pout++ = wd >> 24; *pout++ = wd >> 16; // Fall-through - case 16: + case 2: *pout++ = wd >> 8; // Fall-through - case 8: + case 1: *pout++ = wd; break; default: diff --git a/plugins/channelrx/demoddatv/leansdr/dsp.h b/plugins/channelrx/demoddatv/leansdr/dsp.h index f790212b8..03725abc5 100644 --- a/plugins/channelrx/demoddatv/leansdr/dsp.h +++ b/plugins/channelrx/demoddatv/leansdr/dsp.h @@ -334,7 +334,7 @@ private: { for (unsigned int i = 0; i < ncoeffs; ++i) { - float a = 2 * M_PI * f * (i - ncoeffs / 2); + float a = 2 * M_PI * f * (i - (ncoeffs / 2)); float c = cosf(a), s = sinf(a); // TBD Support T=complex shifted_coeffs[i].re = coeffs[i] * c; diff --git a/plugins/channelrx/demoddatv/leansdr/dvb.h b/plugins/channelrx/demoddatv/leansdr/dvb.h index 3a08afe06..da4e44fb8 100644 --- a/plugins/channelrx/demoddatv/leansdr/dvb.h +++ b/plugins/channelrx/demoddatv/leansdr/dvb.h @@ -106,8 +106,8 @@ inline cstln_lut<256> * make_dvbs2_constellation(cstln_lut<256>::predef c, } // EN 300 421, section 4.4.3, table 2 Punctured code, G1=0171, G2=0133 -static const int DVBS_G1 = 0171; -static const int DVBS_G2 = 0133; +static const int DVBS_G1 = 121; +static const int DVBS_G2 = 91; // G1 = 0b1111001 // G2 = 0b1011011 @@ -1286,7 +1286,7 @@ struct randomizer: runnable { // EN 300 421, section 4.4.1 Transport multiplex adaptation pattern[0] = 0xff; // Invert one in eight sync bytes - unsigned short st = 000251; // 0b 000 000 010 101 001 (Fig 2 reversed) + unsigned short st = 169; // 0b 000 000 010 101 001 (Fig 2 reversed) for (int i = 1; i < 188 * 8; ++i) { u8 out = 0; @@ -1338,7 +1338,7 @@ struct derandomizer: runnable { // EN 300 421, section 4.4.1 Transport multiplex adaptation pattern[0] = 0xff; // Restore the inverted sync byte - unsigned short st = 000251; // 0b 000 000 010 101 001 (Fig 2 reversed) + unsigned short st = 169; // 0b 000 000 010 101 001 (Fig 2 reversed) for (int i = 1; i < 188 * 8; ++i) { u8 out = 0; diff --git a/plugins/channelrx/demoddatv/leansdr/sdr.h b/plugins/channelrx/demoddatv/leansdr/sdr.h index 6d4da2b57..6d87eb90e 100644 --- a/plugins/channelrx/demoddatv/leansdr/sdr.h +++ b/plugins/channelrx/demoddatv/leansdr/sdr.h @@ -603,7 +603,7 @@ private: { // Average power in first quadrant with unit grid int q = m / 2; float avgpower = 2 - * (q * 0.25 + (q - 1) * q / 2 + * (q * 0.25 + (q - 1) * (q / 2) + (q - 1) * q * (2 * q - 1) / 6) / q; scale = 1.0 / sqrtf(avgpower); } diff --git a/plugins/channelrx/demoddsd/dsddemod.cpp b/plugins/channelrx/demoddsd/dsddemod.cpp index 518cc4767..1cc5d941c 100644 --- a/plugins/channelrx/demoddsd/dsddemod.cpp +++ b/plugins/channelrx/demoddsd/dsddemod.cpp @@ -392,7 +392,7 @@ void DSDDemod::applyAudioSampleRate(int sampleRate) { qDebug("DSDDemod::applyAudioSampleRate: %d", sampleRate); - if ((sampleRate != 48000) || (sampleRate != 8000)) { + if ((sampleRate != 48000) && (sampleRate != 8000)) { qWarning("DSDDemod::applyAudioSampleRate: audio does not work properly with sample rates other than 48 or 8 kS/s"); } diff --git a/plugins/samplesink/sdrdaemonsink/udpsinkfec.cpp b/plugins/samplesink/sdrdaemonsink/udpsinkfec.cpp index ce7747b2e..7e268e338 100644 --- a/plugins/samplesink/sdrdaemonsink/udpsinkfec.cpp +++ b/plugins/samplesink/sdrdaemonsink/udpsinkfec.cpp @@ -40,6 +40,7 @@ UDPSinkFEC::UDPSinkFEC() : m_frameCount(0), m_sampleIndex(0) { + memset((char *) m_txBlocks, 0, 4*256); m_currentMetaFEC.init(); m_bufMeta = new uint8_t[m_udpSize]; m_buf = new uint8_t[m_udpSize]; @@ -115,11 +116,11 @@ void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunk metaData.m_crc32 = crc32.checksum(); - memset((void *) &m_superBlock, 0, sizeof(m_superBlock)); + memset((char *) &m_superBlock, 0, sizeof(m_superBlock)); m_superBlock.header.frameIndex = m_frameCount; m_superBlock.header.blockIndex = m_txBlockIndex; - memcpy((void *) &m_superBlock.protectedBlock, (const void *) &metaData, sizeof(MetaDataFEC)); + memcpy((char *) &m_superBlock.protectedBlock, (const char *) &metaData, sizeof(MetaDataFEC)); if (!(metaData == m_currentMetaFEC)) { @@ -143,16 +144,16 @@ void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunk if (m_sampleIndex + inRemainingSamples < samplesPerBlock) // there is still room in the current super block { - memcpy((void *) &m_superBlock.protectedBlock.m_samples[m_sampleIndex], - (const void *) &(*it), + memcpy((char *) &m_superBlock.protectedBlock.m_samples[m_sampleIndex], + (const char *) &(*it), inRemainingSamples * sizeof(Sample)); m_sampleIndex += inRemainingSamples; it = end; // all input samples are consumed } else // complete super block and initiate the next if not end of frame { - memcpy((void *) &m_superBlock.protectedBlock.m_samples[m_sampleIndex], - (const void *) &(*it), + memcpy((char *) &m_superBlock.protectedBlock.m_samples[m_sampleIndex], + (const char *) &(*it), (samplesPerBlock - m_sampleIndex) * sizeof(Sample)); it += samplesPerBlock - m_sampleIndex; m_sampleIndex = 0; @@ -283,7 +284,7 @@ void UDPSinkFECWorker::encodeAndTransmit(UDPSinkFEC::SuperBlock *txBlockx, uint1 for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; ++i) { if (i >= cm256Params.OriginalCount) { - memset((void *) &txBlockx[i].protectedBlock, 0, sizeof(UDPSinkFEC::ProtectedBlock)); + memset((char *) &txBlockx[i].protectedBlock, 0, sizeof(UDPSinkFEC::ProtectedBlock)); } txBlockx[i].header.frameIndex = frameIndex; diff --git a/plugins/samplesink/sdrdaemonsink/udpsinkfec.h b/plugins/samplesink/sdrdaemonsink/udpsinkfec.h index 825a4b12a..0b00d6a52 100644 --- a/plugins/samplesink/sdrdaemonsink/udpsinkfec.h +++ b/plugins/samplesink/sdrdaemonsink/udpsinkfec.h @@ -57,12 +57,12 @@ public: bool operator==(const MetaDataFEC& rhs) { - return (memcmp((const void *) this, (const void *) &rhs, 12) == 0); // Only the 12 first bytes are relevant + return (memcmp((const char *) this, (const char *) &rhs, 12) == 0); // Only the 12 first bytes are relevant } void init() { - memset((void *) this, 0, sizeof(MetaDataFEC)); + memset((char *) this, 0, sizeof(MetaDataFEC)); m_nbFECBlocks = -1; } }; diff --git a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourcebuffer.h b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourcebuffer.h index c051061e9..3cfbd2e76 100644 --- a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourcebuffer.h +++ b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourcebuffer.h @@ -46,12 +46,12 @@ public: bool operator==(const MetaDataFEC& rhs) { - return (memcmp((const void *) this, (const void *) &rhs, 12) == 0); // Only the 12 first bytes are relevant + return (memcmp((const char *) this, (const char *) &rhs, 12) == 0); // Only the 12 first bytes are relevant } void init() { - memset((void *) this, 0, sizeof(MetaDataFEC)); + memset((char *) this, 0, sizeof(MetaDataFEC)); } }; diff --git a/qrtplib/rtpsession.cpp b/qrtplib/rtpsession.cpp index 94dedda1d..643858cb8 100644 --- a/qrtplib/rtpsession.cpp +++ b/qrtplib/rtpsession.cpp @@ -84,28 +84,28 @@ RTPSession::~RTPSession() delete rtprnd; } -int RTPSession::Create(const RTPSessionParams &sessparams, const RTPTransmissionParams *transparams /* = 0 */, RTPTransmitter::TransmissionProtocol protocol) -{ - int status; - - if (created) - return ERR_RTP_SESSION_ALREADYCREATED; - - usingpollthread = sessparams.IsUsingPollThread(); - - useSR_BYEifpossible = sessparams.GetSenderReportForBYE(); - sentpackets = false; - - // Check max packet size - - if ((maxpacksize = sessparams.GetMaximumPacketSize()) < RTP_MINPACKETSIZE) - return ERR_RTP_SESSION_MAXPACKETSIZETOOSMALL; - - // Initialize the transmission component - - rtptrans = 0; - switch (protocol) - { +//int RTPSession::Create(const RTPSessionParams &sessparams, const RTPTransmissionParams *transparams /* = 0 */, RTPTransmitter::TransmissionProtocol protocol) +//{ +// int status; +// +// if (created) +// return ERR_RTP_SESSION_ALREADYCREATED; +// +// usingpollthread = sessparams.IsUsingPollThread(); +// +// useSR_BYEifpossible = sessparams.GetSenderReportForBYE(); +// sentpackets = false; +// +// // Check max packet size +// +// if ((maxpacksize = sessparams.GetMaximumPacketSize()) < RTP_MINPACKETSIZE) +// return ERR_RTP_SESSION_MAXPACKETSIZETOOSMALL; +// +// // Initialize the transmission component +// +// rtptrans = 0; +// switch (protocol) +// { // TODO: see if we keep this Create method or use the one with the transmitter specified // case RTPTransmitter::IPv4UDPProto: // rtptrans = new RTPUDPv4Transmitter(); @@ -121,26 +121,27 @@ int RTPSession::Create(const RTPSessionParams &sessparams, const RTPTransmission // case RTPTransmitter::TCPProto: // rtptrans = new RTPTCPTransmitter(); // break; - default: - return ERR_RTP_SESSION_UNSUPPORTEDTRANSMISSIONPROTOCOL; - } - if (rtptrans == 0) - return ERR_RTP_OUTOFMEM; - if ((status = rtptrans->Init()) < 0) - { - delete rtptrans; - return status; - } - if ((status = rtptrans->Create(maxpacksize, transparams)) < 0) - { - delete rtptrans; - return status; - } - - deletetransmitter = true; - return InternalCreate(sessparams); -} +// default: +// return ERR_RTP_SESSION_UNSUPPORTEDTRANSMISSIONPROTOCOL; +// } +// +// if (rtptrans == 0) +// return ERR_RTP_OUTOFMEM; +// if ((status = rtptrans->Init()) < 0) +// { +// delete rtptrans; +// return status; +// } +// if ((status = rtptrans->Create(maxpacksize, transparams)) < 0) +// { +// delete rtptrans; +// return status; +// } +// +// deletetransmitter = true; +// return InternalCreate(sessparams); +//} int RTPSession::Create(const RTPSessionParams &sessparams, RTPTransmitter *transmitter) { diff --git a/qrtplib/rtpsession.h b/qrtplib/rtpsession.h index d2393ddc9..179609e8f 100644 --- a/qrtplib/rtpsession.h +++ b/qrtplib/rtpsession.h @@ -94,7 +94,7 @@ public: * proto is of type RTPTransmitter::UserDefinedProto, the NewUserDefinedTransmitter function must * be implemented. */ - int Create(const RTPSessionParams &sessparams, const RTPTransmissionParams *transparams = 0, RTPTransmitter::TransmissionProtocol proto = RTPTransmitter::IPv4UDPProto); + //int Create(const RTPSessionParams &sessparams, const RTPTransmissionParams *transparams = 0, RTPTransmitter::TransmissionProtocol proto = RTPTransmitter::IPv4UDPProto); /** Creates an RTP session using \c transmitter as transmission component. * This function creates an RTP session with parameters \c sessparams, which will use the diff --git a/qrtplib/rtpudptransmitter.cpp b/qrtplib/rtpudptransmitter.cpp index 957f62ec2..bcca9c584 100644 --- a/qrtplib/rtpudptransmitter.cpp +++ b/qrtplib/rtpudptransmitter.cpp @@ -53,6 +53,9 @@ RTPUDPTransmitter::RTPUDPTransmitter() : m_rtcpPort = 0; m_rtpPort = 0; m_receivemode = RTPTransmitter::AcceptAll; + m_maxpacksize = 0; + memset(m_rtpBuffer, 0, m_absoluteMaxPackSize); + memset(m_rtcpBuffer, 0, m_absoluteMaxPackSize); } RTPUDPTransmitter::~RTPUDPTransmitter() diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html index 48b129fcf..7c9914972 100644 --- a/sdrbase/resources/webapi/doc/html2/index.html +++ b/sdrbase/resources/webapi/doc/html2/index.html @@ -20190,7 +20190,7 @@ except ApiException as e:
- Generated 2018-03-31T18:20:57.874+02:00 + Generated 2018-04-04T22:16:33.651+02:00
diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 48b129fcf..7c9914972 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -20190,7 +20190,7 @@ except ApiException as e:
- Generated 2018-03-31T18:20:57.874+02:00 + Generated 2018-04-04T22:16:33.651+02:00
diff --git a/swagger/sdrangel/code/qt5/client/SWGHelpers.cpp b/swagger/sdrangel/code/qt5/client/SWGHelpers.cpp index 1c2d92e2f..e6f00e591 100644 --- a/swagger/sdrangel/code/qt5/client/SWGHelpers.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGHelpers.cpp @@ -388,16 +388,19 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { SWGObject *SWGobject = reinterpret_cast(value); if(SWGobject != nullptr) { QJsonObject* o = (*SWGobject).asJsonObject(); - if(name != nullptr) { - output->insert(name, *o); - if(o != nullptr) delete o; - } - else { - output->empty(); - for(QString key : o->keys()) { - output->insert(key, o->value(key)); - } - } + if (o != nullptr) + { + if(name != nullptr) { + output->insert(name, *o); + if(o != nullptr) delete o; + } + else { + output->empty(); + for(QString key : o->keys()) { + output->insert(key, o->value(key)); + } + } + } } } else if(QStringLiteral("QString").compare(type) == 0) {