From 682d49dc1380640a79e525ca5101fc47af55a14f Mon Sep 17 00:00:00 2001 From: turboencabulator Date: Wed, 3 Nov 2021 20:47:00 -0500 Subject: [PATCH] Fix a few compiler warnings (#189) * Fix unused variable warnings * Fix misleading indent warning * Fix potential buffer overflow with fgets() Was reading 256 bytes into a 255-byte array. The function would read at most 255 bytes then try to append a nul (which would overflow), now will read at most 254 bytes before appending the nul. * Move isoCallback() from .h to .cpp file Fixes warnings that the function is unused by every other file that includes unixusbdriver.h. --- Desktop_Interface/isobuffer_file.cpp | 2 +- Desktop_Interface/isodriver.cpp | 4 ++-- Desktop_Interface/ui_elements/espocombobox.cpp | 2 +- Desktop_Interface/ui_elements/esposlider.cpp | 2 +- Desktop_Interface/ui_elements/siprint.cpp | 1 - Desktop_Interface/unixusbdriver.cpp | 18 ++++++++++++++++++ Desktop_Interface/unixusbdriver.h | 18 ------------------ 7 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Desktop_Interface/isobuffer_file.cpp b/Desktop_Interface/isobuffer_file.cpp index 5c73c625..3c5b28f9 100644 --- a/Desktop_Interface/isobuffer_file.cpp +++ b/Desktop_Interface/isobuffer_file.cpp @@ -40,7 +40,7 @@ float *isoBuffer_file::readBuffer(double sampleWindow, int numSamples, bool sing qDebug() << "back" << back; qDebug() << "front" << front; */ - int idx, subIdx; + int idx; if(readData!=NULL) free(readData); readData = (float *) calloc(numSamples, sizeof(float)); diff --git a/Desktop_Interface/isodriver.cpp b/Desktop_Interface/isodriver.cpp index b20bdae5..88265b3b 100644 --- a/Desktop_Interface/isodriver.cpp +++ b/Desktop_Interface/isodriver.cpp @@ -862,8 +862,8 @@ void isoDriver::multimeterAction(){ if(singleShotEnabled && (triggerDelay != 0)) singleShotTriggered(1); - - readData375_CH1 = internalBuffer375_CH1->readBuffer(display.window,GRAPH_SAMPLES, false, display.delay + triggerDelay); + + readData375_CH1 = internalBuffer375_CH1->readBuffer(display.window,GRAPH_SAMPLES, false, display.delay + triggerDelay); QVector x(GRAPH_SAMPLES), CH1(GRAPH_SAMPLES); analogConvert(readData375_CH1.get(), &CH1, 2048, 0, 1); //No AC coupling! diff --git a/Desktop_Interface/ui_elements/espocombobox.cpp b/Desktop_Interface/ui_elements/espocombobox.cpp index 40217ccc..e5cc38a6 100644 --- a/Desktop_Interface/ui_elements/espocombobox.cpp +++ b/Desktop_Interface/ui_elements/espocombobox.cpp @@ -49,7 +49,7 @@ void espoComboBox::readWaveformList(void) qFatal("Could not load _list.wfl"); } - while (fgets(nameBuffer,256,listPtr) !=NULL){ + while (fgets(nameBuffer, sizeof(nameBuffer), listPtr) != NULL){ qDebug() << "nameBuffer = " << nameBuffer; strtok(nameBuffer, "\n\r"); newNames->append(nameBuffer); diff --git a/Desktop_Interface/ui_elements/esposlider.cpp b/Desktop_Interface/ui_elements/esposlider.cpp index b29a83be..62b5f14b 100644 --- a/Desktop_Interface/ui_elements/esposlider.cpp +++ b/Desktop_Interface/ui_elements/esposlider.cpp @@ -70,7 +70,7 @@ void espoSlider::rearrange(){ int k = 7; int c = 5; - int left = this->geometry().left(); + //int left = this->geometry().left(); int right = this->geometry().right(); int top = this->geometry().top(); int bottom = this->geometry().bottom(); diff --git a/Desktop_Interface/ui_elements/siprint.cpp b/Desktop_Interface/ui_elements/siprint.cpp index a2b03b28..b51c9205 100644 --- a/Desktop_Interface/ui_elements/siprint.cpp +++ b/Desktop_Interface/ui_elements/siprint.cpp @@ -8,7 +8,6 @@ siprint::siprint(const char *unitsInit, double valInit) char* siprint::printVal(){ std::string suffix; - double modifiedValue; bool negative = (value < 0); char* tempStringPtr = printString; diff --git a/Desktop_Interface/unixusbdriver.cpp b/Desktop_Interface/unixusbdriver.cpp index 50afe2ee..2f54e574 100644 --- a/Desktop_Interface/unixusbdriver.cpp +++ b/Desktop_Interface/unixusbdriver.cpp @@ -123,6 +123,24 @@ void unixUsbDriver::usbSendControl(uint8_t RequestType, uint8_t Request, uint16_ return; } +//Callback on iso transfer complete. +static void LIBUSB_CALL isoCallback(struct libusb_transfer * transfer){ + tcBlockMutex.lock(); + //int number = ((tcBlock *)transfer->user_data)->number; + //bool completed = ((tcBlock *)transfer->user_data)->completed; + + //qDebug() << "CALLBACK" << number; + //qDebug() << completed; + + if(transfer->status!=LIBUSB_TRANSFER_CANCELLED){ + ((tcBlock *)transfer->user_data)->completed = true; + ((tcBlock *)transfer->user_data)->timeReceived = QDateTime::currentMSecsSinceEpoch(); + } + //qDebug() << ((tcBlock *)transfer->user_data)->timeReceived; + tcBlockMutex.unlock(); + return; +} + int unixUsbDriver::usbIsoInit(void){ int error; diff --git a/Desktop_Interface/unixusbdriver.h b/Desktop_Interface/unixusbdriver.h index 16306db7..c4e9f882 100644 --- a/Desktop_Interface/unixusbdriver.h +++ b/Desktop_Interface/unixusbdriver.h @@ -95,22 +95,4 @@ public slots: void backupCleanup(void); }; -//Callback on iso transfer complete. -static void LIBUSB_CALL isoCallback(struct libusb_transfer * transfer){ - tcBlockMutex.lock(); - //int number = ((tcBlock *)transfer->user_data)->number; - //bool completed = ((tcBlock *)transfer->user_data)->completed; - - //qDebug() << "CALLBACK" << number; - //qDebug() << completed; - - if(transfer->status!=LIBUSB_TRANSFER_CANCELLED){ - ((tcBlock *)transfer->user_data)->completed = true; - ((tcBlock *)transfer->user_data)->timeReceived = QDateTime::currentMSecsSinceEpoch(); - } - //qDebug() << ((tcBlock *)transfer->user_data)->timeReceived; - tcBlockMutex.unlock(); - return; -} - #endif // unixUsbDriver_H