- 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:
koennecke
2009-12-04 12:58:31 +00:00
parent 297f9f2e02
commit 8cc5474334
80 changed files with 899 additions and 881 deletions

View File

@@ -80,7 +80,7 @@ static float Energy2Wave(float fVal, SConnection * pCon)
char pBueffel[132];
if (fVal < .0) {
sprintf(pBueffel,
snprintf(pBueffel,sizeof(pBueffel)-1,
"ERROR: Invalid energy %f specified, defaulted to 20.", fVal);
SCWrite(pCon, pBueffel, eError);
fWave = 20. / 2.07;
@@ -120,7 +120,7 @@ static int CheckELimits(void *pSelf, float fNew, char *error, int iErrLen)
fWave = fNew / 2.07;
if (fWave < .0) {
sprintf(pBueffel, "ERROR: Invalid energy %f specified", fNew);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Invalid energy %f specified", fNew);
strncpy(error, pBueffel, iErrLen);
return 0;
}
@@ -364,7 +364,7 @@ int MakeWaveLengthVar(SConnection * pCon, SicsInterp * pSics, void *pData,
/* 99.99999999999 % of all code is argument checking! */
argtolower(argc, argv);
if (argc < 3) {
sprintf(pBueffel, "ERROR: Insufficient number of arguments to %s",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Insufficient number of arguments to %s",
argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
@@ -373,18 +373,18 @@ int MakeWaveLengthVar(SConnection * pCon, SicsInterp * pSics, void *pData,
/* argv[1] == name, argv[2] should be a monochromator, find it */
pCom = FindCommand(pSics, argv[2]);
if (!pCom) {
sprintf(pBueffel, "ERROR: %s not found", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not found", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
pMono = (pSicsSelector) pCom->pData;
if (!pMono) {
sprintf(pBueffel, "ERROR: %s is no monochromator", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no monochromator", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
if (!iHasType(pMono, "CrystalSelector")) {
sprintf(pBueffel, "ERROR: %s is no monochromator", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no monochromator", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@@ -392,13 +392,13 @@ int MakeWaveLengthVar(SConnection * pCon, SicsInterp * pSics, void *pData,
/* got everything we need to set things up */
pNeu = CreateWLVar(argv[1], pMono);
if (!pNeu) {
sprintf(pBueffel, "ERROR: Out of memory creating %s found", argv[1]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Out of memory creating %s found", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
iRet = AddCommand(pSics, argv[1], WaveLengthAction, DeleteSelVar, pNeu);
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]);
DeleteSelVar((void *) pNeu);
SCWrite(pCon, pBueffel, eError);
return 0;
@@ -419,7 +419,7 @@ int MakeEnergyVar(SConnection * pCon, SicsInterp * pSics, void *pData,
/* 99.99999999999 % of all code is argument checking! */
argtolower(argc, argv);
if (argc < 3) {
sprintf(pBueffel, "ERROR: Insufficient number of arguments to %s",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Insufficient number of arguments to %s",
argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
@@ -428,18 +428,18 @@ int MakeEnergyVar(SConnection * pCon, SicsInterp * pSics, void *pData,
/* argv[1] == name, argv[2] should be a monochromator, find it */
pCom = FindCommand(pSics, argv[2]);
if (!pCom) {
sprintf(pBueffel, "ERROR: %s not found", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not found", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
pMono = (pSicsSelector) pCom->pData;
if (!pMono) {
sprintf(pBueffel, "ERROR: %s is no monochromator", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no monochromator", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
if (!iHasType(pMono, "CrystalSelector")) {
sprintf(pBueffel, "ERROR: %s is no monochromator", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no monochromator", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@@ -447,13 +447,13 @@ int MakeEnergyVar(SConnection * pCon, SicsInterp * pSics, void *pData,
/* got everything we need to set things up */
pNeu = CreateEnergy(argv[1], pMono);
if (!pNeu) {
sprintf(pBueffel, "ERROR: Out of memory creating %s found", argv[1]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Out of memory creating %s found", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
iRet = AddCommand(pSics, argv[1], EnergyAction, DeleteSelVar, pNeu);
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);
DeleteSelVar((void *) pNeu);
return 0;
@@ -479,7 +479,7 @@ static int WaveLengthCallBack(int iEvent, void *pEvent, void *pUser)
}
fVal = GetSelValue(self, pCon);
sprintf(pBueffel, "%s.value = %f", self->name, fVal);
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.value = %f", self->name, fVal);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
@@ -525,12 +525,12 @@ int WaveLengthAction(SConnection * pCon, SicsInterp * pSics, void *pData,
/* verify that argv[1] is a valid number */
iRet = Tcl_GetDouble(pSics->pTcl, argv[1], &dVal);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: %s is NO valid number ", argv[1]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is NO valid number ", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
if (dVal < 0) {
sprintf(pBueffel, "ERROR: %s cannnot be a valid wavelength",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s cannnot be a valid wavelength",
argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
@@ -538,7 +538,7 @@ int WaveLengthAction(SConnection * pCon, SicsInterp * pSics, void *pData,
/*
Removed, on demand of Lukas Keller, DMC
sprintf(pBueffel,"%s %s %s",DRIVE,argv[0],argv[1]);
snprintf(pBueffel,sizeof(pBueffel)-1,"%s %s %s",DRIVE,argv[0],argv[1]);
return InterpExecute(pSics,pCon,pBueffel);
*/
snprintf(pBueffel, 131, "ERROR: subcommand %s to %s not understood",
@@ -548,7 +548,7 @@ int WaveLengthAction(SConnection * pCon, SicsInterp * pSics, void *pData,
} else { /* get case */
fWave = GetMonoPosition(self->pSel, pCon);
sprintf(pBueffel, "%s = %f", argv[0], fWave);
snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %f", argv[0], fWave);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
@@ -588,18 +588,18 @@ int EnergyAction(SConnection * pCon, SicsInterp * pSics, void *pData,
/* verify that argv[1] is a valid number */
iRet = Tcl_GetDouble(pSics->pTcl, argv[1], &dVal);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: %s is NO valid number ", argv[1]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is NO valid number ", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
if (dVal < 0) {
sprintf(pBueffel, "ERROR: %s cannnot be a valid energy", argv[1]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s cannnot be a valid energy", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
sprintf(pBueffel, "%s %s %s", DRIVE, argv[0], argv[1]);
snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s %s", DRIVE, argv[0], argv[1]);
return InterpExecute(pSics, pCon, pBueffel);
} else { /* get case */
@@ -611,7 +611,7 @@ int EnergyAction(SConnection * pCon, SicsInterp * pSics, void *pData,
} else {
fWave = 777.77;
}
sprintf(pBueffel, "%s = %f", argv[0], fWave);
snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %f", argv[0], fWave);
SCWrite(pCon, pBueffel, eValue);
return 1;
}