- 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

90
scan.c
View File

@ -151,14 +151,14 @@ pScanData CreateScanObject(char *pRecover, char *pHeader, pCounter pCount,
/* assign various things */
if (pRecover) {
strcpy(pNew->pRecover, pRecover);
strncpy(pNew->pRecover, pRecover,1024);
}
if (pHeader) {
strcpy(pNew->pHeaderFile, pHeader);
strncpy(pNew->pHeaderFile, pHeader,1024);
}
pNew->iMode = eTimer;
pNew->fPreset = 10.;
strcpy(pNew->pCounterName, pCount->name);
strncpy(pNew->pCounterName, pCount->name,511);
pNew->pCounterData = pCount;
pNew->PrepareScan = PrepareScan;
pNew->WriteHeader = WriteHeader;
@ -759,7 +759,7 @@ int ContinueScan(pScanData self, SicsInterp * pSics, SConnection * pCon,
/* get NP */
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &self->iNP);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -769,7 +769,7 @@ int ContinueScan(pScanData self, SicsInterp * pSics, SConnection * pCon,
} else if (strcmp(argv[3], "monitor") == 0) {
self->iMode = ePreset;
} else {
sprintf(pBueffel, "ERROR: %s not recognized as valid counter mode",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not recognized as valid counter mode",
argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
@ -777,7 +777,7 @@ int ContinueScan(pScanData self, SicsInterp * pSics, SConnection * pCon,
/* preset */
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[4], &dVal);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -798,9 +798,9 @@ int ContinueScan(pScanData self, SicsInterp * pSics, SConnection * pCon,
self->pSics = NULL;
return 0;
}
sprintf(pBueffel, "Writing data file: %s ...", pPtr);
snprintf(pBueffel,sizeof(pBueffel)-1, "Writing data file: %s ...", pPtr);
SCWrite(self->pCon, pBueffel, eWarning);
strcpy(self->pFile, pPtr);
strncpy(self->pFile, pPtr,1023);
free(pPtr);
iRet = self->WriteHeader(self);
if (!iRet) {
@ -1130,18 +1130,18 @@ int ScanFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
strtolower(argv[2]);
pCom = FindCommand(pSics, argv[2]);
if (!pCom) {
sprintf(pBueffel, "ERROR: cannot find counter %s", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot find counter %s", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
pDum = (pDummy) pCom->pData;
if (!pDum) {
sprintf(pBueffel, "ERROR: counter %s has no data", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: counter %s has no data", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
if (!(pDum->pDescriptor->GetInterface(pDum, COUNTID))) {
sprintf(pBueffel, "ERROR: object %s is NO counter", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: object %s is NO counter", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -1155,7 +1155,7 @@ int ScanFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
iRet = AddCommand(pSics, argv[1], ScanWrapper, DeleteScanObject, 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;
}
@ -1212,7 +1212,7 @@ static int ScanInterest(int iEvent, void *pEventData, void *pUser)
strcpy(pPtr, "scan.Counts= {");
for (i = 0; i < self->iNP; i++) {
sprintf(pItem, "%ld ", lData[i]);
snprintf(pItem,sizeof(pItem)-1, "%ld ", lData[i]);
strcat(pPtr, pItem);
}
strcat(pPtr, "}");
@ -1634,7 +1634,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
argtolower(argc, argv);
if (argc < 2) {
sprintf(pBueffel, "ERROR: not enough arguments for %s", argv[0]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: not enough arguments for %s", argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -1645,7 +1645,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/*---------- getfile */
if (strcmp(argv[1], "getfile") == 0) {
sprintf(pBueffel, "scan.File = %s", self->pFile);
snprintf(pBueffel,sizeof(pBueffel)-1, "scan.File = %s", self->pFile);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
@ -1665,7 +1665,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
}
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &i);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected integer, got %s", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected integer, got %s", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -1703,13 +1703,13 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
}
/*--------- noscanvar */
else if (strcmp(argv[1], "noscanvar") == 0) {
sprintf(pBueffel, "%s.noscanvar = %d", argv[0], self->iScanVar);
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.noscanvar = %d", argv[0], self->iScanVar);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
/*-------- NP */
else if (strcmp(argv[1], "np") == 0) {
sprintf(pBueffel, "%s.nP = %d", argv[0], self->iNP);
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.nP = %d", argv[0], self->iNP);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
@ -1719,7 +1719,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argc >= 3) {
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &i);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected integer, got %s", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected integer, got %s", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -1764,7 +1764,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/* format them */
sprintf(pPtr, "scan.%s = ", ScanVarName(pVar));
for (i = 0; i < self->iNP; i++) {
sprintf(pItem, "{%12.4f} ", fData[i]);
snprintf(pItem,sizeof(pItem)-1, "{%12.4f} ", fData[i]);
strcat(pPtr, pItem);
}
SCWrite(pCon, pPtr, eValue);
@ -1778,7 +1778,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argc >= 3) {
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &i);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected integer, got %s", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected integer, got %s", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -1850,7 +1850,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/*---------- add command */
if (strcmp(argv[1], "add") == 0) {
if (argc < 5) {
sprintf(pBueffel,
snprintf(pBueffel,sizeof(pBueffel)-1,
"ERROR: Insufficient number of arguments given for %s add",
argv[0]);
SCWrite(pCon, pBueffel, eError);
@ -1859,13 +1859,13 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/* get numbers */
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[3], &fStart);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[4], &fStep);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -1877,7 +1877,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
return iRet;
} else if (strcmp(argv[1], "log") == 0) {
if (argc < 3) {
sprintf(pBueffel,
snprintf(pBueffel,sizeof(pBueffel)-1,
"ERROR: Insufficient number of arguments given for %s log",
argv[0]);
SCWrite(pCon, pBueffel, eError);
@ -1942,7 +1942,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
iRet = site->ConfigureScan(self, argv[2]);
}
if (!iRet) {
sprintf(pBueffel, "ERROR: option %s not recognized by configure",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: option %s not recognized by configure",
argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
@ -1959,14 +1959,14 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/*---------- scan */
else if (strcmp(argv[1], "run") == 0) {
if (argc < 5) {
sprintf(pBueffel, "ERROR: not enough arguments for %s run", argv[0]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: not enough arguments for %s run", argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
/* get NP */
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &lNP);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -1976,7 +1976,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
} else if (strcmp(argv[3], "monitor") == 0) {
iMode = ePreset;
} else {
sprintf(pBueffel, "ERROR: %s not recognized as valid counter mode",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not recognized as valid counter mode",
argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
@ -1984,7 +1984,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/* preset */
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[4], &fPreset);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -2001,7 +2001,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/*---------- silent */
else if (strcmp(argv[1], "silent") == 0) {
if (argc < 5) {
sprintf(pBueffel, "ERROR: not enough arguments for %s silent",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: not enough arguments for %s silent",
argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
@ -2009,7 +2009,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/* get NP */
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &lNP);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -2019,7 +2019,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
} else if (strcmp(argv[3], "monitor") == 0) {
iMode = ePreset;
} else {
sprintf(pBueffel, "ERROR: %s not recognized as valid counter mode",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not recognized as valid counter mode",
argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
@ -2027,7 +2027,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/* preset */
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[4], &fPreset);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -2054,7 +2054,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/* convert to int */
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &iChannel);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected integer, got %s", argv[2]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected integer, got %s", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -2072,7 +2072,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
else if (strcmp(argv[1], "command") == 0) {
/* inquire */
if (argc < 3) {
sprintf(pBueffel, "%s.command = %s", argv[0], self->pCommand);
snprintf(pBueffel,sizeof(pBueffel)-1, "%s.command = %s", argv[0], self->pCommand);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
@ -2090,7 +2090,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/* set value */
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &iChannel);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -2104,7 +2104,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
return 1;
} else {
/* request the value */
sprintf(pBueffel, "Integration Window = %d", self->iWindow);
snprintf(pBueffel,sizeof(pBueffel)-1, "Integration Window = %d", self->iWindow);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
@ -2128,7 +2128,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
case INTEGFUNNYBACK:
SCWrite(pCon, "WARNING: background asymmetric or worse", eWarning);
default:
sprintf(pBueffel, "Intensity = %f, Variance = %f", fSum, fVar);
snprintf(pBueffel,sizeof(pBueffel)-1, "Intensity = %f, Variance = %f", fSum, fVar);
SCWrite(pCon, pBueffel, eValue);
return 1;
break;
@ -2142,21 +2142,21 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
}
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[2], &x);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
fPos = x;
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[3], &x);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
FWHM = x;
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[4], &x);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -2189,13 +2189,13 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
}
iRet = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &i);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
iRet = Tcl_GetDouble(InterpGetTcl(pSics), argv[3], &fStep);
if (iRet != TCL_OK) {
sprintf(pBueffel, "ERROR: expected number, got %s", argv[3]);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: expected number, got %s", argv[3]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
@ -2211,7 +2211,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
return 0;
}
} else {
sprintf(pBueffel, "ERROR: %s not recognized as subcommand to %s",
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not recognized as subcommand to %s",
argv[1], argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;