From f01b90094b5d543e5f6fbce0f6338913a4f0b1de Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 21 Feb 2018 18:54:59 +0100 Subject: [PATCH] PVS-Studio static analysis corrections (1) issue #137 --- devices/plutosdr/deviceplutosdrbox.cpp | 2 +- httpserver/httpconnectionhandlerpool.cpp | 2 +- httpserver/httpcookie.cpp | 1 + httpserver/httprequest.cpp | 15 +- plugins/channeltx/modatv/atvmod.cpp | 2 +- plugins/channeltx/modatv/atvmodgui.cpp | 8 +- plugins/samplesink/filesink/filesinkthread.h | 2 +- .../filesource/filesourceinput.cpp | 2 +- .../filesource/filesourcethread.h | 2 +- .../testsource/testsourcethread.h | 2 +- sdrbase/dsp/samplesourcefifo.cpp | 4 +- sdrgui/CMakeLists.txt | 2 - sdrgui/dsp/scopevismulti.cpp | 5 +- sdrgui/dsp/scopevisng.cpp | 5 +- sdrgui/gui/glscopemultigui.cpp | 2 +- sdrgui/gui/glscopenggui.cpp | 2 +- sdrgui/gui/scale.cpp | 129 ------------------ sdrgui/gui/scale.h | 37 ----- sdrgui/sdrgui.pro | 2 - 19 files changed, 36 insertions(+), 190 deletions(-) delete mode 100644 sdrgui/gui/scale.cpp delete mode 100644 sdrgui/gui/scale.h diff --git a/devices/plutosdr/deviceplutosdrbox.cpp b/devices/plutosdr/deviceplutosdrbox.cpp index e5690c17e..ee3215189 100644 --- a/devices/plutosdr/deviceplutosdrbox.cpp +++ b/devices/plutosdr/deviceplutosdrbox.cpp @@ -621,7 +621,7 @@ void DevicePlutoSDRBox::setLOPPMTenths(int ppmTenths) char buff[100]; std::vector params; int64_t newXO = m_xoInitial + ((m_xoInitial*ppmTenths) / 10000000L); - snprintf(buff, sizeof(buff), "xo_correction=%ld", newXO); + snprintf(buff, sizeof(buff), "xo_correction=%ld", (long int) newXO); params.push_back(std::string(buff)); set_params(DEVICE_PHY, params); m_LOppmTenths = ppmTenths; diff --git a/httpserver/httpconnectionhandlerpool.cpp b/httpserver/httpconnectionhandlerpool.cpp index 98f67c99b..74c2aded9 100644 --- a/httpserver/httpconnectionhandlerpool.cpp +++ b/httpserver/httpconnectionhandlerpool.cpp @@ -93,9 +93,9 @@ void HttpConnectionHandlerPool::cleanup() { if (++idleCounter > maxIdleHandlers) { - delete handler; pool.removeOne(handler); qDebug("HttpConnectionHandlerPool: Removed connection handler (%p), pool size is now %i",handler,pool.size()); + delete handler; break; // remove only one handler in each interval } } diff --git a/httpserver/httpcookie.cpp b/httpserver/httpcookie.cpp index 0bc85929c..0f8e5cbd1 100644 --- a/httpserver/httpcookie.cpp +++ b/httpserver/httpcookie.cpp @@ -12,6 +12,7 @@ HttpCookie::HttpCookie() version=1; maxAge=0; secure=false; + httpOnly=false; } HttpCookie::HttpCookie(const QByteArray name, const QByteArray value, const int maxAge, const QByteArray path, const QByteArray comment, const QByteArray domain, const bool secure, const bool httpOnly) diff --git a/httpserver/httprequest.cpp b/httpserver/httprequest.cpp index ec623384e..856f4f008 100644 --- a/httpserver/httprequest.cpp +++ b/httpserver/httprequest.cpp @@ -488,13 +488,16 @@ void HttpRequest::parseMultiPartFile() #ifdef SUPERVERBOSE qDebug("HttpRequest::parseMultiPartFile: finishing writing to uploaded file"); #endif - uploadedFile->resize(uploadedFile->size()-2); - uploadedFile->flush(); - uploadedFile->seek(0); parameters.insert(fieldName,fileName); - qDebug("HttpRequest::parseMultiPartFile: set parameter %s=%s",fieldName.data(),fileName.data()); - uploadedFiles.insert(fieldName,uploadedFile); - qDebug("HttpRequest::parseMultiPartFile: uploaded file size is %i",(int) uploadedFile->size()); + if (uploadedFile) + { + uploadedFile->resize(uploadedFile->size()-2); + uploadedFile->flush(); + uploadedFile->seek(0); + qDebug("HttpRequest::parseMultiPartFile: set parameter %s=%s",fieldName.data(),fileName.data()); + uploadedFiles.insert(fieldName,uploadedFile); + qDebug("HttpRequest::parseMultiPartFile: uploaded file size is %i",(int) uploadedFile->size()); + } } if (line.contains(boundary+"--")) { diff --git a/plugins/channeltx/modatv/atvmod.cpp b/plugins/channeltx/modatv/atvmod.cpp index 264ac7b24..01ae25a16 100644 --- a/plugins/channeltx/modatv/atvmod.cpp +++ b/plugins/channeltx/modatv/atvmod.cpp @@ -451,7 +451,7 @@ void ATVMod::pullVideo(Real& sample) if (camera.m_videoFPSCount < camera.m_videoFPSManualEnable ? camera.m_videoFPSManual : camera.m_videoFPS) { camera.m_videoPrevFPSCount = (int) camera.m_videoFPSCount; - camera.m_videoFPSCount += camera.m_videoFPSManualEnable ? camera.m_videoFPSqManual : camera.m_videoFPSq; + camera.m_videoFPSCount += (camera.m_videoFPSManualEnable ? camera.m_videoFPSqManual : camera.m_videoFPSq); } else { diff --git a/plugins/channeltx/modatv/atvmodgui.cpp b/plugins/channeltx/modatv/atvmodgui.cpp index 9627c332c..20962c396 100644 --- a/plugins/channeltx/modatv/atvmodgui.cpp +++ b/plugins/channeltx/modatv/atvmodgui.cpp @@ -129,8 +129,12 @@ bool ATVModGUI::handleMessage(const Message& message) } else if (status == 2) // camera FPS scan is finished { - m_camBusyFPSMessageBox->close(); - if (m_camBusyFPSMessageBox) delete m_camBusyFPSMessageBox; + if (m_camBusyFPSMessageBox) + { + m_camBusyFPSMessageBox->close(); + delete m_camBusyFPSMessageBox; + } + m_camBusyFPSMessageBox = 0; } diff --git a/plugins/samplesink/filesink/filesinkthread.h b/plugins/samplesink/filesink/filesinkthread.h index 3c7b820f7..c86c47936 100644 --- a/plugins/samplesink/filesink/filesinkthread.h +++ b/plugins/samplesink/filesink/filesinkthread.h @@ -55,7 +55,7 @@ public: private: QMutex m_startWaitMutex; QWaitCondition m_startWaiter; - bool m_running; + volatile bool m_running; std::ofstream* m_ofstream; std::size_t m_bufsize; diff --git a/plugins/samplesource/filesource/filesourceinput.cpp b/plugins/samplesource/filesource/filesourceinput.cpp index 7a14df424..59f5f287c 100644 --- a/plugins/samplesource/filesource/filesourceinput.cpp +++ b/plugins/samplesource/filesource/filesourceinput.cpp @@ -112,7 +112,7 @@ void FileSourceInput::seekFileStream(int seekPercentage) { QMutexLocker mutexLocker(&m_mutex); - if ((m_ifstream.is_open()) && !m_fileSourceThread->isRunning()) + if ((m_ifstream.is_open()) && m_fileSourceThread && !m_fileSourceThread->isRunning()) { int seekPoint = ((m_recordLength * seekPercentage) / 100) * m_sampleRate; m_fileSourceThread->setSamplesCount(seekPoint); diff --git a/plugins/samplesource/filesource/filesourcethread.h b/plugins/samplesource/filesource/filesourcethread.h index ff483b84d..ef02de9a1 100644 --- a/plugins/samplesource/filesource/filesourcethread.h +++ b/plugins/samplesource/filesource/filesourcethread.h @@ -52,7 +52,7 @@ public: private: QMutex m_startWaitMutex; QWaitCondition m_startWaiter; - bool m_running; + volatile bool m_running; std::ifstream* m_ifstream; quint8 *m_fileBuf; diff --git a/plugins/samplesource/testsource/testsourcethread.h b/plugins/samplesource/testsource/testsourcethread.h index a91b6c010..dbfd508a2 100644 --- a/plugins/samplesource/testsource/testsourcethread.h +++ b/plugins/samplesource/testsource/testsourcethread.h @@ -61,7 +61,7 @@ public: private: QMutex m_startWaitMutex; QWaitCondition m_startWaiter; - bool m_running; + volatile bool m_running; qint16 *m_buf; quint32 m_bufsize; diff --git a/sdrbase/dsp/samplesourcefifo.cpp b/sdrbase/dsp/samplesourcefifo.cpp index d5b07f2a1..5640d5a95 100644 --- a/sdrbase/dsp/samplesourcefifo.cpp +++ b/sdrbase/dsp/samplesourcefifo.cpp @@ -14,6 +14,7 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include #include #include "samplesourcefifo.h" @@ -40,7 +41,8 @@ void SampleSourceFifo::resize(uint32_t size) void SampleSourceFifo::init() { - memset(&m_data[0], 0, sizeof(2*m_size*sizeof(Sample))); + static Sample zero = {0,0}; + std::fill(m_data.begin(), m_data.end(), zero); m_ir = 0; m_iw = m_size/2; m_init = true; diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 42f9132e0..f8a5874a1 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -36,7 +36,6 @@ set(sdrgui_SOURCES gui/rollupwidget.cpp gui/samplingdevicecontrol.cpp gui/samplingdevicedialog.cpp - gui/scale.cpp gui/scaleengine.cpp gui/tickedslider.cpp gui/transverterbutton.cpp @@ -92,7 +91,6 @@ set(sdrgui_HEADERS gui/rollupwidget.h gui/samplingdevicecontrol.h gui/samplingdevicedialog.h - gui/scale.h gui/scaleengine.h gui/tickedslider.h gui/transverterbutton.h diff --git a/sdrgui/dsp/scopevismulti.cpp b/sdrgui/dsp/scopevismulti.cpp index b7339e5f2..42303f69a 100644 --- a/sdrgui/dsp/scopevismulti.cpp +++ b/sdrgui/dsp/scopevismulti.cpp @@ -542,7 +542,10 @@ bool ScopeVisMulti::handleMessage(const Message& message) if (m_preTriggerDelay != triggerPre) { m_preTriggerDelay = triggerPre; - m_glScope->setTriggerPre(m_preTriggerDelay); + + if (m_glScope) { + m_glScope->setTriggerPre(m_preTriggerDelay); + } } if (freeRun != m_freeRun) diff --git a/sdrgui/dsp/scopevisng.cpp b/sdrgui/dsp/scopevisng.cpp index ffb3add73..b34a7de2a 100644 --- a/sdrgui/dsp/scopevisng.cpp +++ b/sdrgui/dsp/scopevisng.cpp @@ -595,7 +595,10 @@ bool ScopeVisNG::handleMessage(const Message& message) if (m_preTriggerDelay != triggerPre) { m_preTriggerDelay = triggerPre; - m_glScope->setTriggerPre(m_preTriggerDelay); + + if (m_glScope) { + m_glScope->setTriggerPre(m_preTriggerDelay); + } } if (freeRun != m_freeRun) diff --git a/sdrgui/gui/glscopemultigui.cpp b/sdrgui/gui/glscopemultigui.cpp index 56cf93de3..b83cf231c 100644 --- a/sdrgui/gui/glscopemultigui.cpp +++ b/sdrgui/gui/glscopemultigui.cpp @@ -224,7 +224,7 @@ bool GLScopeMultiGUI::deserialize(const QByteArray& data) ui->verticalXY->setEnabled(false); ui->polar->setEnabled(false); - ui->traceMode->setCurrentIndex(intValue); + ui->traceMode->setCurrentIndex(0); d.readS32(1, &intValue, (int) GLScopeMulti::DisplayX); m_glScope->setDisplayMode((GLScopeMulti::DisplayMode) intValue); diff --git a/sdrgui/gui/glscopenggui.cpp b/sdrgui/gui/glscopenggui.cpp index 5bd258e85..894d88ced 100644 --- a/sdrgui/gui/glscopenggui.cpp +++ b/sdrgui/gui/glscopenggui.cpp @@ -220,7 +220,7 @@ bool GLScopeNGGUI::deserialize(const QByteArray& data) ui->verticalXY->setEnabled(false); ui->polar->setEnabled(false); - ui->traceMode->setCurrentIndex(intValue); + ui->traceMode->setCurrentIndex(0); d.readS32(1, &intValue, (int) GLScopeNG::DisplayX); m_glScope->setDisplayMode((GLScopeNG::DisplayMode) intValue); diff --git a/sdrgui/gui/scale.cpp b/sdrgui/gui/scale.cpp deleted file mode 100644 index 5e456bacd..000000000 --- a/sdrgui/gui/scale.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////// -// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany // -// written by Christian Daniel // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation as version 3 of the License, or // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License V3 for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program. If not, see . // -/////////////////////////////////////////////////////////////////////////////////// - -#include -#include "gui/scale.h" - -Scale::Scale(QWidget* parent) : - QWidget(parent) -{ -} - -void Scale::setOrientation(Qt::Orientation orientation) -{ - m_orientation = orientation; - m_scaleEngine.setOrientation(orientation); - m_scaleEngine.setFont(font()); - QFontMetrics fm(font()); - switch(m_orientation) { - case Qt::Horizontal: - m_scaleEngine.setSize(width()); - setMinimumWidth(0); - setMaximumWidth(QWIDGETSIZE_MAX); - setMinimumHeight(3 + fontMetrics().ascent()); - setMaximumHeight(3 + fontMetrics().ascent()); - break; - case Qt::Vertical: - m_scaleEngine.setSize(height()); - setMinimumWidth(30); - setMaximumWidth(30); - setMinimumHeight(0); - setMaximumHeight(QWIDGETSIZE_MAX); - break; - } -} - -void Scale::setRange(Unit::Physical physicalUnit, float rangeMin, float rangeMax) -{ - m_scaleEngine.setRange(physicalUnit, rangeMin, rangeMax); - update(); -} - -void Scale::paintEvent(QPaintEvent*) -{ - QPainter painter(this); - const ScaleEngine::TickList& tickList = m_scaleEngine.getTickList(); - QFontMetricsF fontMetrics(font()); - const ScaleEngine::Tick* tick; - int i; - float bottomLine; - - switch(m_orientation) { - case Qt::Horizontal: { - painter.setPen(Qt::black); - - // Zwischenlinien für x-Achse zeichnen - for(i = 0; i < tickList.count(); i++) { - tick = &tickList[i]; - if(!tick->major) - painter.drawLine(QLineF(tick->pos, 0, tick->pos, 1)); - } - - // Skala am Rand zeichnen - painter.drawLine(QLineF(0, 0, width() - 1, 0)); - - // Hauptlinien und Beschriftung für x-Achse zeichnen - for(i = 0; i < tickList.count(); i++) { - tick = &tickList[i]; - if(tick->major) { - painter.drawLine(QLineF(tick->pos - 1, 0, tick->pos - 1, 3)); - if(tick->textSize > 0) { - painter.drawText(QPointF(tick->textPos, 3 + fontMetrics.ascent()), tick->text); - } - } - } - break; - } - case Qt::Vertical: { - bottomLine = height() - 1; - painter.setPen(Qt::black); - - // Zwischenlinien für y-Achse zeichnen - for(i = 0; i < tickList.count(); i++) { - tick = &tickList[i]; - if(!tick->major) - painter.drawLine(QLineF(width() - 2, bottomLine - tick->pos, width() - 1, bottomLine - tick->pos)); - } - - // Skala am Rand zeichnen - painter.drawLine(QLineF(width() - 1, 0, width() - 1, height() - 1)); - - // Hauptlinien und Beschriftung für y-Achse zeichnen - for(i = 0; i < tickList.count(); i++) { - tick = &tickList[i]; - if(tick->major) { - painter.drawLine(QLineF(width() - 4, bottomLine - tick->pos, width() - 1, bottomLine - tick->pos)); - if(tick->textSize > 0) - painter.drawText(QPointF(width() - 4 - tick->textSize, bottomLine - tick->textPos), tick->text); - } - } - - } - } -} - -void Scale::resizeEvent(QResizeEvent*) -{ - switch(m_orientation) { - case Qt::Horizontal: - m_scaleEngine.setSize(width()); - break; - case Qt::Vertical: - m_scaleEngine.setSize(height()); - break; - } -} diff --git a/sdrgui/gui/scale.h b/sdrgui/gui/scale.h deleted file mode 100644 index 4a5356cfa..000000000 --- a/sdrgui/gui/scale.h +++ /dev/null @@ -1,37 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////// -// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany // -// written by Christian Daniel // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation as version 3 of the License, or // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License V3 for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program. If not, see . // -/////////////////////////////////////////////////////////////////////////////////// - -#include -#include "gui/scaleengine.h" -#include "util/export.h" - -class SDRANGEL_API Scale : public QWidget { - Q_OBJECT - -public: - Scale(QWidget* parent = NULL); - - void setOrientation(Qt::Orientation orientation); - void setRange(Unit::Physical physicalUnit, float rangeMin, float rangeMax); - -private: - Qt::Orientation m_orientation; - ScaleEngine m_scaleEngine; - - void paintEvent(QPaintEvent*); - void resizeEvent(QResizeEvent*); -}; diff --git a/sdrgui/sdrgui.pro b/sdrgui/sdrgui.pro index a9bf2e80f..c7e6e5d5d 100644 --- a/sdrgui/sdrgui.pro +++ b/sdrgui/sdrgui.pro @@ -75,7 +75,6 @@ SOURCES += mainwindow.cpp\ gui/samplingdevicecontrol.cpp\ gui/samplingdevicedialog.cpp\ gui/mypositiondialog.cpp\ - gui/scale.cpp\ gui/scaleengine.cpp\ gui/transverterbutton.cpp\ gui/transverterdialog.cpp\ @@ -126,7 +125,6 @@ HEADERS += mainwindow.h\ gui/samplingdevicecontrol.h\ gui/samplingdevicedialog.h\ gui/mypositiondialog.h\ - gui/scale.h\ gui/scaleengine.h\ gui/tickedslider.h\ gui/transverterbutton.h\