- 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:
48
optimise.c
48
optimise.c
@ -311,7 +311,7 @@ static int CenterVariable(pOptimise self, SConnection * pCon, int i)
|
||||
if (!iRet) {
|
||||
return 0;
|
||||
}
|
||||
sprintf(pBueffel, "Trying hard to optimise variable %s", pOvar->pName);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Trying hard to optimise variable %s", pOvar->pName);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
iRet = SilentScan(self->pScanner, pOvar->iStep, self->eCount,
|
||||
self->fPreset, pServ->pSics, pCon);
|
||||
@ -328,7 +328,7 @@ static int CenterVariable(pOptimise self, SConnection * pCon, int i)
|
||||
|
||||
/* write some diagnostic messages */
|
||||
strcpy(pBueffel, "Peak Diagnosis: \n");
|
||||
sprintf(cData, "New %s position: %f \n", pOvar->pName, fNewCenter);
|
||||
snprintf(cData,sizeof(cData)-1, "New %s position: %f \n", pOvar->pName, fNewCenter);
|
||||
switch (iRet) {
|
||||
case 1:
|
||||
strcat(pBueffel, "Peak found in scan range \n");
|
||||
@ -355,7 +355,7 @@ static int CenterVariable(pOptimise self, SConnection * pCon, int i)
|
||||
break;
|
||||
default:
|
||||
strcat(pBueffel, cData);
|
||||
sprintf(pData, "Fitting ended with error code %d \n", iRet);
|
||||
snprintf(pData,sizeof(pData)-1, "Fitting ended with error code %d \n", iRet);
|
||||
strcat(pBueffel, cData);
|
||||
break;
|
||||
}
|
||||
@ -390,10 +390,10 @@ static int CenterVariable(pOptimise self, SConnection * pCon, int i)
|
||||
} else { /* the success case */
|
||||
|
||||
pOvar->fShift = ABS(pOvar->fCenter - fNewCenter);
|
||||
sprintf(pBueffel, "%s shifted by %8.2f ", pOvar->pName, pOvar->fShift);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s shifted by %8.2f ", pOvar->pName, pOvar->fShift);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
pOvar->fPrecision = 3 * fStdDev;
|
||||
sprintf(pBueffel, "%s precision set to 3*StdDev = %8.3f",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s precision set to 3*StdDev = %8.3f",
|
||||
pOvar->pName, 3 * fStdDev);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
pOvar->fCenter = fNewCenter;
|
||||
@ -625,7 +625,7 @@ int OptimiserRun(pOptimise self, SConnection * pCon)
|
||||
return iRet;
|
||||
}
|
||||
for (iCycle = 0; iCycle < self->iMaxCycles; iCycle++) {
|
||||
sprintf(pBueffel, "Optimiser cycle %d of %d started", iCycle,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Optimiser cycle %d of %d started", iCycle,
|
||||
self->iMaxCycles);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
for (i = iRedoVar; i < self->iVar; i++) {
|
||||
@ -665,7 +665,7 @@ int OptimiserClimb(pOptimise self, SConnection * pCon)
|
||||
return iRet;
|
||||
}
|
||||
for (iCycle = 0; iCycle < self->iMaxCycles; iCycle++) {
|
||||
sprintf(pBueffel, "Optimiser cycle %d of %d started", iCycle,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Optimiser cycle %d of %d started", iCycle,
|
||||
self->iMaxCycles);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
for (i = iRedoVar; i < self->iVar; i++) {
|
||||
@ -703,14 +703,14 @@ int MakeOptimiser(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* 2 argument must be counter name */
|
||||
pCom = FindCommand(pSics, argv[2]);
|
||||
if (!pCom) {
|
||||
sprintf(pBueffel, "ERROR: Expected counter name, cannot find %s",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Expected counter name, cannot find %s",
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
pCt = GetCountableInterface(pCom->pData);
|
||||
if (!pCt) {
|
||||
sprintf(pBueffel, "ERROR: Expected counter name, BUT %s is NO counter",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Expected counter name, BUT %s is NO counter",
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@ -726,7 +726,7 @@ int MakeOptimiser(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
iRet = AddCommand(pSics, argv[1], OptimiserAction,
|
||||
DeleteOptimiser, 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;
|
||||
}
|
||||
@ -750,7 +750,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
|
||||
|
||||
if (argc < 2) {
|
||||
sprintf(pBueffel, "ERROR: Insufficient arguments to %s", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Insufficient arguments to %s", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
@ -766,7 +766,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
/* check no of args */
|
||||
if (argc < 6) {
|
||||
sprintf(pBueffel, "ERROR: Insufficient arguments to %s addvar",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Insufficient arguments to %s addvar",
|
||||
argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@ -774,7 +774,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/* convert arguments to types */
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[3], &d);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel, "ERROR: expected float value for step but got %s",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected float value for step but got %s",
|
||||
argv[3]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@ -782,7 +782,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
fStep = (float) d;
|
||||
iRet = Tcl_GetInt(pSics->pTcl, argv[4], &iStep);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: expected integer value for iStep but got %s",
|
||||
argv[3]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@ -790,7 +790,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[5], &d);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: expected float value for precision but got %s",
|
||||
argv[3]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@ -799,7 +799,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
fPrec = (float) d;
|
||||
iRet = OptimiserAdd(self, argv[2], fStep, iStep, fPrec);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: cannot optimise variable %s, mistyped?", argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@ -832,7 +832,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
return 0;
|
||||
break;
|
||||
case MAXCYCLE:
|
||||
sprintf(pBueffel, "ERROR: could not optimise peak in %d cycles",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: could not optimise peak in %d cycles",
|
||||
self->iMaxCycles);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@ -876,7 +876,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
return 0;
|
||||
break;
|
||||
case MAXCYCLE:
|
||||
sprintf(pBueffel, "ERROR: could not optimise peak in %d cycles",
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: could not optimise peak in %d cycles",
|
||||
self->iMaxCycles);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
@ -931,9 +931,9 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
|
||||
OptimiserGetPar(self, "countmode", &fVal);
|
||||
if (fVal < 0.05) {
|
||||
sprintf(pBueffel, "%s.countmode = timer", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.countmode = timer", argv[0]);
|
||||
} else {
|
||||
sprintf(pBueffel, "%s.countmode = monitor", argv[0]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.countmode = monitor", argv[0]);
|
||||
}
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
@ -949,7 +949,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &d);
|
||||
if (iRet != TCL_OK) {
|
||||
sprintf(pBueffel,
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1,
|
||||
"ERROR: expected numeric value for %s but got %s", argv[1],
|
||||
argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@ -962,7 +962,7 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else {
|
||||
sprintf(pBueffel, "ERROR: parameter %s not known", argv[1]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: parameter %s not known", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
@ -970,11 +970,11 @@ int OptimiserAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
|
||||
iRet = OptimiserGetPar(self, argv[1], &fVal);
|
||||
if (!iRet) {
|
||||
sprintf(pBueffel, "ERROR: parameter %s not known", argv[1]);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: parameter %s not known", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
sprintf(pBueffel, "%s.%s = %f", argv[0], argv[1], fVal);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %f", argv[0], argv[1], fVal);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user