- 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:
70
velo.c
70
velo.c
@@ -93,7 +93,7 @@ static int VSLimits(void *pData, float fVal, char *pError, int iErrLen)
|
||||
iRet = LLDnodePtr2First(self->iForbidden);
|
||||
LLDnodeDataTo(self->iForbidden, &Alcatraz);
|
||||
if ((fVal < Alcatraz.fMin) || (fVal > Alcatraz.fMax)) {
|
||||
sprintf(pBueffel, " %f out of range: %f --- %f",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, " %f out of range: %f --- %f",
|
||||
fVal, Alcatraz.fMin, Alcatraz.fMax);
|
||||
strncpy(pError, pBueffel, iErrLen);
|
||||
return 0;
|
||||
@@ -104,7 +104,7 @@ static int VSLimits(void *pData, float fVal, char *pError, int iErrLen)
|
||||
while (iRet != 0) {
|
||||
LLDnodeDataTo(self->iForbidden, &Alcatraz);
|
||||
if ((fVal > Alcatraz.fMin) && (fVal < Alcatraz.fMax)) {
|
||||
sprintf(pBueffel, " %f violates forbidden region %f --- %f",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, " %f violates forbidden region %f --- %f",
|
||||
fVal, Alcatraz.fMin, Alcatraz.fMax);
|
||||
strncpy(pError, pBueffel, iErrLen);
|
||||
return 0;
|
||||
@@ -177,7 +177,7 @@ static long VSSetValue(void *pData, SConnection * pCon, float fVal)
|
||||
} else { /* error case */
|
||||
|
||||
self->pDriv->GetError(self->pDriv, &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, eLog);
|
||||
iTest = self->pDriv->TryAndFixIt(self->pDriv, iCode);
|
||||
switch (iTest) {
|
||||
@@ -189,7 +189,7 @@ static long VSSetValue(void *pData, SConnection * pCon, float fVal)
|
||||
/* actual redo done by loop */
|
||||
break;
|
||||
case VELOFAIL:
|
||||
sprintf(pBueffel, "ERROR: aborting with %s", pError);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: aborting with %s", pError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
SCSetInterrupt(pCon, (int) ObVal(self->pPar, INT));
|
||||
return 0;
|
||||
@@ -201,7 +201,7 @@ static long VSSetValue(void *pData, SConnection * pCon, float fVal)
|
||||
/* if we are here we tried three times and failed to get it
|
||||
work
|
||||
*/
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERRROR: Failed 3 times to vary rotation speed. Failing.");
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
SCSetInterrupt(pCon, (int) ObVal(self->pPar, INT));
|
||||
@@ -237,7 +237,7 @@ static int VSCheckStatus(void *pData, SConnection * pCon)
|
||||
case VSNOCON:
|
||||
case VSFAIL:
|
||||
self->pDriv->GetError(self->pDriv, &iCode, pError, 131);
|
||||
sprintf(pBueffel, "WARNING: %s detected", pError);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s detected", pError);
|
||||
SCWrite(pCon, pBueffel, eWarning);
|
||||
iTest = self->pDriv->TryAndFixIt(self->pDriv, iCode);
|
||||
switch (iTest) {
|
||||
@@ -282,11 +282,11 @@ static float VSGetValue(void *pData, SConnection * pCon)
|
||||
switch (iTest) {
|
||||
case VELOOK:
|
||||
case VELOREDO:
|
||||
sprintf(pBueffel, "WARNING: problem %s fixed", pError);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: problem %s fixed", pError);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
break;
|
||||
case VELOFAIL:
|
||||
sprintf(pBueffel, "ERROR: %s", pError);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s", pError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return -9999.;
|
||||
default:
|
||||
@@ -420,7 +420,7 @@ void VSDestroy(void *pData)
|
||||
|
||||
if (self->pMonitor) {
|
||||
strtolower(self->pName);
|
||||
sprintf(pBueffel, "%swatch", self->pName);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%swatch", self->pName);
|
||||
/* EVUnregister(FindEMON(pServ->pSics),pBueffel); */
|
||||
DeleteEVController(self->pMonitor);
|
||||
}
|
||||
@@ -499,7 +499,7 @@ int VSSetTiltRot(pVelSel self, SConnection * pCon, float fNewRot,
|
||||
/* check if rotation in limits */
|
||||
iRet = VSLimits(self, fNewRot, pError, 131);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "ERROR: %s", pError);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s", pError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
@@ -594,7 +594,7 @@ int VSGetLossCurrent(pVelSel self, SConnection * pCon, float *fLoss)
|
||||
SetStatus(eOld);
|
||||
if (!iRet) {
|
||||
self->pDriv->GetError(self->pDriv, &iCode, pError, 131);
|
||||
sprintf(pBueffel, "ERROR: %s while trying to measure loss current",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s while trying to measure loss current",
|
||||
pError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@@ -783,7 +783,7 @@ int VelSelFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
strtolower(argv[2]);
|
||||
pTilt = FindMotor(pSics, argv[2]);
|
||||
if (!pTilt) {
|
||||
sprintf(pBueffel, "ERROR: in VelSelFactory --> %s is not valid motor!",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: in VelSelFactory --> %s is not valid motor!",
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@@ -795,7 +795,7 @@ int VelSelFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
pDriv = VSCreateSim();
|
||||
} else {
|
||||
if (argc < 5) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: missing options array for velocity selector");
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@@ -812,7 +812,7 @@ int VelSelFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
|
||||
if (!pDriv) {
|
||||
sprintf(pBueffel, "ERROR: creating velocity selector driver %s",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: creating velocity selector driver %s",
|
||||
argv[3]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@@ -833,7 +833,7 @@ int VelSelFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
pNew->pName = strdup(argv[1]);
|
||||
iRet = AddCommand(pSics, argv[1], VelSelAction, VSDestroy, pNew);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[2]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate command %s not created", argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
VSDestroy((void *) pNew);
|
||||
return 0;
|
||||
@@ -847,8 +847,8 @@ int VelSelFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
return 0;
|
||||
}
|
||||
pBueffel[0] = '\0';
|
||||
strcpy(pBueffel, argv[1]);
|
||||
strcat(pBueffel, "watch");
|
||||
strncpy(pBueffel, argv[1],255);
|
||||
strncat(pBueffel, "watch",255);
|
||||
pNew->pMonitor = CreateEVController(pMonDriv, pBueffel, &iRet);
|
||||
if (!pNew->pMonitor) {
|
||||
DeleteEVDriver(pMonDriv); /* was missing M.Z. Jul 04 */
|
||||
@@ -858,7 +858,7 @@ int VelSelFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
iRet = AddCommand(pSics, pBueffel, EVControlWrapper,
|
||||
NULL, pNew->pMonitor);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "ERROR: duplicate command %s not created", pBueffel);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate command %s not created", pBueffel);
|
||||
RemoveCommand(pSics, argv[1]);
|
||||
return 0;
|
||||
}
|
||||
@@ -905,10 +905,10 @@ static int RotationInterest(int iEvent, void *pData, void *pUser)
|
||||
}
|
||||
|
||||
if (iEvent == ROTSTART) {
|
||||
sprintf(pBueffel, "%s Starting", pDat->pName);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s Starting", pDat->pName);
|
||||
SCWrite(pDat->pCon, pBueffel, eWarning);
|
||||
} else if (iEvent == ROTMOVE) {
|
||||
sprintf(pBueffel, "%s.rpm = %f", pDat->pName, *fVal);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.rpm = %f", pDat->pName, *fVal);
|
||||
SCWrite(pDat->pCon, pBueffel, eWarning);
|
||||
}
|
||||
return 1;
|
||||
@@ -937,7 +937,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
assert(pSics);
|
||||
|
||||
if (argc < 2) {
|
||||
sprintf(pBueffel, "ERROR: %s expects at least one parameter", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s expects at least one parameter", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
@@ -948,7 +948,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
if (argc >= 3) { /* user wants to set */
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: %s not recognized as numeric value for parameter",
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@@ -957,7 +957,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
return ObParSet(self->pPar, argv[0], argv[1], (float) dVal, pCon);
|
||||
} else { /* just print it */
|
||||
|
||||
sprintf(pBueffel, "%s.%s = %f", argv[0], argv[1], pPar->fVal);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %f", argv[0], argv[1], pPar->fVal);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
@@ -991,14 +991,14 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
/* next two arguments must be min, max */
|
||||
if (argc < 4) {
|
||||
sprintf(pBueffel, "ERROR: insufficient number to %s add", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number to %s add", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
/* OK find fMin */
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: %s not recognized as numeric value for fMin",
|
||||
argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@@ -1009,7 +1009,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* OK find fMax */
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[3], &dVal);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: %s not recognized as numeric value for fMax",
|
||||
argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@@ -1046,7 +1046,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
iRet = VSGetLossCurrent(self, pCon, &fLoss);
|
||||
if (iRet) {
|
||||
sprintf(pBueffel, "%s.LossCurrent = %f", argv[0], fLoss);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.LossCurrent = %f", argv[0], fLoss);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
} else { /* error should have been reported in VSGetLossCurrent */
|
||||
@@ -1076,7 +1076,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* set case */
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: %s not recognized as numeric value for fMax",
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@@ -1089,7 +1089,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else {
|
||||
sprintf(pBueffel, "%s.rottolerance = %f",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.rottolerance = %f",
|
||||
argv[0], self->pDriv->fTolerance);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 1;
|
||||
@@ -1115,7 +1115,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* set case */
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: %s not recognized as numeric value for fMax",
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@@ -1124,7 +1124,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
fTilt = dVal;
|
||||
iDrive = 1;
|
||||
} else {
|
||||
sprintf(pBueffel, "%s tilt = %f", argv[0], fTilt);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s tilt = %f", argv[0], fTilt);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 1;
|
||||
}
|
||||
@@ -1137,7 +1137,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* set case */
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: %s not recognized as numeric value for fMax",
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@@ -1146,7 +1146,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
fRot = dVal;
|
||||
iDrive = 1;
|
||||
} else {
|
||||
sprintf(pBueffel, "%s rot = %f", argv[0], fRot);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s rot = %f", argv[0], fRot);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 1;
|
||||
}
|
||||
@@ -1178,7 +1178,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
/* list command */
|
||||
if (strcmp(argv[1], "list") == 0) {
|
||||
sprintf(pBueffel, "%s.rotation = %f\n%s.Tilt = %f", argv[0], fRot,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.rotation = %f\n%s.Tilt = %f", argv[0], fRot,
|
||||
argv[0], fTilt);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
@@ -1186,7 +1186,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
|
||||
end:
|
||||
/* command not recognized */
|
||||
sprintf(pBueffel, "ERROR: command %s not recognized", pCommand);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: command %s not recognized", pCommand);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user