Skip to content

Commit

Permalink
Merge pull request #178 from ralphlange/misc-fixes
Browse files Browse the repository at this point in the history
Misc fixes found by static code analysis
  • Loading branch information
MarkRivers authored May 24, 2023
2 parents 06f104d + 7b56a38 commit b691d1f
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ O.*/
*.swp
*_BAK.adl
/QtC-*
/.qtc_*
cdCommands
envPaths
dllPath.bat
2 changes: 1 addition & 1 deletion asyn/asynDriver/asynManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion asyn/asynGpib/drvSkeleton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion asyn/asynPortClient/asynPortClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions asyn/devEpics/devAsynOctet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion asyn/devGpib/devGpibConvertExample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 2 additions & 5 deletions asyn/drvAsynFTDI/drvAsynFTDIPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -523,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");
Expand Down
21 changes: 13 additions & 8 deletions asyn/drvAsynFTDI/ftdiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ 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})
, pinState(0)
, pinDirection(0)
{
static const char *functionName = "FTDIDriver::FTDIDriver";
debugPrint("%s : Method called - ", functionName);
Expand All @@ -66,8 +72,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() {
Expand All @@ -88,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.
Expand Down Expand Up @@ -574,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;
Expand Down Expand Up @@ -602,11 +606,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 : %llu bytes written err=%d: ", functionName, (unsigned long long) *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: %llu (%s)\n", (unsigned long long) rc, ftdi_get_error_string(ftdi_));
*bytesWritten = 0;
return FTDIDriverError;
}
Expand Down Expand Up @@ -636,7 +640,8 @@ 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=%llu, timeout=%d\n",
functionName, (unsigned long long) bufferSize, timeout);

timeval stime;
timeval ctime;
Expand Down
1 change: 0 additions & 1 deletion asyn/drvAsynFTDI/ftdiDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class FTDIDriver {
int spi;
int spiInit;
int buf[0x10000];
unsigned char *pbuf;

int connected_;
int vendor_;
Expand Down
2 changes: 1 addition & 1 deletion asyn/drvAsynSerial/drvAsynIPPort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions asyn/drvAsynSerial/drvAsynIPServerPort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion asyn/drvAsynSerial/drvAsynSerialPort.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,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;
Expand Down
2 changes: 1 addition & 1 deletion asyn/drvAsynSerial/drvAsynSerialPortWin32.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,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;
Expand Down
2 changes: 1 addition & 1 deletion asyn/linuxGpib/drvLinuxGpib.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,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;
Expand Down
2 changes: 1 addition & 1 deletion asyn/miscellaneous/asynShellCommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b691d1f

Please sign in to comment.