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.
This commit is contained in:
turboencabulator 2021-11-03 20:47:00 -05:00 committed by GitHub
parent fb04347852
commit 682d49dc13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 24 deletions

View File

@ -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));

View File

@ -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<double> x(GRAPH_SAMPLES), CH1(GRAPH_SAMPLES);
analogConvert(readData375_CH1.get(), &CH1, 2048, 0, 1); //No AC coupling!

View File

@ -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);

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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