From 0b1e5e80a01f1ed3dfa7e948ec2ae44dd20a8d25 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Wed, 26 Apr 2023 13:42:15 -0500 Subject: [PATCH 1/7] Add project folder for QT Creator 9.x to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fc8c56a29..b6a2ceee8 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ O.*/ *.swp *_BAK.adl /QtC-* +/.qtc_* cdCommands envPaths dllPath.bat From ddfcff5afa33dad077b2d451c099fc2ae7410d29 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Thu, 27 Apr 2023 13:41:56 -0500 Subject: [PATCH 2/7] Initialize local variable - found by cppcheck/sonarqube --- asyn/miscellaneous/asynShellCommands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyn/miscellaneous/asynShellCommands.c b/asyn/miscellaneous/asynShellCommands.c index 2b6f6662f..83a8f41c4 100644 --- a/asyn/miscellaneous/asynShellCommands.c +++ b/asyn/miscellaneous/asynShellCommands.c @@ -264,7 +264,7 @@ getEos(asynUser *pasynUser) default: getFunc = NULL; break; } if (getFunc) { - int l; + int l = 0; peosargs->status = (*getFunc)(peosargs->drvPvt, pasynUser, peosargs->eos, sizeof peosargs->eos, &l); peosargs->eosLen = l; } From b069be1efe0dc0f7b140af97e0712d50ba92df96 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Thu, 27 Apr 2023 14:01:38 -0500 Subject: [PATCH 3/7] Avoid syntax error in skeleton driver - found by cppcheck/sonar --- asyn/asynGpib/drvSkeleton.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyn/asynGpib/drvSkeleton.c b/asyn/asynGpib/drvSkeleton.c index b7b393dc8..fa4388d19 100644 --- a/asyn/asynGpib/drvSkeleton.c +++ b/asyn/asynGpib/drvSkeleton.c @@ -136,7 +136,7 @@ static asynGpib skeletonDriver = { serialPollEnd }; -int skeletonDriverConfig(const char *name, /*Start of device dependent args*/) +int skeletonDriverConfig(const char *name /*, ... Start of device dependent args*/) { skeletonPvt *pskeletonPvt; char *portName; From 1ffb9759bed775cf0ec4df8af4b92fed5f796838 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Fri, 28 Apr 2023 11:12:08 -0500 Subject: [PATCH 4/7] Initialize all class members - found by cppcheck/sonar --- asyn/asynPortClient/asynPortClient.cpp | 2 +- asyn/drvAsynFTDI/ftdiDriver.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/asyn/asynPortClient/asynPortClient.cpp b/asyn/asynPortClient/asynPortClient.cpp index cc3b9329f..b2bc0f896 100644 --- a/asyn/asynPortClient/asynPortClient.cpp +++ b/asyn/asynPortClient/asynPortClient.cpp @@ -29,7 +29,7 @@ asynParamClient::asynParamClient(const char *portName, int addr, const char *asynInterfaceType, const char *drvInfo, double timeout) : pasynUser_(NULL), pasynUserSyncIO_(NULL), timeout_(timeout), portName_(epicsStrDup(portName)), - addr_(addr), asynInterfaceType_(epicsStrDup(asynInterfaceType)), drvInfo_(NULL) + addr_(addr), asynInterfaceType_(epicsStrDup(asynInterfaceType)), drvInfo_(NULL), drvPvt(NULL) ,interruptPvt_(NULL) { asynStatus status; diff --git a/asyn/drvAsynFTDI/ftdiDriver.cpp b/asyn/drvAsynFTDI/ftdiDriver.cpp index b2d27d0dc..c7d0b13b0 100644 --- a/asyn/drvAsynFTDI/ftdiDriver.cpp +++ b/asyn/drvAsynFTDI/ftdiDriver.cpp @@ -45,7 +45,14 @@ void debugPrint(...){} * @param vendor - Vendor ID * @param product - Product ID */ -FTDIDriver::FTDIDriver(int mode):spi(mode) +FTDIDriver::FTDIDriver(int mode) + : ftdi_(nullptr) + , spi(mode) + , spiInit(0) + , buf({0}) + , pbuf(nullptr) + , pinState(0) + , pinDirection(0) { static const char *functionName = "FTDIDriver::FTDIDriver"; debugPrint("%s : Method called - ", functionName); @@ -66,8 +73,6 @@ FTDIDriver::FTDIDriver(int mode):spi(mode) parity_ = NONE; break_ = BREAK_OFF; flowctrl_ = SIO_DISABLE_FLOW_CTRL; - spiInit = 0; // Status whether init done - memset(buf, 0, sizeof(buf)); } FTDIDriverStatus FTDIDriver::initSPI() { From 07432f14e6f444c936fa1c58fc384e58f04f8389 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Thu, 27 Apr 2023 14:18:33 -0500 Subject: [PATCH 5/7] Don't check unsigned variables for value < 0 - found by cppcheck/sonar --- asyn/asynDriver/asynManager.c | 2 +- asyn/devEpics/devAsynOctet.c | 4 ++-- asyn/devGpib/devGpibConvertExample.c | 2 +- asyn/drvAsynFTDI/drvAsynFTDIPort.cpp | 5 +---- asyn/drvAsynSerial/drvAsynIPPort.c | 2 +- asyn/drvAsynSerial/drvAsynIPServerPort.c | 4 ++-- asyn/drvAsynSerial/drvAsynSerialPort.c | 2 +- asyn/drvAsynSerial/drvAsynSerialPortWin32.c | 2 +- 8 files changed, 10 insertions(+), 13 deletions(-) diff --git a/asyn/asynDriver/asynManager.c b/asyn/asynDriver/asynManager.c index e063a4fc2..2061131ed 100644 --- a/asyn/asynDriver/asynManager.c +++ b/asyn/asynDriver/asynManager.c @@ -3000,7 +3000,7 @@ static int traceVprintIOSource(asynUser *pasynUser,int reason, } } /* If the traceIOMask is 0 or traceTruncateSize <=0 we need to output a newline */ - if((traceIOMask == 0) || (traceTruncateSize <=0)) { + if((traceIOMask == 0) || (traceTruncateSize ==0)) { if(fp) { nout += fprintf(fp,"\n"); } else { diff --git a/asyn/devEpics/devAsynOctet.c b/asyn/devEpics/devAsynOctet.c index d25fb81cb..240e5b89f 100644 --- a/asyn/devEpics/devAsynOctet.c +++ b/asyn/devEpics/devAsynOctet.c @@ -315,7 +315,7 @@ static long initCommon(dbCommon *precord, DBLINK *plink, userCallback callback, goto bad; } } - if(valSize <= 0) { + if (valSize == 0) { printf("%s record size must be > 0\n",precord->name); precord->pact = 1; goto bad; @@ -629,7 +629,7 @@ static int initCmdBuffer(devPvt *pPvt) static const char *functionName="initCmdBuffer"; len = strlen(pPvt->userParam); - if(len<=0) { + if (len == 0) { printf("%s %s::%s no userParam\n",precord->name, driverName, functionName); precord->pact = 1; recGblSetSevr(precord,LINK_ALARM,INVALID_ALARM); diff --git a/asyn/devGpib/devGpibConvertExample.c b/asyn/devGpib/devGpibConvertExample.c index cd4d51ec8..30828f0cf 100644 --- a/asyn/devGpib/devGpibConvertExample.c +++ b/asyn/devGpib/devGpibConvertExample.c @@ -201,7 +201,7 @@ static int writeCvtio(gpibDpvt *pgpibDpvt,int P1, int P2, char **P3) pgpibDpvt->msgInputLen = 0; lenmsg = writeString(pgpibDpvt,P1,P2,P3); - if(lenmsg <= 0) return -1; + if (lenmsg == 0) return -1; status = pasynOctet->write(asynOctetPvt,pasynUser, pgpibDpvt->msg,lenmsg,&nsent); if(nsent==lenmsg) { diff --git a/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp b/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp index e66ac8f73..b3588938d 100644 --- a/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp +++ b/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp @@ -428,7 +428,7 @@ static asynStatus readIt(void *drvPvt, asynUser *pasynUser, return status; } } - if (maxchars <= 0) { + if (maxchars == 0) { epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize, "%d:%d maxchars %d. Why <=0?\n",ftdi->FTDIvendor, ftdi->FTDIproduct,(int)maxchars); return asynError; @@ -447,9 +447,6 @@ static asynStatus readIt(void *drvPvt, asynUser *pasynUser, } } - if (thisRead < 0){ - thisRead = 0; - } *nbytesTransfered = thisRead; /* If there is room add a null byte */ diff --git a/asyn/drvAsynSerial/drvAsynIPPort.c b/asyn/drvAsynSerial/drvAsynIPPort.c index ff521f06a..a5fd1415f 100644 --- a/asyn/drvAsynSerial/drvAsynIPPort.c +++ b/asyn/drvAsynSerial/drvAsynIPPort.c @@ -733,7 +733,7 @@ static asynStatus readIt(void *drvPvt, asynUser *pasynUser, return asynError; } } - if (maxchars <= 0) { + if (maxchars == 0) { epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize, "%s maxchars %d. Why <=0?",tty->IPDeviceName,(int)maxchars); return asynError; diff --git a/asyn/drvAsynSerial/drvAsynIPServerPort.c b/asyn/drvAsynSerial/drvAsynIPServerPort.c index de123594a..7fac554ef 100644 --- a/asyn/drvAsynSerial/drvAsynIPServerPort.c +++ b/asyn/drvAsynSerial/drvAsynIPServerPort.c @@ -177,7 +177,7 @@ static asynStatus readIt(void *drvPvt, asynUser *pasynUser, asynPrint(pasynUser, ASYN_TRACE_FLOW, "%s %p read.\n", tty->IPDeviceName, tty->pasynUser); - if (maxchars <= 0) { + if (maxchars == 0) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "%s maxchars %d. Why <=0?\n", tty->IPDeviceName, (int) maxchars); return asynError; @@ -530,7 +530,7 @@ int drvAsynIPServerPortConfigure(const char *portName, printf("TCP server information missing.\n"); return -1; } - if (maxClients <= 0) { + if (maxClients == 0) { printf("No clients.\n"); return -1; } diff --git a/asyn/drvAsynSerial/drvAsynSerialPort.c b/asyn/drvAsynSerial/drvAsynSerialPort.c index 1ed6ab475..012ef178e 100644 --- a/asyn/drvAsynSerial/drvAsynSerialPort.c +++ b/asyn/drvAsynSerial/drvAsynSerialPort.c @@ -838,7 +838,7 @@ static asynStatus readIt(void *drvPvt, asynUser *pasynUser, "%s disconnected:", tty->serialDeviceName); return asynError; } - if (maxchars <= 0) { + if (maxchars == 0) { epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize, "%s maxchars %d Why <=0?",tty->serialDeviceName,(int)maxchars); return asynError; diff --git a/asyn/drvAsynSerial/drvAsynSerialPortWin32.c b/asyn/drvAsynSerial/drvAsynSerialPortWin32.c index 2ffbf1548..e27ea0639 100644 --- a/asyn/drvAsynSerial/drvAsynSerialPortWin32.c +++ b/asyn/drvAsynSerial/drvAsynSerialPortWin32.c @@ -524,7 +524,7 @@ static asynStatus readIt(void *drvPvt, asynUser *pasynUser, "%s disconnected:", tty->serialDeviceName); return asynError; } - if (maxchars <= 0) { + if (maxchars == 0) { epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize, "%s maxchars %d Why <=0?",tty->serialDeviceName,(int)maxchars); return asynError; From 201773349982e5ff548d343c4b01fdbf1d065214 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Fri, 28 Apr 2023 11:50:29 -0500 Subject: [PATCH 6/7] Fix printf conversion specifiers - found by cppcheck/sonar --- asyn/drvAsynFTDI/drvAsynFTDIPort.cpp | 2 +- asyn/drvAsynFTDI/ftdiDriver.cpp | 6 +++--- asyn/drvAsynSerial/drvAsynIPServerPort.c | 2 +- asyn/linuxGpib/drvLinuxGpib.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp b/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp index b3588938d..6bae50277 100644 --- a/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp +++ b/asyn/drvAsynFTDI/drvAsynFTDIPort.cpp @@ -520,7 +520,7 @@ drvAsynFTDIPortConfigure(const char *portName, int SPI = ((mode & UART_SPI_BIT)==UART_SPI_BIT)? 1:0; printf("drvAsynFTDIPortConfigure: latency=%d\n", latency); - printf("drvAsynFTDIPortConfigure: priority=%d\n", priority); + printf("drvAsynFTDIPortConfigure: priority=%u\n", priority); printf("drvAsynFTDIPortConfigure: noAutoconnect=%d\n", noAutoConnect); printf("drvAsynFTDIPortConfigure: noProcessEos=%d\n", noProcessEos); printf("drvAsynFTDIPortConfigure: mode="); SPI ? printf("SPI\n") : printf("UART\n"); diff --git a/asyn/drvAsynFTDI/ftdiDriver.cpp b/asyn/drvAsynFTDI/ftdiDriver.cpp index c7d0b13b0..add9ff7af 100644 --- a/asyn/drvAsynFTDI/ftdiDriver.cpp +++ b/asyn/drvAsynFTDI/ftdiDriver.cpp @@ -607,11 +607,11 @@ FTDIDriverStatus FTDIDriver::write(const unsigned char *buffer, int bufferSize, if (rc[3] > 0){ // Since we write also the address byte byteswritten = sz+1 *bytesWritten = (size_t)(sz+1); - debugPrint("%s : %d bytes written err=%d: ", functionName, *bytesWritten, err); + debugPrint("%s : %lu bytes written err=%d: ", functionName, *bytesWritten, err); if( err == FTDIDriverError ) debugPrint("FTDIDriverError\n"); else debugPrint("FTDIDriverSUCCESS\n"); } else { - debugPrint("FTDI write error: %d (%s)\n", rc, ftdi_get_error_string(ftdi_)); + debugPrint("FTDI write error: %lu (%s)\n", rc, ftdi_get_error_string(ftdi_)); *bytesWritten = 0; return FTDIDriverError; } @@ -641,7 +641,7 @@ FTDIDriverStatus FTDIDriver::read(unsigned char *buffer, size_t bufferSize, size return FTDIDriverError; } - debugPrint("%s : Reading: bufferSize=%d, timeout=%d\n", functionName, bufferSize, timeout); + debugPrint("%s : Reading: bufferSize=%lu, timeout=%d\n", functionName, bufferSize, timeout); timeval stime; timeval ctime; diff --git a/asyn/drvAsynSerial/drvAsynIPServerPort.c b/asyn/drvAsynSerial/drvAsynIPServerPort.c index 7fac554ef..7a7f27bdd 100644 --- a/asyn/drvAsynSerial/drvAsynIPServerPort.c +++ b/asyn/drvAsynSerial/drvAsynIPServerPort.c @@ -416,7 +416,7 @@ int createServerSocket(ttyController_t *tty) { srvaddrtxt[sizeof(srvaddrtxt) - 1] = '\0'; printf("serverAddr: %s\n", srvaddrtxt); } - printf("serverPort: %i\n", tty->portNumber); + printf("serverPort: %u\n", tty->portNumber); if (tty->socketType == SOCK_DGRAM) { /* For Port reuse, multiple IOCs */ epicsSocketEnableAddressUseForDatagramFanout(tty->fd); diff --git a/asyn/linuxGpib/drvLinuxGpib.c b/asyn/linuxGpib/drvLinuxGpib.c index 382ef32e1..f89422b89 100644 --- a/asyn/linuxGpib/drvLinuxGpib.c +++ b/asyn/linuxGpib/drvLinuxGpib.c @@ -570,7 +570,7 @@ static asynStatus setEos(void *pdrvPvt,asynUser *pasynUser,const char *eos,int e ibconfig(pGpibBoardPvt->uddev[primaryAddr][secondaryAddr],IbcEOSrd,1); if(DEBUG) - printf("Seting EOS: %u\n",*eos); + printf("Seting EOS: %d\n", *eos); status=checkError(pdrvPvt,pasynUser,addr); if(status!=asynSuccess)return status; From 68e8b6907f1b6bf9135222ff40e9e7bc4c32a796 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Fri, 28 Apr 2023 11:56:17 -0500 Subject: [PATCH 7/7] Reduce scope of temporary variable --- asyn/drvAsynFTDI/ftdiDriver.cpp | 5 ++--- asyn/drvAsynFTDI/ftdiDriver.h | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/asyn/drvAsynFTDI/ftdiDriver.cpp b/asyn/drvAsynFTDI/ftdiDriver.cpp index add9ff7af..cd1f59f1b 100644 --- a/asyn/drvAsynFTDI/ftdiDriver.cpp +++ b/asyn/drvAsynFTDI/ftdiDriver.cpp @@ -50,7 +50,6 @@ FTDIDriver::FTDIDriver(int mode) , spi(mode) , spiInit(0) , buf({0}) - , pbuf(nullptr) , pinState(0) , pinDirection(0) { @@ -93,7 +92,7 @@ FTDIDriverStatus FTDIDriver::initSPI() { // MASTER RESET pinState = Pin::CS|Pin::SYNCIO|Pin::RESET; pinDirection = Pin::SK|Pin::DO|Pin::CS|Pin::SYNCIO|Pin::RESET; - pbuf = (unsigned char *)&buf[0]; + unsigned char *pbuf = (unsigned char *)&buf[0]; *(pbuf + i++) = TCK_DIVISOR; // opcode: set clk divisor *(pbuf + i++) = 0x05; // argument: low bit. 60 MHz / (5+1) = 1 MHz *(pbuf + i++) = 0x00; // argument: high bit. @@ -579,7 +578,7 @@ FTDIDriverStatus FTDIDriver::write(const unsigned char *buffer, int bufferSize, if( spi ) { if( !spiInit ) initSPI(); i = 0; - pbuf = (unsigned char *)&buf[0]; + unsigned char *pbuf = (unsigned char *)&buf[0]; memcpy((pbuf+i), buffer, bufferSize); i+= bufferSize; diff --git a/asyn/drvAsynFTDI/ftdiDriver.h b/asyn/drvAsynFTDI/ftdiDriver.h index fd1e661c6..c235add29 100644 --- a/asyn/drvAsynFTDI/ftdiDriver.h +++ b/asyn/drvAsynFTDI/ftdiDriver.h @@ -94,7 +94,6 @@ class FTDIDriver { int spi; int spiInit; int buf[0x10000]; - unsigned char *pbuf; int connected_; int vendor_;