There are now zero warnings for weak checking with splint.

Reduced number of splint standard check warnings to 4

r1016 | ffr | 2006-06-01 17:07:33 +1000 (Thu, 01 Jun 2006) | 3 lines
This commit is contained in:
Ferdi Franceschini
2006-06-01 17:07:33 +10:00
committed by Douglas Clowes
parent 52b57c96cd
commit 38b6e44306

View File

@@ -36,9 +36,10 @@
/*@-incondefs@*/ /*@-incondefs@*/
/* XXX Should this also free pData */ /* XXX Should this also free pData */
int readRS232(prs232 self, /*@out@*/void *data, /*@out@*/int *dataLen); int readRS232(prs232 self, /*@out@*/void *data, /*@out@*/int *dataLen);
int readRS232TillTerm(prs232 self, /*@out@*/void *data, int *datalen);
void KillRS232(/*@only@*/ void *pData); void KillRS232(/*@only@*/ void *pData);
/*@only@*/ char *Tcl_GetVar2(Tcl_Interp *interp, char *name1, char *name2, int flags); /*@observer@*/ char *Tcl_GetVar2(Tcl_Interp *interp, char *name1, char *name2, int flags);
/*@observer@*/ Tcl_Interp *InterpGetTcl(SicsInterp *pSics); /*@observer@*//*@dependent@*/ Tcl_Interp *InterpGetTcl(SicsInterp *pSics);
/*@+incondefs@*/ /*@+incondefs@*/
/*----------------------------------------------------------------------- /*-----------------------------------------------------------------------
The motor driver structure. Please note that the first set of fields has The motor driver structure. Please note that the first set of fields has
@@ -48,32 +49,30 @@ typedef struct __MoDriv {
/* general motor driver interface /* general motor driver interface
fields. _REQUIRED! fields. _REQUIRED!
*/ */
/*@-incondefs@*/
float fUpper; /* upper limit */ float fUpper; /* upper limit */
float fLower; /* lower limit */ float fLower; /* lower limit */
char *name; /*@owned@*/char *name;
int (*GetPosition)(void *self,float *fPos); int (*GetPosition)(/*@dependent@*/void *self, float *fPos);
int (*RunTo)(void *self, float fNewVal); int (*RunTo)(/*@dependent@*/void *self, float fNewVal);
int (*GetStatus)(void *self); int (*GetStatus)(/*@dependent@*/void *self);
void (*GetError)(void *self, int *iCode, char *buffer, int iBufLen); void (*GetError)(/*@dependent@*/void *self, int *iCode, char *buffer, int iBufLen);
int (*TryAndFixIt)(void *self,int iError, float fNew); int (*TryAndFixIt)(/*@dependent@*/void *self,int iError, float fNew);
int (*Halt)(void *self); int (*Halt)(/*@dependent@*/void *self);
int (*GetDriverPar)(void *self, char *name, int (*GetDriverPar)(/*@dependent@*/void *self, char *name,
float *value); float *value);
int (*SetDriverPar)(void *self,SConnection *pCon, int (*SetDriverPar)(/*@dependent@*/void *self,SConnection *pCon,
char *name, float newValue); char *name, float newValue);
void (*ListDriverPar)(void *self, char *motorName, void (*ListDriverPar)(/*@dependent@*/void *self, char *motorName,
SConnection *pCon); SConnection *pCon);
void (*KillPrivate)(void *self); void (*KillPrivate)(/*@dependent@*/void *self);
/*@+incondefs@*/
/* DMC-2280 specific fields */ /* DMC-2280 specific fields */
SConnection *pCon; /*@observer@*//*@dependent@*/SConnection *pCon;
prs232 controller; prs232 controller;
int iMotor;
int errorCode; int errorCode;
int oredMsr;
int lastValue;
int iConfig;
char units[256]; /**< physical units for axis */ char units[256]; /**< physical units for axis */
float speed; /**< physical units per second */ float speed; /**< physical units per second */
float maxSpeed; /**< physical units per second */ float maxSpeed; /**< physical units per second */
@@ -134,14 +133,14 @@ typedef struct __MoDriv {
#define DECEL "decel" #define DECEL "decel"
#define MAXDECEL "maxDecel" #define MAXDECEL "maxDecel"
static int DMC2280Receive(pDMC2280Driv self, /*@out@*/ char *reply); static int DMC2280Receive(/*@dependent@*/pDMC2280Driv self, /*@out@*/ char *reply);
/** \brief Convert motor speed from physical units to steps/sec /** \brief Convert motor speed from physical units to steps/sec
* \param self (r) provides access to the motor's data structure * \param self (r) provides access to the motor's data structure
* \param speed in physical units, eg mm/sec degrees/sec * \param speed in physical units, eg mm/sec degrees/sec
* \return the speed in motor steps/sec * \return the speed in motor steps/sec
*/ */
static int motSpeed(pDMC2280Driv self, float speed) { static int motSpeed(/*@dependent@*/pDMC2280Driv self, float speed) {
int motSpeed; int motSpeed;
motSpeed = abs((int)(speed * self->stepsPerX + 0.5)); motSpeed = abs((int)(speed * self->stepsPerX + 0.5));
return motSpeed; return motSpeed;
@@ -152,7 +151,7 @@ static int motSpeed(pDMC2280Driv self, float speed) {
* \param acceleration in physical units, eg mm/sec^2 degrees/sec^2 * \param acceleration in physical units, eg mm/sec^2 degrees/sec^2
* \return the acceleration in motor steps/sec^2 * \return the acceleration in motor steps/sec^2
*/ */
static int motAccel(pDMC2280Driv self, float accel) { static int motAccel(/*@dependent@*/pDMC2280Driv self, float accel) {
int motAccel; int motAccel;
motAccel = abs((int)(accel * self->stepsPerX + 0.5)); motAccel = abs((int)(accel * self->stepsPerX + 0.5));
return motAccel; return motAccel;
@@ -163,7 +162,7 @@ static int motAccel(pDMC2280Driv self, float accel) {
* \param deceleration in physical units, eg mm/sec^2 degrees/sec^2 * \param deceleration in physical units, eg mm/sec^2 degrees/sec^2
* \return the deceleration in motor steps/sec^2 * \return the deceleration in motor steps/sec^2
*/ */
static int motDecel(pDMC2280Driv self, float decel) { static int motDecel(/*@dependent@*/pDMC2280Driv self, float decel) {
int motDecel; int motDecel;
motDecel = abs((int)(decel * self->stepsPerX + 0.5)); motDecel = abs((int)(decel * self->stepsPerX + 0.5));
return motDecel; return motDecel;
@@ -179,8 +178,9 @@ static int motDecel(pDMC2280Driv self, float decel) {
* - FAILURE * - FAILURE
* \see SUCCESS FAILURE * \see SUCCESS FAILURE
*/ */
static int DMC2280ReadChar(pDMC2280Driv self, /*@out@*/char *reply) { static int DMC2280ReadChar(/*@dependent@*/pDMC2280Driv self, /*@out@*/char *reply) {
int i, status, retries=20, dataLen=1; int i, status, retries=20, dataLen=1;
reply[0] = '\0';
for (i=0; i<retries; i++) { for (i=0; i<retries; i++) {
status=readRS232(self->controller, reply, &dataLen); status=readRS232(self->controller, reply, &dataLen);
switch (status) { switch (status) {
@@ -213,13 +213,15 @@ static int DMC2280ReadChar(pDMC2280Driv self, /*@out@*/char *reply) {
/* First character returned by controller is /* First character returned by controller is
'?' for an invalid command or '?' for an invalid command or
':' or space for a valid command */ ':' or space for a valid command */
static int DMC2280Send(pDMC2280Driv self, /*@unique@*/char *command) { static int DMC2280Send(/*@dependent@*/pDMC2280Driv self, /*@observer@*//*@dependent@*/char *command) {
char cmdValid, pError[ERRLEN], reply[256]; char cmdValid, pError[ERRLEN], reply[256];
char *GetEMsg = "TC 1"; char *GetEMsg = "TC 1";
int status; int status;
strncpy(self->lastCmd, command, CMDLEN); strncpy(self->lastCmd, command, CMDLEN);
/*@+matchanyintegral@ let size_t from strlen match int */
status = writeRS232(self->controller, command, strlen(command)); status = writeRS232(self->controller, command, strlen(command));
/*@-matchanyintegral@*/
if (status != 1) { if (status != 1) {
self->errorCode = status; self->errorCode = status;
return FAILURE; return FAILURE;
@@ -234,7 +236,9 @@ static int DMC2280Send(pDMC2280Driv self, /*@unique@*/char *command) {
case ' ': case ' ':
return SUCCESS; return SUCCESS;
case '?': case '?':
/*@+matchanyintegral@ let size_t from strlen match int */
status = writeRS232(self->controller, GetEMsg, strlen(GetEMsg)); status = writeRS232(self->controller, GetEMsg, strlen(GetEMsg));
/*@-matchanyintegral@*/
if (status != 1) { if (status != 1) {
self->errorCode = status; self->errorCode = status;
return FAILURE; return FAILURE;
@@ -264,8 +268,9 @@ static int DMC2280Send(pDMC2280Driv self, /*@unique@*/char *command) {
* - FAILURE * - FAILURE
* \see SUCCESS FAILURE * \see SUCCESS FAILURE
*/ */
static int DMC2280Receive(pDMC2280Driv self, /*@out@*/char *reply) { static int DMC2280Receive(/*@dependent@*/pDMC2280Driv self, /*@out@*/char *reply) {
int i, status, retries=20, dataLen=255; int i, status, retries=20, dataLen=255;
reply[0] = '\0';
for (i=0; i<retries; i++) { for (i=0; i<retries; i++) {
status=readRS232TillTerm(self->controller, reply, &dataLen); status=readRS232TillTerm(self->controller, reply, &dataLen);
switch (status) { switch (status) {
@@ -292,7 +297,7 @@ static int DMC2280Receive(pDMC2280Driv self, /*@out@*/char *reply) {
* - OKOK request succeeded * - OKOK request succeeded
* - HWFault request failed * - HWFault request failed
* */ * */
static int DMC2280GetPos(void *pData, float *fPos){ static int DMC2280GetPos(/*@dependent@*/void *pData, float *fPos){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
char reply[1024]; char reply[1024];
char cmd[CMDLEN]; char cmd[CMDLEN];
@@ -330,7 +335,7 @@ static int DMC2280GetPos(void *pData, float *fPos){
* - OKOK request succeeded * - OKOK request succeeded
* - HWFault request failed * - HWFault request failed
* */ * */
static int DMC2280Run(void *pData,float fValue){ static int DMC2280Run(/*@dependent@*/void *pData,float fValue){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
char axis; char axis;
char cmd[CMDLEN], SH[CMDLEN], BG[CMDLEN], absPosCmd[CMDLEN]; char cmd[CMDLEN], SH[CMDLEN], BG[CMDLEN], absPosCmd[CMDLEN];
@@ -381,7 +386,7 @@ static int DMC2280Run(void *pData,float fValue){
* - HWWarn There is a warning from the controller. * - HWWarn There is a warning from the controller.
* - HWIdle The motor has finished driving and is idle. * - HWIdle The motor has finished driving and is idle.
*/ */
static int DMC2280Status(void *pData){ static int DMC2280Status(/*@dependent@*/void *pData){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
char cmd[CMDLEN]; char cmd[CMDLEN];
int switches; int switches;
@@ -462,7 +467,7 @@ static int DMC2280Status(void *pData){
* \param *error error message * \param *error error message
* \param errLen maximum error message length allowed by abstract motor * \param errLen maximum error message length allowed by abstract motor
*/ */
static void DMC2280Error(void *pData, int *iCode, char *error, int errLen){ static void DMC2280Error(/*@dependent@*/void *pData, int *iCode, char *error, int errLen){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
self = (pDMC2280Driv)pData; self = (pDMC2280Driv)pData;
assert(self != NULL); assert(self != NULL);
@@ -530,7 +535,7 @@ static void DMC2280Error(void *pData, int *iCode, char *error, int errLen){
* - MOTREDO try to redo the last move. * - MOTREDO try to redo the last move.
* - MOTFAIL move failed, give up. * - MOTFAIL move failed, give up.
*/ */
static int DMC2280Fix(void *pData, int iCode,/*@unused@*/ float fValue){ static int DMC2280Fix(/*@dependent@*/void *pData, int iCode,/*@unused@*/ float fValue){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
self = (pDMC2280Driv)pData; self = (pDMC2280Driv)pData;
@@ -560,7 +565,7 @@ static int DMC2280Fix(void *pData, int iCode,/*@unused@*/ float fValue){
* *
* XXX Does abstract motor use the return values? * XXX Does abstract motor use the return values?
*/ */
static int DMC2280Halt(void *pData){ static int DMC2280Halt(/*@dependent@*/void *pData){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
char cmd[CMDLEN]; char cmd[CMDLEN];
@@ -593,7 +598,7 @@ static int DMC2280Halt(void *pData){
* - 1 request succeeded * - 1 request succeeded
* - 0 request failed * - 0 request failed
* */ * */
static int DMC2280GetPar(void *pData, char *name, static int DMC2280GetPar(/*@dependent@*/void *pData, char *name,
float *fValue){ float *fValue){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
@@ -651,7 +656,7 @@ static int DMC2280GetPar(void *pData, char *name,
* - 1 request succeeded * - 1 request succeeded
* - 0 request failed * - 0 request failed
* */ * */
static int DMC2280SetPar(void *pData, SConnection *pCon, static int DMC2280SetPar(/*@dependent@*/void *pData, SConnection *pCon,
char *name, float newValue){ char *name, float newValue){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
char pError[ERRLEN]; char pError[ERRLEN];
@@ -749,7 +754,7 @@ static int DMC2280SetPar(void *pData, SConnection *pCon,
* \param *name (r) name of motor. * \param *name (r) name of motor.
* \param *pCon (r) connection object. * \param *pCon (r) connection object.
*/ */
static void DMC2280List(void *self, char *name, SConnection *pCon){ static void DMC2280List(/*@dependent@*/void *self, char *name, SConnection *pCon){
char buffer[BUFFLEN]; char buffer[BUFFLEN];
snprintf(buffer, BUFFLEN, "%s.axis = %c\n", name, ((pDMC2280Driv)self)->axisLabel); snprintf(buffer, BUFFLEN, "%s.axis = %c\n", name, ((pDMC2280Driv)self)->axisLabel);
@@ -775,7 +780,7 @@ static void DMC2280List(void *self, char *name, SConnection *pCon){
/** \brief Free memory if motor is removed /** \brief Free memory if motor is removed
* \param *pData (rw) provides access to the motor's data structure * \param *pData (rw) provides access to the motor's data structure
*/ */
static void KillDMC2280(void *pData){ static void KillDMC2280(/*@only@*/void *pData){
pDMC2280Driv self = NULL; pDMC2280Driv self = NULL;
self = (pDMC2280Driv)pData; self = (pDMC2280Driv)pData;
assert(self != NULL); assert(self != NULL);
@@ -790,7 +795,7 @@ static void KillDMC2280(void *pData){
* \param port DMC2280 port number * \param port DMC2280 port number
* \return controller structure * \return controller structure
*/ */
/*@null@ @only@*/ static prs232 DMC2280Connect(SConnection *pCon, char *host, int port) { /*@null@*/ /*@only@*/ static prs232 DMC2280Connect(/*@dependent@*/SConnection *pCon, char *host, int port) {
prs232 controller=NULL; prs232 controller=NULL;
char pError[ERRLEN]; char pError[ERRLEN];
int usecTimeout = 50000; /* 50msec timeout */ int usecTimeout = 50000; /* 50msec timeout */
@@ -828,7 +833,7 @@ static void KillDMC2280(void *pData){
* - _OPTIONAL * - _OPTIONAL
* \return a string with the parameter value * \return a string with the parameter value
*/ */
/*@observer@*/static char *getParam(SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName, int mustHave ) { /*@observer@*/static char *getParam(/*@dependent@*/SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName, int mustHave ) {
char *pPtr=NULL; char *pPtr=NULL;
char pError[ERRLEN]; char pError[ERRLEN];
pPtr = Tcl_GetVar2(pTcl,params,parName,TCL_GLOBAL_ONLY); pPtr = Tcl_GetVar2(pTcl,params,parName,TCL_GLOBAL_ONLY);
@@ -855,8 +860,8 @@ static void KillDMC2280(void *pData){
* \param *params (r) configuration parameter array. * \param *params (r) configuration parameter array.
* \return a reference to Motordriver structure * \return a reference to Motordriver structure
*/ */
/*@null@*/ MotorDriver *CreateDMC2280(SConnection *pCon, char *motor, char *params){ /*@only@*//*@null@*/ MotorDriver *CreateDMC2280(/*@observer@*/SConnection *pCon, /*@observer@*/char *motor, /*@observer@*/char *params){
/*@keep@*/ pDMC2280Driv pNew = NULL; pDMC2280Driv pNew = NULL;
char *pPtr = NULL; char *pPtr = NULL;
char buffer[132]; char buffer[132];
char pError[ERRLEN]; char pError[ERRLEN];
@@ -877,30 +882,39 @@ static void KillDMC2280(void *pData){
eError); eError);
return NULL; return NULL;
} }
pNew->controller = NULL;
pNew->name = NULL;
pNew->errorCode = 0;
pNew->lastCmd = NULL;
pNew->absEncHome = 0;
pNew->cntsPerX = 0;
/* Get hostname and port from the list of named parameters */ /* Get hostname and port from the list of named parameters */
if ((pPtr=getParam(pCon, interp, params,"port",1)) == NULL) if ((pPtr=getParam(pCon, interp, params,"port",1)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
sscanf(pPtr,"%d",&port); sscanf(pPtr,"%d",&port);
if ((pPtr=getParam(pCon, interp, params,"host",1)) == NULL) if ((pPtr=getParam(pCon, interp, params,"host",1)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
strncpy(buffer,pPtr, 131); strncpy(buffer,pPtr, 131);
/* Connect to the controller */ /* Connect to the controller */
memset(pNew,0,sizeof(DMC2280Driv));
pNew->controller = DMC2280Connect(pCon, buffer,port); pNew->controller = DMC2280Connect(pCon, buffer,port);
if( pNew->controller == NULL ) { if( pNew->controller == NULL ) {
snprintf(pError, ERRLEN, "\tError occurred when creating DMC2280 motor '%s'", motor); snprintf(pError, ERRLEN, "\tError occurred when creating DMC2280 motor '%s'", motor);
SCWrite(pCon,pError,eError); SCWrite(pCon,pError,eError);
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
} }
/*FIXME Tell splint that there's no memory leak because pointers are being initialised here */ /*FIXME Tell splint that there's no memory leak because pointers are being initialised here */
/*@-mustfreeonly@*/
pNew->name = (char *)malloc(sizeof(char)*(strlen(motor)+1)); pNew->name = (char *)malloc(sizeof(char)*(strlen(motor)+1));
if (pNew->name == NULL) { if (pNew->name == NULL) {
(void) SCWrite(pCon,"ERROR: no memory to allocate motor driver", (void) SCWrite(pCon,"ERROR: no memory to allocate motor driver",
eError); eError);
free(pNew); KillDMC2280(pNew);
return NULL; return NULL;
} }
strcpy(pNew->name, motor); strcpy(pNew->name, motor);
@@ -918,26 +932,38 @@ static void KillDMC2280(void *pData){
pNew->SetDriverPar = DMC2280SetPar; pNew->SetDriverPar = DMC2280SetPar;
pNew->ListDriverPar = DMC2280List; pNew->ListDriverPar = DMC2280List;
pNew->KillPrivate = KillDMC2280; pNew->KillPrivate = KillDMC2280;
if ((pPtr=getParam(pCon, interp, params,UNITS,_REQUIRED)) == NULL) if ((pPtr=getParam(pCon, interp, params,UNITS,_REQUIRED)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
sscanf(pPtr,"%s",pNew->units); sscanf(pPtr,"%s",pNew->units);
if ((pPtr=getParam(pCon, interp, params,MAXSPEED,_REQUIRED)) == NULL) if ((pPtr=getParam(pCon, interp, params,MAXSPEED,_REQUIRED)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
sscanf(pPtr,"%f",&(pNew->speed)); sscanf(pPtr,"%f",&(pNew->speed));
pNew->maxSpeed = pNew->speed; pNew->maxSpeed = pNew->speed;
if ((pPtr=getParam(pCon, interp, params,MAXACCEL,_REQUIRED)) == NULL) if ((pPtr=getParam(pCon, interp, params,MAXACCEL,_REQUIRED)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
sscanf(pPtr,"%f",&(pNew->accel)); sscanf(pPtr,"%f",&(pNew->accel));
pNew->maxAccel = pNew->accel; pNew->maxAccel = pNew->accel;
if ((pPtr=getParam(pCon, interp, params,MAXDECEL,_REQUIRED)) == NULL) if ((pPtr=getParam(pCon, interp, params,MAXDECEL,_REQUIRED)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
sscanf(pPtr,"%f",&(pNew->decel)); sscanf(pPtr,"%f",&(pNew->decel));
pNew->maxDecel = pNew->decel; pNew->maxDecel = pNew->decel;
if ((pPtr=getParam(pCon, interp, params,"axis",_REQUIRED)) == NULL) if ((pPtr=getParam(pCon, interp, params,"axis",_REQUIRED)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
sscanf(pPtr,"%c",&(pNew->axisLabel)); sscanf(pPtr,"%c",&(pNew->axisLabel));
if ((pPtr=getParam(pCon, interp, params,"stepsPerX",_REQUIRED)) == NULL) if ((pPtr=getParam(pCon, interp, params,"stepsPerX",_REQUIRED)) == NULL) {
goto FailedCreateDMC2280; KillDMC2280(pNew);
return NULL;
}
sscanf(pPtr,"%d",&(pNew->stepsPerX)); sscanf(pPtr,"%d",&(pNew->stepsPerX));
if ((pPtr=getParam(pCon, interp, params,"motorHome",_OPTIONAL)) == NULL) if ((pPtr=getParam(pCon, interp, params,"motorHome",_OPTIONAL)) == NULL)
pNew->motorHome=0; pNew->motorHome=0;
@@ -956,7 +982,6 @@ static void KillDMC2280(void *pData){
else else
sscanf(pPtr,"%d",&(pNew->cntsPerX)); sscanf(pPtr,"%d",&(pNew->cntsPerX));
} }
/*@+mustfreeonly@*/
/* Set speed */ /* Set speed */
snprintf(cmd,CMDLEN,"SP%c=%d", pNew->axisLabel, motSpeed(pNew, pNew->speed)); snprintf(cmd,CMDLEN,"SP%c=%d", pNew->axisLabel, motSpeed(pNew, pNew->speed));
@@ -972,10 +997,6 @@ static void KillDMC2280(void *pData){
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* TODO Initialise current position and target to get a sensible initial list output */ /* TODO Initialise current position and target to get a sensible initial list output */
return (MotorDriver *)pNew; return (MotorDriver *)pNew;
FailedCreateDMC2280:
if (NULL != pNew)
free(pNew);
return NULL;
} }