- After a bug at TRICS I replaced all occurrences of strcpy, strcat, sprintf
by length limited versions wherever appropriate. SKIPPED: psi/el755driv.c psi/faverage.c psi/frame.c psi/lmd200.c psi/polterwrite.c psi/psi.c psi/sanswave.c psi/sinqhmdriv.c psi/termprot.c
This commit is contained in:
80
motor.c
80
motor.c
@ -248,38 +248,38 @@ static int MotorSaveStatus(void *pData, char *name, FILE * fd)
|
||||
|
||||
self = (pMotor) pData;
|
||||
fprintf(fd, "# Motor %s\n", name);
|
||||
sprintf(pBueffel, "%s sign %f\n", name, ObVal(self->ParArray, SIGN));
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s sign %f\n", name, ObVal(self->ParArray, SIGN));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s SoftZero %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s SoftZero %f\n", name,
|
||||
ObVal(self->ParArray, SZERO));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s SoftLowerLim %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s SoftLowerLim %f\n", name,
|
||||
ObVal(self->ParArray, SLOW));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s SoftUpperLim %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s SoftUpperLim %f\n", name,
|
||||
ObVal(self->ParArray, SUPP));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s Fixed %f\n", name, ObVal(self->ParArray, FIX));
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s Fixed %f\n", name, ObVal(self->ParArray, FIX));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s InterruptMode %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s InterruptMode %f\n", name,
|
||||
ObVal(self->ParArray, INT));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s precision %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s precision %f\n", name,
|
||||
ObVal(self->ParArray, PREC));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s ignorefault %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s ignorefault %f\n", name,
|
||||
ObVal(self->ParArray, IGNOREFAULT));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s AccessCode %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s AccessCode %f\n", name,
|
||||
ObVal(self->ParArray, USRIGHTS));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s failafter %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s failafter %f\n", name,
|
||||
ObVal(self->ParArray, ECOUNT));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s maxretry %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s maxretry %f\n", name,
|
||||
ObVal(self->ParArray, POSCOUNT));
|
||||
fputs(pBueffel, fd);
|
||||
sprintf(pBueffel, "%s movecount %f\n", name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s movecount %f\n", name,
|
||||
ObVal(self->ParArray, MOVECOUNT));
|
||||
fputs(pBueffel, fd);
|
||||
return 1;
|
||||
@ -639,11 +639,11 @@ static int MotorGetHardPositionImpl(pMotor self, SConnection * pCon,
|
||||
/* no point in trying this three times */
|
||||
self->pDriver->GetError(self->pDriver, &iCode, pError, 255);
|
||||
iRet = self->pDriver->TryAndFixIt(self->pDriver, iCode, fVal);
|
||||
sprintf(pBueffel, "WARNING: Trying to fix %s", pError);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: Trying to fix %s", pError);
|
||||
SCWrite(pCon, pBueffel, eWarning);
|
||||
switch (iRet) {
|
||||
case MOTFAIL:
|
||||
sprintf(pBueffel, "ERROR: cannot fix motor %s", self->name);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot fix motor %s", self->name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
SCSetInterrupt(pCon, (int) ObVal(self->ParArray, INT));
|
||||
*fHard = fVal;
|
||||
@ -655,7 +655,7 @@ static int MotorGetHardPositionImpl(pMotor self, SConnection * pCon,
|
||||
*fHard = fVal * ObVal(self->ParArray, SIGN);
|
||||
return 1;
|
||||
} else {
|
||||
sprintf(pBueffel, "ERROR: cannot fix motor %s", self->name);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot fix motor %s", self->name);
|
||||
SCSetInterrupt(pCon, (int) ObVal(self->ParArray, INT));
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
*fHard = fVal;
|
||||
@ -684,7 +684,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
|
||||
/* check if I'am allowed to move this motor */
|
||||
if (!SCMatchRights(pCon, (int) ObVal(self->ParArray, USRIGHTS))) {
|
||||
sprintf(pBueffel, "ERROR: You are not authorised to move motor %s",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: You are not authorised to move motor %s",
|
||||
self->name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
@ -713,7 +713,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
/* big alarm */
|
||||
ServerWriteGlobal("ERROR: !!! MOTOR ALARM !!! MOTOR ALARM !!!",
|
||||
eError);
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: too many position errors counted at motor %s",
|
||||
self->name);
|
||||
ServerWriteGlobal(pBueffel, eError);
|
||||
@ -733,7 +733,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
if (iRet != OKOK) { /* try three times to fix it */
|
||||
for (i = 0; (i < 3) && (iRet != OKOK); i++) {
|
||||
self->pDriver->GetError(self->pDriver, &iCode, pError, 131);
|
||||
sprintf(pBueffel, "WARNING: Trying to fix: %s", pError);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: Trying to fix: %s", pError);
|
||||
SCWrite(pCon, pBueffel, eWarning);
|
||||
iRet = self->pDriver->TryAndFixIt(self->pDriver, iCode, fHard);
|
||||
switch (iRet) {
|
||||
@ -1008,7 +1008,7 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* create the motor */
|
||||
pNew = MotorInit("SIM", argv[1], pDriver);
|
||||
if (!pNew) {
|
||||
sprintf(pBueffel, "Failure to create motor %s", argv[1]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Failure to create motor %s", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eLogError);
|
||||
return 0;
|
||||
}
|
||||
@ -1020,7 +1020,7 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* create the motor */
|
||||
pNew = MotorInit("TCLMOT", argv[1], pDriver);
|
||||
if (!pNew) {
|
||||
sprintf(pBueffel, "Failure to create motor %s", argv[1]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Failure to create motor %s", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eLogError);
|
||||
return 0;
|
||||
}
|
||||
@ -1032,7 +1032,7 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* create the motor */
|
||||
pNew = MotorInit("regress", argv[1], pDriver);
|
||||
if (!pNew) {
|
||||
sprintf(pBueffel, "Failure to create motor %s", argv[1]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Failure to create motor %s", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eLogError);
|
||||
return 0;
|
||||
}
|
||||
@ -1042,7 +1042,7 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
pNew = site->CreateMotor(pCon, argc - 1, &argv[1]);
|
||||
}
|
||||
if (pNew == NULL) {
|
||||
sprintf(pBueffel, "Motor Type %s not recognized for motor %s",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Motor Type %s not recognized for motor %s",
|
||||
argv[2], argv[1]);
|
||||
SCWrite(pCon, pBueffel, eLogError);
|
||||
return 0;
|
||||
@ -1052,7 +1052,7 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* create the interpreter command */
|
||||
iRet = AddCommand(pSics, argv[1], MotorAction, MotorKill, pNew);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[1]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate command %s not created", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
@ -1066,11 +1066,11 @@ void MotorListLL(pMotor self, SConnection * pCon)
|
||||
int i, iLen;
|
||||
|
||||
iLen = ObParLength(self->ParArray);
|
||||
sprintf(pBueffel, "Parameter Listing for motor %s", self->name);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Parameter Listing for motor %s", self->name);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
sprintf(pBueffel, "%s.Position = %f\n", self->name, self->fPosition);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.Position = %f\n", self->name, self->fPosition);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
sprintf(pBueffel, "%s.TargetPosition = %f\n", self->name, self->fTarget);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.TargetPosition = %f\n", self->name, self->fTarget);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
|
||||
snprintf(pBueffel, 511, "%s.hardlowerlim = %f", self->name,
|
||||
@ -1080,7 +1080,7 @@ void MotorListLL(pMotor self, SConnection * pCon)
|
||||
self->pDriver->fUpper);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
for (i = 0; i < iLen; i++) {
|
||||
sprintf(pBueffel, "%s.%s = %f\n", self->name,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %f\n", self->name,
|
||||
self->ParArray[i].name, self->ParArray[i].fVal);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
}
|
||||
@ -1146,7 +1146,7 @@ static int InterestCallback(int iEvent, void *pEvent, void *pUser)
|
||||
if (pInfo->lastValue != psCall->fVal) {
|
||||
pInfo->lastValue = psCall->fVal;
|
||||
(pInfo->pCon)->conEventType = POSITION;
|
||||
sprintf(pBueffel, "%s.position = %f ", pInfo->pName, pInfo->lastValue);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.position = %f ", pInfo->pName, pInfo->lastValue);
|
||||
SCWrite(pInfo->pCon, pBueffel, eEvent);
|
||||
}
|
||||
return 1;
|
||||
@ -1174,7 +1174,7 @@ static int EndScriptCallback(int iEvent, void *pEvent, void *pUser)
|
||||
psCall = (MotCallback *) pEvent;
|
||||
pScript = (char *) pUser;
|
||||
|
||||
sprintf(pCommand, "%s %f", pScript, psCall->fVal);
|
||||
snprintf(pCommand,sizeof(pCommand)-1, "%s %f", pScript, psCall->fVal);
|
||||
iRet = Tcl_Eval(pServ->pSics->pTcl, pCommand);
|
||||
return iRet;
|
||||
}
|
||||
@ -1223,12 +1223,12 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
if (!pCurrent) { /* no argument, print value */
|
||||
iRet = MotorGetSoftPosition(self, pCon, &fValue);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "Error obtaining position for %s", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Error obtaining position for %s", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
sprintf(pBueffel, "%s = %f", argv[0], fValue);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %f", argv[0], fValue);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 1;
|
||||
@ -1242,7 +1242,7 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
} /* check for reset */
|
||||
else if (strcmp(pCurrent->text, "reset") == 0) {
|
||||
if (!SCMatchRights(pCon, usUser)) {
|
||||
sprintf(pBueffel, "Insufficient privilege to reset %s", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient privilege to reset %s", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
@ -1261,7 +1261,7 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
pMoti->pCon = SCCopyConnection(pCon);
|
||||
iRet = MotorGetSoftPosition(self, pCon, &fValue);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"Failed to register interest, Reason:Error obtaining current position for %s",
|
||||
argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@ -1308,36 +1308,36 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
if (strcmp(pName->text, "position") == 0) {
|
||||
iRet = MotorGetSoftPosition(self, pCon, &fValue);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "Error obtaining position for %s", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Error obtaining position for %s", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
sprintf(pBueffel, "%s.SoftPosition = %f", argv[0], fValue);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.SoftPosition = %f", argv[0], fValue);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 1;
|
||||
} else if (strcmp(pName->text, "hardposition") == 0) {
|
||||
iRet = MotorGetHardPosition(self, pCon, &fValue);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "Error obtaining position for %s", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Error obtaining position for %s", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
sprintf(pBueffel, "%s.HardPosition = %f", argv[0], fValue);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.HardPosition = %f", argv[0], fValue);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 1;
|
||||
}
|
||||
iRet = MotorGetPar(self, pName->text, &fValue);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "Parameter %s not found ", pName->text);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Parameter %s not found ", pName->text);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
} else {
|
||||
sprintf(pBueffel, "%s.%s = %f", self->name, pName->text, fValue);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %f", self->name, pName->text, fValue);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 1;
|
||||
@ -1350,7 +1350,7 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
} else if (pCurrent->Type == eFloat) {
|
||||
fValue = pCurrent->fVal;
|
||||
} else {
|
||||
sprintf(pBueffel, "Wrong argument type for %s %s set",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Wrong argument type for %s %s set",
|
||||
argv[0], pName->text);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
DeleteTokenList(pList);
|
||||
|
Reference in New Issue
Block a user