From 8cc54743348608d227420418833605ec35f835f9 Mon Sep 17 00:00:00 2001 From: koennecke Date: Fri, 4 Dec 2009 12:58:31 +0000 Subject: [PATCH] - 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 --- SCinter.c | 95 ++++++++++++++++++------------- alias.c | 4 +- anticollider.c | 10 ++-- ascon.c | 5 ++ chadapter.c | 10 ++-- choco.c | 6 +- commandlog.c | 16 +++--- cone.c | 2 +- confvirtualmot.c | 2 +- conman.c | 22 +++---- counter.c | 28 ++++----- danu.c | 10 ++-- definealias.c | 2 +- devexec.c | 22 +++---- drive.c | 44 +++++++------- emon.c | 8 +-- evcontroller.c | 32 +++++------ exeman.c | 6 +- fitcenter.c | 16 +++--- fourmess.c | 2 +- frame.c | 8 +-- fupa.c | 8 +-- gpibcontroller.c | 16 +++--- histdriv.c | 2 +- histmem.c | 96 +++++++++++++++---------------- hkl.c | 42 +++++++------- hklscan.c | 48 ++++++++-------- hmcontrol.c | 12 ++-- hmdata.c | 12 ++-- ifile.c | 2 +- intcli.c | 2 +- lin2ang.c | 14 ++--- lomax.c | 52 ++++++++--------- macro.c | 18 +++--- maximize.c | 18 +++--- motor.c | 80 +++++++++++++------------- motorsec.c | 14 ++--- motreg.c | 2 +- multicounter.c | 8 +-- mumo.c | 62 ++++++++++---------- mumoconf.c | 16 +++--- nread.c | 14 ++--- nserver.c | 8 +-- nxscript.c | 116 ++++++++++++++++++------------------- nxutil.c | 20 +++---- o2t.c | 4 +- obpar.c | 6 +- ofac.c | 6 +- optimise.c | 48 ++++++++-------- perfmon.c | 6 +- protocol.c | 10 ++-- reflist.c | 2 +- rs232controller.c | 20 +++---- scan.c | 90 ++++++++++++++--------------- scanvar.c | 4 +- script.c | 22 +++---- sel2.c | 4 +- selector.c | 62 ++++++++++---------- selvar.c | 46 +++++++-------- servlog.c | 4 +- sicsdata.c | 2 +- sicvar.c | 34 +++++------ simchop.c | 12 ++-- sinqhmtcl.c | 20 +++---- splitter.c | 4 +- status.c | 4 +- statusfile.c | 8 +-- stdscan.c | 142 +++++++++++++++++++++++----------------------- synchronize.c | 8 +-- tasdrive.c | 2 +- tasscanub.c | 38 ++++++------- tcldrivable.c | 4 +- tclev.c | 20 +++---- tclintimpl.c | 6 +- telnet.c | 10 ++-- token.c | 2 +- udpquieck.c | 2 +- varlog.c | 8 +-- velo.c | 70 +++++++++++------------ xytable.c | 18 +++--- 80 files changed, 899 insertions(+), 881 deletions(-) diff --git a/SCinter.c b/SCinter.c index dcec3d12..ad1d491b 100644 --- a/SCinter.c +++ b/SCinter.c @@ -120,7 +120,7 @@ int AddCommandWithFlag(SicsInterp * pInterp, char *pName, ObjectFunc pFunc, assert(pFunc); assert(pInterp); - strcpy(pBueffel, pName); + strncpy(pBueffel, pName,511); strtolower(pBueffel); RemoveAlias(&pInterp->AList, pBueffel); /* M.Z. */ if (FindCommand(pInterp, pBueffel) != NULL) { @@ -130,7 +130,7 @@ int AddCommandWithFlag(SicsInterp * pInterp, char *pName, ObjectFunc pFunc, /* new memory */ pNew = (CommandList *) malloc(sizeof(CommandList)); if (!pNew) { - sprintf(pBueffel, "Out of memory creating command - %s -", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "Out of memory creating command - %s -", pName); SICSLogWrite(pBueffel, eInternal); return 0; } @@ -198,7 +198,7 @@ int RemoveCommand(SicsInterp * pInterp, char *pName) assert(pInterp); assert(pName); - strcpy(pBueffel, pName); + strncpy(pBueffel, pName,255); strtolower(pBueffel); if (pInterp->iDeleting) { @@ -263,11 +263,11 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText) /* write info to Log */ if (pCon->sockHandle >= 0) { - sprintf(pBueffel, "Executing -> %s <- from socket %d", pText, + snprintf(pBueffel,1023, "Executing -> %s <- from socket %d", pText, pCon->sockHandle); SICSLogWrite(pBueffel, eCommand); } else { - sprintf(pBueffel, "Executing -> %s <- from dummy socket\n", pText); + snprintf(pBueffel,1023, "Executing -> %s <- from dummy socket\n", pText); SICSLogWrite(pBueffel, eCommand); } @@ -293,7 +293,7 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText) /* find it */ pCommand = FindCommand(self, argv[0]); if (!pCommand) { - sprintf(pBueffel, "ERROR: Object -> %s <- NOT found", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Object -> %s <- NOT found", argv[0]); SCWrite(pCon, pBueffel, eError); iRet = -1; goto deleteArgv; @@ -333,7 +333,7 @@ deleteArgv: CommandList *FindCommand(SicsInterp * self, char *pName) { CommandList *pCurrent = NULL; - char pBueffel[256], *pCmd; + char pBuffer[1024], *pCmd, *pBueffel = NULL; assert(self); @@ -341,7 +341,18 @@ CommandList *FindCommand(SicsInterp * self, char *pName) return NULL; } - strcpy(pBueffel, pName); + if(strlen(pName) > sizeof(pBuffer)){ + pBueffel = malloc((strlen(pName)+1)*sizeof(char)); + if(pBueffel == NULL){ + return NULL; + } + memset(pBueffel,0,strlen(pName)+1); + } else { + pBueffel = pBuffer; + } + + memset(pBueffel,0,1024); + strncpy(pBueffel, pName,1023); strtolower(pBueffel); pCmd = TranslateAlias(&self->AList, pBueffel); /* M.Z. */ @@ -350,11 +361,17 @@ CommandList *FindCommand(SicsInterp * self, char *pName) while (pCurrent) { if (pCurrent->pName != NULL) { if (strcmp(pCurrent->pName, pCmd) == 0) { /* M.Z. */ + if(pBueffel != pBuffer){ + free(pBueffel); + } return pCurrent; } } pCurrent = pCurrent->pNext; } + if(pBueffel != pBuffer){ + free(pBueffel); + } return NULL; } @@ -504,15 +521,15 @@ static void printAll(SicsInterp * pSics, SConnection * pCon) pCurrent = pSics->pCList; while (pCurrent) { if (iNum == 0) { - strcpy(pBueffel, pCurrent->pName); + strncpy(pBueffel, pCurrent->pName,255); iNum++; } else if (iNum < 4) { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); iNum++; } else { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); strcat(pBueffel, "\r\n"); SCWrite(pCon, pBueffel, eValue); iNum = 0; @@ -523,7 +540,7 @@ static void printAll(SicsInterp * pSics, SConnection * pCon) /* write final entries */ if (strlen(pBueffel) > 2) { - strcat(pBueffel, "\r\n"); + strncat(pBueffel, "\r\n",255); SCWrite(pCon, pBueffel, eValue); } } @@ -570,7 +587,7 @@ static void printAllTypes(SicsInterp * pSics, SConnection * pCon, pTest = (pDummy) pCurrent->pData; if (NULL != pTest->pDescriptor) { pType = pTest->pDescriptor->name; - strcpy(pType_lc, pType); + strncpy(pType_lc, pType,255); strtolower(pType_lc); LLDnodePtr2First(typeListID); @@ -585,7 +602,7 @@ static void printAllTypes(SicsInterp * pSics, SConnection * pCon, /* NB: First checked node is current node, then search to end of list */ if (0 != LLDnodeFind(typeListID, compareStringNode, (void *) pType)) { /* empty list or 'typename' not found */ - strcpy(pName_lc, pCurrent->pName); + strncpy(pName_lc, pCurrent->pName,255); strtolower(pName_lc); if ((0 == iFiltered) || ((1 == iFiltered) && (0 != strcmp(pType_lc, pName_lc)))) { /*ie Add if unfiltered or pass filter(name!=typename) */ LLDstringAdd(typeListID, pType); @@ -620,16 +637,16 @@ static void printInterface(SicsInterp * pSics, SConnection * pCon, int id) if (pObj != NULL) { if (pObj->GetInterface(pObj, id) != NULL) { if (iNum == 0) { - strcpy(pBueffel, pCurrent->pName); + strncpy(pBueffel, pCurrent->pName,255); iNum++; } else if (iNum < 4) { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); iNum++; } else { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); - strcat(pBueffel, "\r\n"); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); + strncat(pBueffel, "\r\n",255); SCWrite(pCon, pBueffel, eValue); iNum = 0; pBueffel[0] = '\0'; @@ -666,16 +683,16 @@ static void printMatch(SicsInterp * pSics, SConnection * pCon, char *mask) if (pObj != NULL) { if (!match(mask, pObj->name)) { if (iNum == 0) { - strcpy(pBueffel, pCurrent->pName); + strncpy(pBueffel, pCurrent->pName,255); iNum++; } else if (iNum < 4) { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); iNum++; } else { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); - strcat(pBueffel, "\r\n"); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); + strncat(pBueffel, "\r\n",255); SCWrite(pCon, pBueffel, eValue); pBueffel[0] = '\0'; iNum = 0; @@ -686,7 +703,7 @@ static void printMatch(SicsInterp * pSics, SConnection * pCon, char *mask) } /* write final entries */ - strcat(pBueffel, "\r\n"); + strncat(pBueffel, "\r\n",255); SCWrite(pCon, pBueffel, eValue); } @@ -711,16 +728,16 @@ static void printType(SicsInterp * pSics, SConnection * pCon, if (pCurrent->pData != NULL) { if (iHasType(pCurrent->pData, typeName)) { if (iNum == 0) { - strcpy(pBueffel, pCurrent->pName); + strncpy(pBueffel, pCurrent->pName,255); iNum++; } else if (iNum < 4) { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); iNum++; } else { - strcat(pBueffel, " "); - strcat(pBueffel, pCurrent->pName); - strcat(pBueffel, "\r\n"); + strncat(pBueffel, " ",255); + strncat(pBueffel, pCurrent->pName,255); + strncat(pBueffel, "\r\n",255); Tcl_DStringAppend(&txt, pBueffel, -1); pBueffel[0] = '\0'; iNum = 0; @@ -731,7 +748,7 @@ static void printType(SicsInterp * pSics, SConnection * pCon, } /* write final entries */ - strcat(pBueffel, "\r\n"); + strncat(pBueffel, "\r\n",255); SCWrite(pCon, Tcl_DStringValue(&txt), eValue); Tcl_DStringFree(&txt); } @@ -814,12 +831,12 @@ int ListObjects(SConnection * pCon, SicsInterp * pSics, void *pData, printAllTypes(pSics, pCon, 0); return 1; } - strcpy(pType, argv[2]); + strncpy(pType, argv[2],255); /* Cater for multi-word types eg 'Environment Monitor' */ if (argc > 3) { for (i = 3; i < argc; i++) { - strcat(pType, " "); - strcat(pType, argv[i]); + strncat(pType, " ",255); + strncat(pType, argv[i],255); } } printType(pSics, pCon, pType); diff --git a/alias.c b/alias.c index f5e26762..188312a4 100644 --- a/alias.c +++ b/alias.c @@ -69,7 +69,7 @@ int SicsAlias(SConnection * pCon, SicsInterp * pSics, void *pData, /* first parameter should be an registered SICS object */ pCom = FindCommand(pSics, argv[1]); if (!pCom) { - sprintf(pBueffel, "ERROR: cannot find %s, no alias created", argv[1]); + snprintf(pBueffel,255, "ERROR: cannot find %s, no alias created", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -77,7 +77,7 @@ int SicsAlias(SConnection * pCon, SicsInterp * pSics, void *pData, /* alright: create the alias */ iRet = AddCommand(pSics, argv[2], pCom->OFunc, NULL, pCom->pData); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[2]); + snprintf(pBueffel,255, "ERROR: duplicate command %s not created", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/anticollider.c b/anticollider.c index f4f3dd46..5e4cbee6 100644 --- a/anticollider.c +++ b/anticollider.c @@ -118,7 +118,7 @@ static long ColliderSetValue(void *pData, SConnection * pCon, if (iRet != TCL_OK) { SCWrite(pCon, "ERROR: Movement not possible or bad collider script", eError); - SCWrite(pCon, Tcl_DStringValue(&command), eError); + SCPrintf(pCon,eError, "%s returned %s", Tcl_DStringValue(&command), Tcl_GetStringResult(pServ->pSics->pTcl)); /* SCWrite(pCon,pServ->pSics->pTcl->result,eError); */ @@ -213,7 +213,7 @@ int StartLevel(int level, int sequenceList, int motorList, */ count++; } else { - sprintf(pBueffel, + snprintf(pBueffel,131, "ERROR: motor %s, requested from anticollider script", seq.pMotor); SCWrite(pCon, pBueffel, eError); @@ -236,7 +236,7 @@ static void ListSequence(int sequenceList, SConnection * pCon) iRet = LLDnodePtr2First(sequenceList); while (iRet != 0) { LLDnodeDataTo(sequenceList, &seq); - sprintf(pBueffel, "%d %s %f", seq.level, seq.pMotor, seq.target); + snprintf(pBueffel,131, "%d %s %f", seq.level, seq.pMotor, seq.target); SCWrite(pCon, pBueffel, eValue); iRet = LLDnodePtr2Next(sequenceList); } @@ -371,7 +371,7 @@ int AntiColliderAction(SConnection * pCon, SicsInterp * pSics, return 0; } if (FindDrivable(pSics, argv[2]) == NULL) { - sprintf(pBueffel, "ERROR: %s is NOT drivable, cannot register", + snprintf(pBueffel,255, "ERROR: %s is NOT drivable, cannot register", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; @@ -389,7 +389,7 @@ int AntiColliderAction(SConnection * pCon, SicsInterp * pSics, } else if (strcmp(argv[1], "add") == 0) { if (argc < 5) { SCWrite(pCon, - "ERROR: InsUfficient number of arguments to anticollicion add", + "ERROR: Insufficient number of arguments to anticollicion add", eError); return 0; } diff --git a/ascon.c b/ascon.c index 9150c21b..6269a356 100644 --- a/ascon.c +++ b/ascon.c @@ -439,6 +439,11 @@ int AsconStdHandler(Ascon * a) a->state = AsconWriteDone; return 1; } + if(a->lineCount == 0){ + a->noResponse = 1; + } else { + a->noResponse = 0; + } break; /* go to the base handler */ case AsconReading: if (a->lineCount == 0) { diff --git a/chadapter.c b/chadapter.c index f4dd8738..6de4efd7 100644 --- a/chadapter.c +++ b/chadapter.c @@ -110,7 +110,7 @@ static int CHStatus(void *pData, SConnection * pCon) case HWFault: self->pDriv->GetError(self->pDriv, &iCode, pBueffel, 79); iRet = self->pDriv->TryFixIt(self->pDriv, iCode); - sprintf(pError, "ERROR: %s", pBueffel); + snprintf(pError,131, "ERROR: %s", pBueffel); SCWrite(pCon, pError, eError); if (iRet == CHFAIL || iRetry >= 3) { iRetry = 0; @@ -213,7 +213,7 @@ int CHAdapterFactory(SConnection * pCon, SicsInterp * pSics, void *pData, } } if (!pChopper) { - sprintf(pBueffel, "ERROR: %s is NO chopper controller", argv[3]); + snprintf(pBueffel,255, "ERROR: %s is NO chopper controller", argv[3]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -221,7 +221,7 @@ int CHAdapterFactory(SConnection * pCon, SicsInterp * pSics, void *pData, /* interpret limits */ iRet = Tcl_GetDouble(pSics->pTcl, argv[5], &dUpper); if (iRet != TCL_OK) { - sprintf(pBueffel, + snprintf(pBueffel,255, "ERROR: expected numeric argument for upper limit, got %s", argv[4]); SCWrite(pCon, pBueffel, eError); @@ -229,7 +229,7 @@ int CHAdapterFactory(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetDouble(pSics->pTcl, argv[4], &dLower); if (iRet != TCL_OK) { - sprintf(pBueffel, + snprintf(pBueffel,255, "ERROR: expected numeric argument for lower limit, got %s", argv[5]); SCWrite(pCon, pBueffel, eError); @@ -267,7 +267,7 @@ int CHAdapterFactory(SConnection * pCon, SicsInterp * pSics, void *pData, /* install command */ iRet = AddCommand(pSics, argv[1], CHAdapterAction, KillAdapter, pNew); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,255, "ERROR: duplicate ChopperAdapter command %s NOT created", argv[1]); SCWrite(pCon, pBueffel, eError); diff --git a/choco.c b/choco.c index 6007e2fa..4fba277f 100644 --- a/choco.c +++ b/choco.c @@ -94,7 +94,7 @@ int ChocoAction(SConnection * pCon, SicsInterp * pSics, void *pData, assert(self); if (argc < 2) { - sprintf(pMessage, "ERROR: argument required for %s", argv[0]); + snprintf(pMessage,255, "ERROR: argument required for %s", argv[0]); SCWrite(pCon, pMessage, eError); return 0; } @@ -192,7 +192,7 @@ int ChocoFactory(SConnection * pCon, SicsInterp * pSics, void *pData, pDriv = NULL; } if (pDriv == NULL) { - sprintf(pBueffel, + snprintf(pBueffel,131, "ERROR: Driver %s NOT supported for MakeController", argv[2]); SCWrite(pCon, pBueffel, eError); @@ -217,7 +217,7 @@ int ChocoFactory(SConnection * pCon, SicsInterp * pSics, void *pData, /* install as command */ iRet = AddCommand(pSics, argv[1], ChocoAction, KillChoco, pNew); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s NOT created", argv[1]); + snprintf(pBueffel, 131, "ERROR: duplicate command %s NOT created", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/commandlog.c b/commandlog.c index 08f239bc..25ee4552 100644 --- a/commandlog.c +++ b/commandlog.c @@ -291,7 +291,7 @@ static void AutoLog(void) CLFormatTime(pTime, 79); /* build file name */ - sprintf(pBueffel, "%s/auto%s.log", pPtr, pTime); + snprintf(pBueffel,1024, "%s/auto%s.log", pPtr, pTime); /* open file */ fauto = fopen(pBueffel, "w"); @@ -302,7 +302,7 @@ static void AutoLog(void) /* write the instrument name to it for identification */ pInst = FindVariable(pServ->pSics, "instrument"); if (pInst) { - sprintf(pBueffel, "Logfile started at instrument %s at %s", + snprintf(pBueffel,1024, "Logfile started at instrument %s at %s", pInst->text, pTime); WriteToCommandLog("SYS>>", pBueffel); } @@ -317,7 +317,7 @@ static void AutoLog(void) } SCnoSock(pIntern); SCSetRights(pIntern, usUser); - sprintf(pBueffel, "fileeval %s", pPtr); + snprintf(pBueffel,1024, "fileeval %s", pPtr); InterpExecute(pServ->pSics, pIntern, pBueffel); SCDeleteConnection(pIntern); } @@ -448,19 +448,19 @@ int CommandLog(SConnection * pCon, SicsInterp * pSics, void *pData, pPtr = IFindOption(pSICSOptions, "LogFileDir"); if (!pPtr) { SCWrite(pCon, "WARNING: no log file directory specified", eWarning); - sprintf(pBueffel, "%s", argv[2]); + snprintf(pBueffel,1023, "%s", argv[2]); } else { - sprintf(pBueffel, "%s/%s", pPtr, argv[2]); + snprintf(pBueffel,1023, "%s/%s", pPtr, argv[2]); } fd = fopen(pBueffel, "w"); if (!fd) { - sprintf(pBueffel, "ERROR: cannot open %s/%s for writing", pPtr, + snprintf(pBueffel,1023, "ERROR: cannot open %s/%s for writing", pPtr, argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } - strcpy(pFile, argv[2]); + strncpy(pFile, argv[2],255); SCSendOK(pCon); return 1; } else if (strcmp(argv[1], "auto") == 0) { @@ -498,7 +498,7 @@ int CommandLog(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } - sprintf(pBueffel, "ERROR: subcommand %s to commandlog unknown", argv[1]); + snprintf(pBueffel, 1024,"ERROR: subcommand %s to commandlog unknown", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/cone.c b/cone.c index 8a70c103..e895f738 100644 --- a/cone.c +++ b/cone.c @@ -292,7 +292,7 @@ int MakeCone(SConnection * pCon, SicsInterp * pSics, void *pData, int argc, pHdb cmd; if (argc > 1) { - strcpy(pName, argv[1]); + strncpy(pName, argv[1],80); } else { strcpy(pName, "cone"); } diff --git a/confvirtualmot.c b/confvirtualmot.c index bca60967..8fc28115 100644 --- a/confvirtualmot.c +++ b/confvirtualmot.c @@ -585,7 +585,7 @@ int ConfigurableVirtualMotorAction(SConnection * pCon, SicsInterp * pSics, pRegInfo->pCon = SCCopyConnection(pCon); value = ConfGetValue(self, pCon); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,511, "Failed to register interest, Reason:Error obtaining current position for %s", argv[0]); SCWrite(pCon, pBueffel, eError); diff --git a/conman.c b/conman.c index 9ff958c5..2340c219 100644 --- a/conman.c +++ b/conman.c @@ -1421,7 +1421,7 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, /* check no of args */ if (argc < 2) { - sprintf(pBueffel, "Insufficient number of args to %s", argv[0]); + snprintf(pBueffel,511, "Insufficient number of args to %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1435,7 +1435,7 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, SCWrite(pCon, pBueffel, eValue); return 1; } else if (strcmp(argv[1], "myname") == 0) { - sprintf(pBueffel, "MyName = %s", ConName(pCon->ident)); + snprintf(pBueffel,511, "MyName = %s", ConName(pCon->ident)); SCWrite(pCon, pBueffel, eValue); return 1; } else if (strcmp(argv[1], "myrights") == 0) { @@ -1464,7 +1464,7 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, /* check no or args */ if (argc < 3) { - sprintf(pBueffel, "Insufficient number of args to %s", argv[0]); + snprintf(pBueffel,511, "Insufficient number of args to %s", argv[0]); SCWrite(pCon, pBueffel, eInError); return 0; } @@ -1479,7 +1479,7 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, i++; } if (i > iNoCodes) { - sprintf(pBueffel, "OutCode %s not recognized", argv[2]); + snprintf(pBueffel,511, "OutCode %s not recognized", argv[2]); SCWrite(pCon, pBueffel, eInError); return 0; } @@ -1506,13 +1506,13 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, return 1; } else if (strcmp(argv[1], "rights") == 0) { if (argc < 4) { - sprintf(pBueffel, "Insufficient number of args to %s", argv[0]); + snprintf(pBueffel,511, "Insufficient number of args to %s", argv[0]); SCWrite(pCon, pBueffel, eInError); return 0; } i = IsValidUser(argv[2], argv[3]); if (i < 0) { - sprintf(pBueffel, + snprintf(pBueffel,511, " %s with password ****** is NO valid User on SICS", argv[2]); SCWrite(pCon, pBueffel, eError); @@ -1527,7 +1527,7 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, WriteToCommandLogId("SYS>", pCon->sockHandle, pBueffel); } } else { - sprintf(pBueffel, "User %s handle %d switched to %d privilege", + snprintf(pBueffel, 511, "User %s handle %d switched to %d privilege", argv[2], pCon->sockHandle, i); WriteToCommandLog("SYS>", pBueffel); } @@ -1722,7 +1722,7 @@ int ConSicsAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* get object */ pCom = FindCommand(pSics, argv[2]); if (!pCom) { - sprintf(pBueffel, "ERROR: object %s NOT found", argv[2]); + snprintf(pBueffel,1024, "ERROR: object %s NOT found", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1733,7 +1733,7 @@ int ConSicsAction(SConnection * pCon, SicsInterp * pSics, void *pData, pInterface = (pICallBack) pDum->pDescriptor->GetInterface(pDum, CALLBACKINTERFACE); if (!pInterface) { - sprintf(pBueffel, "ERROR: %s does not support CallBacks", argv[2]); + snprintf(pBueffel,1023, "ERROR: %s does not support CallBacks", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1741,7 +1741,7 @@ int ConSicsAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* get Event */ iEvent = Text2Event(argv[3]); if (iEvent < 0) { - sprintf(pBueffel, "ERROR: Unknown event code %s", argv[3]); + snprintf(pBueffel,1023, "ERROR: Unknown event code %s", argv[3]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1855,7 +1855,7 @@ int SCTaskFunction(void *pData) } } else { ANETinfo(self->sockHandle, pHost, 131); - sprintf(pBueffel, + snprintf(pBueffel, 511, "Accepted connection %s on socket %d from %s", ConName(self->ident), self->sockHandle, pHost); SICSLogWrite(pBueffel, eInternal); diff --git a/counter.c b/counter.c index a5201971..c5bd53c4 100644 --- a/counter.c +++ b/counter.c @@ -268,23 +268,19 @@ static int CheckCountStatus(void *pData, SConnection * pCon) static int SaveCounterStatus(void *pData, char *name, FILE * fd) { pCounter self = NULL; - char pBueffel[512]; assert(pData); assert(fd); self = (pCounter) pData; - sprintf(pBueffel, "# Counter %s\n", name); - fputs(pBueffel, fd); - sprintf(pBueffel, "%s SetPreset %f\n", name, self->pDriv->fPreset); - fputs(pBueffel, fd); + fprintf(fd, "# Counter %s\n", name); + fprintf(fd, "%s SetPreset %f\n", name, self->pDriv->fPreset); if (self->pDriv->eMode == eTimer) { - sprintf(pBueffel, "%s SetMode Timer\n", name); + fprintf(fd, "%s SetMode Timer\n", name); } else { - sprintf(pBueffel, "%s SetMode Monitor\n", name); + fprintf(fd, "%s SetMode Monitor\n", name); } - fputs(pBueffel, fd); return 1; } @@ -475,7 +471,7 @@ int MakeCounter(SConnection * pCon, SicsInterp * pSics, void *pData, } if (!pDriv) { - sprintf(pBueffel, "ERROR: cannot create requested driver %s", argv[2]); + snprintf(pBueffel,255, "ERROR: cannot create requested driver %s", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -483,7 +479,7 @@ int MakeCounter(SConnection * pCon, SicsInterp * pSics, void *pData, /* create Counter and command */ pNew = CreateCounter(argv[1], pDriv); if (!pNew) { - sprintf(pBueffel, "ERROR: cannot create counter %s", argv[1]); + snprintf(pBueffel, 255,"ERROR: cannot create counter %s", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -491,7 +487,7 @@ int MakeCounter(SConnection * pCon, SicsInterp * pSics, void *pData, AddCommand(pSics, argv[1], CountAction, DeleteCounter, (void *) pNew); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[1]); + snprintf(pBueffel,255, "ERROR: duplicate command %s not created", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -693,7 +689,7 @@ static int CounterInterest(int iEvent, void *pEvent, void *pUser) pMon = (pMonEvent) pEvent; assert(pCon); assert(pMon); - sprintf(pBueffel, "%s.CountStatus = %f %d", pMon->pName, pMon->fPreset, + snprintf(pBueffel,511, "%s.CountStatus = %f %d", pMon->pName, pMon->fPreset, (int) nintf(pMon->fCurrent)); /** * prevent this to be written to log files @@ -814,7 +810,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, EvaluateFuPa((pFuncTemplate) & ActionTemplate, 23, argc - 1, argx, &PaRes); if (iRet < 0) { - sprintf(pBueffel, "%s", PaRes.pError); + snprintf(pBueffel, 255,"%s", PaRes.pError); SCWrite(pCon, pBueffel, eError); return 0; } @@ -872,7 +868,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBueffel, "ERROR: %s not recognized as valid counter mode", + snprintf(pBueffel,255, "ERROR: %s not recognized as valid counter mode", PaRes.Arg[0].text); SCWrite(pCon, pBueffel, eError); return 0; @@ -1014,7 +1010,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBueffel, + snprintf(pBueffel,255, "ERROR: %s not recognized as valid counter mode", PaRes.Arg[0].text); SCWrite(pCon, pBueffel, eError); @@ -1101,7 +1097,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = self->pDriv->Get(self->pDriv, PaRes.Arg[0].text, PaRes.Arg[1].iVal, &fVal); if (iRet == 1) { - sprintf(pBueffel, "%s.%s %d = %f", argv[0], PaRes.Arg[0].text, + snprintf(pBueffel,255, "%s.%s %d = %f", argv[0], PaRes.Arg[0].text, PaRes.Arg[1].iVal, fVal); SCWrite(pCon, pBueffel, eValue); return 1; diff --git a/danu.c b/danu.c index b67a19be..8354ccd8 100644 --- a/danu.c +++ b/danu.c @@ -89,7 +89,7 @@ static int writeDataNumber(pDataNumber self, int iNum) fprintf(fd, " %d \n", iNum); fprintf(fd, "NEVER, EVER modify or delete this file\n"); fprintf(fd, - "You'll risk eternal damnation and a reincarnation as a cockroach!|n"); + "You'll risk eternal damnation and a reincarnation as a cockroach!\n"); fclose(fd); return 1; } @@ -278,7 +278,7 @@ int DNWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, if (argc < 2) { /* value request */ iNum = readDataNumber(self); if (iNum < 0) { - sprintf(pBueffel, "ERROR: cannot open file %s", self->pFileName); + snprintf(pBueffel,511, "ERROR: cannot open file %s", self->pFileName); SCWrite(pCon, pBueffel, eError); return 0; } @@ -324,7 +324,7 @@ int DNWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); } - sprintf(pBueffel, "ERROR: unknown command %s supplied to %s", + snprintf(pBueffel,511, "ERROR: unknown command %s supplied to %s", argv[1], argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -377,13 +377,13 @@ int DNFactory(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = AddCommand(pSics, argv[1], DNWrapper, DeleteDataNumber, self); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[1]); + snprintf(pBueffel, 511,"ERROR: duplicate command %s not created", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = AddCommand(pSics, "killfile", DEWrapper, NULL, self); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[1]); + snprintf(pBueffel, 511,"ERROR: duplicate command %s not created", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/definealias.c b/definealias.c index a9a61e7b..defec4eb 100644 --- a/definealias.c +++ b/definealias.c @@ -190,7 +190,7 @@ int DefineAlias(pSConnection pCon, SicsInterp * pSics, void *pData, pErr = CreateAlias(&pSics->AList, argv[1], argv[2]); if (pErr != NULL) { - sprintf(pBueffel, "ERROR: %s", pErr); + snprintf(pBueffel,255, "ERROR: %s", pErr); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/devexec.c b/devexec.c index bb6ee0b0..adef7f69 100644 --- a/devexec.c +++ b/devexec.c @@ -84,7 +84,7 @@ int openDevexecLog() if (devLog == NULL) { fileName = IFindOption(pSICSOptions, "devexeclog"); if (fileName != NULL) { - strcpy(fileBuffer, fileName); + strncpy(fileBuffer, fileName,1024); } else { iDate = time(NULL); psTime = localtime(&iDate); @@ -370,7 +370,7 @@ int StartDevice(pExeList self, char *name, pObjectDescriptor pDes, DevexecLog("START", pNew->name); return 1; } else { - sprintf(pBueffel, "ERROR: cannot start device %s", name); + snprintf(pBueffel,131, "ERROR: cannot start device %s", name); SCWrite(pCon, pBueffel, eError); DeleteDevEntry(pNew); if (LLDcheck(self->iList) >= LIST_EMPTY) { @@ -398,25 +398,25 @@ int StartMotor(pExeList self, SicsInterp * pSics, SConnection * pCon, pCom = FindCommand(pSics, name); if (!pCom) { - sprintf(pBueffel, "ERROR: cannot find motor %s", name); + snprintf(pBueffel,255, "ERROR: cannot find motor %s", name); SCWrite(pCon, pBueffel, eError); return 0; } pMot = (pDummy) pCom->pData; if (!pMot) { - sprintf(pBueffel, "ERROR: %s is no motor ", name); + snprintf(pBueffel,255, "ERROR: %s is no motor ", name); SCWrite(pCon, pBueffel, eError); return 0; } if (!pMot->pDescriptor) { - sprintf(pBueffel, "ERROR: cannot find motor %s", name); + snprintf(pBueffel,255, "ERROR: cannot find motor %s", name); SCWrite(pCon, pBueffel, eError); return 0; } if (!pMot->pDescriptor->GetInterface(pMot, DRIVEID)) { - sprintf(pBueffel, "ERROR: %s is no motor", name); + snprintf(pBueffel, 255, "ERROR: %s is no motor", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -438,25 +438,25 @@ int StartCounter(pExeList self, SicsInterp * pSics, SConnection * pCon, pCom = FindCommand(pSics, name); if (!pCom) { - sprintf(pBueffel, "ERROR: cannot find counter %s", name); + snprintf(pBueffel,255, "ERROR: cannot find counter %s", name); SCWrite(pCon, pBueffel, eError); return 0; } pCter = (pCounter) pCom->pData; if (!pCter) { - sprintf(pBueffel, "ERROR: %s is no counter ", name); + snprintf(pBueffel,255, "ERROR: %s is no counter ", name); SCWrite(pCon, pBueffel, eError); return 0; } if (!pCter->pDes) { - sprintf(pBueffel, "ERROR: cannot find counter %s", name); + snprintf(pBueffel, 255, "ERROR: cannot find counter %s", name); SCWrite(pCon, pBueffel, eError); return 0; } if (!pCter->pDes->GetInterface(pCter, COUNTID)) { - sprintf(pBueffel, "ERROR: %s is no counter", name); + snprintf(pBueffel,255, "ERROR: %s is no counter", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1000,7 +1000,7 @@ int StopCommand(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = StopExe(self, argv[1]); if (!iRet) { - sprintf(pBueffel, "ERROR: %s not found, so could not halt", argv[1]); + snprintf(pBueffel,131, "ERROR: %s not found, so could not halt", argv[1]); SCWrite(pCon, pBueffel, eError); } return iRet; diff --git a/drive.c b/drive.c index 1a76b9ac..6dd77dc3 100644 --- a/drive.c +++ b/drive.c @@ -66,7 +66,7 @@ int Drive(SConnection * pCon, SicsInterp * pInter, char *name, float fNew) /* check if user is allowed to drive */ if (!SCMatchRights(pCon, usUser)) { - sprintf(pBueffel, "Insuficient Privilege to drive %s", name); + snprintf(pBueffel, 511, "Insuficient Privilege to drive %s", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -74,7 +74,7 @@ int Drive(SConnection * pCon, SicsInterp * pInter, char *name, float fNew) /* first try to find the thing to drive */ pObject = FindCommand(pInter, name); if (!pObject) { - sprintf(pBueffel, "Cannot find %s to drive ", name); + snprintf(pBueffel,511, "Cannot find %s to drive ", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -85,7 +85,7 @@ int Drive(SConnection * pCon, SicsInterp * pInter, char *name, float fNew) pDum = (Dummy *) pObject->pData; pDes = pDum->pDescriptor; if (!pDes) { - sprintf(pBueffel, "%s is NOT drivable!", pDes->name); + snprintf(pBueffel,511, "%s is NOT drivable!", pDes->name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -96,7 +96,7 @@ int Drive(SConnection * pCon, SicsInterp * pInter, char *name, float fNew) pInt = pDes->GetInterface(pDum, DRIVEID); if (!pInt) { - sprintf(pBueffel, "%s is NOT drivable!", pDes->name); + snprintf(pBueffel,511, "%s is NOT drivable!", pDes->name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -109,7 +109,7 @@ int Drive(SConnection * pCon, SicsInterp * pInter, char *name, float fNew) } iRet = StartDevice(GetExecutor(), name, pDes, pDum, pCon, RUNDRIVE, fNew); if (!iRet) { - sprintf(pBueffel, "ERROR: cannot start device %s", name); + snprintf(pBueffel,511, "ERROR: cannot start device %s", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -120,23 +120,23 @@ int Drive(SConnection * pCon, SicsInterp * pInter, char *name, float fNew) if (iRet == DEVINT) { if (SCGetInterrupt(pCon) == eAbortOperation) { SCSetInterrupt(pCon, eContinue); - sprintf(pBueffel, "Driving %s aborted at %9.3f", name, fPos); + snprintf(pBueffel, 511, "Driving %s aborted at %9.3f", name, fPos); SCWrite(pCon, pBueffel, eError); } return 0; } else if (iRet == DEVDONE) { - sprintf(pBueffel, "Driving %s to %9.3f done", name, fPos); + snprintf(pBueffel, 511, "Driving %s to %9.3f done", name, fPos); SCWrite(pCon, pBueffel, eValue); return 1; } else { - sprintf(pBueffel, + snprintf(pBueffel, 511, "Driving %s finished with problems, position: %9.3f", name, fPos); SCWrite(pCon, pBueffel, eValue); return 1; } } - sprintf(pBueffel, "%s is NOT drivable", pDes->name); + snprintf(pBueffel, 511, "%s is NOT drivable", pDes->name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -159,7 +159,7 @@ int Start2Run(SConnection * pCon, SicsInterp * pInter, char *name, /* check if user is allowed to drive */ if (!SCMatchRights(pCon, usUser)) { - sprintf(pBueffel, "Insuficient Privilege to drive %s", name); + snprintf(pBueffel,511, "Insuficient Privilege to drive %s", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -167,7 +167,7 @@ int Start2Run(SConnection * pCon, SicsInterp * pInter, char *name, /* first try to find the thing to drive */ pObject = FindCommand(pInter, name); if (!pObject) { - sprintf(pBueffel, "Cannot find %s to drive ", name); + snprintf(pBueffel,511, "Cannot find %s to drive ", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -178,7 +178,7 @@ int Start2Run(SConnection * pCon, SicsInterp * pInter, char *name, pDum = (Dummy *) pObject->pData; pDes = pDum->pDescriptor; if (!pDes) { - sprintf(pBueffel, "%s is NOT drivable!", pDes->name); + snprintf(pBueffel,511, "%s is NOT drivable!", pDes->name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -188,7 +188,7 @@ int Start2Run(SConnection * pCon, SicsInterp * pInter, char *name, */ pInt = pDes->GetInterface(pDum, DRIVEID); if (!pInt) { - sprintf(pBueffel, "%s is NOT drivable!", pDes->name); + snprintf(pBueffel,511, "%s is NOT drivable!", pDes->name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -206,7 +206,7 @@ int Start2Run(SConnection * pCon, SicsInterp * pInter, char *name, return 1; } } else { - sprintf(pBueffel, "%s is NOT drivable", pDes->name); + snprintf(pBueffel,511, "%s is NOT drivable", pDes->name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -251,7 +251,7 @@ static float findPosition(SicsInterp * pSics, SConnection * pCon, if (pDes) { pInt = pDes->GetInterface(pDum, DRIVEID); if (!pInt) { - sprintf(pBueffel, + snprintf(pBueffel,131, "ERROR: internal error in findPosition for %s", name); SCWrite(pCon, pBueffel, eError); return -999.99; @@ -285,7 +285,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, argtolower(argc, argv); /* check no of args */ if (argc < 3) { - sprintf(pBueffel, "Insufficient number of args. Usage %s name val", + snprintf(pBueffel, 511,"Insufficient number of args. Usage %s name val", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -303,7 +303,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, SetStatus(eDriving); for (i = 1; i < argc; i += 2) { if (argv[i + 1] == NULL) { - sprintf(pBueffel, "ERROR: no value found for driving %s", argv[i]); + snprintf(pBueffel, 511, "ERROR: no value found for driving %s", argv[i]); SCWrite(pCon, pBueffel, eError); SetStatus(eOld); return 0; @@ -317,7 +317,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Start2Run(pCon, pSics, argv[i], RUNDRIVE, dTarget); if (!iRet) { - sprintf(pBueffel, "ERROR: cannot run %s to %s", argv[i], + snprintf(pBueffel, 511,"ERROR: cannot run %s to %s", argv[i], argv[i + 1]); SCWrite(pCon, pBueffel, eError); StopExe(GetExecutor(), "ALL"); @@ -331,7 +331,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, /* print positions */ for (i = 1; i < argc; i += 2) { - sprintf(pBueffel, "New %s position: %9.3f", argv[i], + snprintf(pBueffel,511, "New %s position: %9.3f", argv[i], findPosition(pSics, pCon, argv[i])); SCWrite(pCon, pBueffel, eValue); } @@ -377,7 +377,7 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, /* check no of args */ if (argc < 3) { - sprintf(pBueffel, "Insufficient number of args. Usage %s name val", + snprintf(pBueffel,511, "Insufficient number of args. Usage %s name val", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -395,7 +395,7 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, SetStatus(eDriving); for (i = 1; i < argc; i += 2) { if (argv[i + 1] == NULL) { - sprintf(pBueffel, "ERROR: no value found for driving %s", argv[i]); + snprintf(pBueffel,511, "ERROR: no value found for driving %s", argv[i]); SCWrite(pCon, pBueffel, eError); SetStatus(eOld); return 0; @@ -409,7 +409,7 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Start2Run(pCon, pSics, argv[i], RUNRUN, dTarget); if (!iRet) { - sprintf(pBueffel, "ERROR: cannot run %s to %s", argv[i], + snprintf(pBueffel, 511, "ERROR: cannot run %s to %s", argv[i], argv[i + 1]); SCWrite(pCon, pBueffel, eError); StopExe(GetExecutor(), "ALL"); diff --git a/emon.c b/emon.c index 41df1127..ea604516 100644 --- a/emon.c +++ b/emon.c @@ -117,7 +117,7 @@ int EVRegisterController(pEnvMon self, char *pName, void *pData, sEntry.pInter = sEntry.pDum->pDescriptor->GetInterface(pData, ENVIRINTERFACE); if (sEntry.pInter == NULL) { - sprintf(pBueffel, + snprintf(pBueffel,511, "ERROR: cannot register %s, no environment interface", pName); SCWrite(pCon, pBueffel, eError); return 0; @@ -283,7 +283,7 @@ int EVWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } pCom = FindCommand(pSics, argv[2]); if (!pCom) { - sprintf(pBueffel, "ERROR: object %s not found, not registered", + snprintf(pBueffel,511, "ERROR: object %s not found, not registered", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; @@ -302,12 +302,12 @@ int EVWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = EVUnregister(self, argv[2]); if (!iRet) { - sprintf(pBueffel, "WARNING: %s not found in emon", argv[2]); + snprintf(pBueffel,511, "WARNING: %s not found in emon", argv[2]); SCWrite(pCon, pBueffel, eWarning); } return 1; } else { - sprintf(pBueffel, "ERROR: %s not recognized as command to emon", + snprintf(pBueffel, 511, "ERROR: %s not recognized as command to emon", argv[1]); SCWrite(pCon, pBueffel, eError); } diff --git a/evcontroller.c b/evcontroller.c index 20244410..c6d405c2 100644 --- a/evcontroller.c +++ b/evcontroller.c @@ -244,7 +244,7 @@ static int EVIStatus(void *pData, SConnection * pCon) } if (fPos < -990.) { - sprintf(pBueffel, "ERROR: %s cannot read its current value", + snprintf(pBueffel, 255, "ERROR: %s cannot read its current value", self->pName); SCWrite(pCon, pBueffel, eError); self->eMode = EVIdle; @@ -268,7 +268,7 @@ static int EVIStatus(void *pData, SConnection * pCon) tmo = (int) (ObVal(self->pParam, MAXWAIT)); /* based on this: logic ! */ if (tmo > 0 && now > self->start + tmo) { /* time out */ - sprintf(pBueffel, "ERROR: wait time limit reached on %s", self->pName); + snprintf(pBueffel,255, "ERROR: wait time limit reached on %s", self->pName); SCWrite(pCon, pBueffel, eError); self->eMode = EVMonitor; notifyStatus(self, pCon, HWIdle); @@ -283,7 +283,7 @@ static int EVIStatus(void *pData, SConnection * pCon) if (self->lastt <= 0) { /* lastt negative: -seconds already waited */ self->lastt += now; if (tmo > 0) { - sprintf(pBueffel, "%s inside tolerance, wait %.2f sec to settle", + snprintf(pBueffel,255, "%s inside tolerance, wait %.2f sec to settle", self->pName, (self->lastt + tmo - now) * 1.0); SCWrite(pCon, pBueffel, eLog); } @@ -300,7 +300,7 @@ static int EVIStatus(void *pData, SConnection * pCon) } else { if (self->lastt > 0) { /* save time already waited */ if (tmo > 0) { - sprintf(pBueffel, "%s outside tolerance, settling time suspended", + snprintf(pBueffel,255, "%s outside tolerance, settling time suspended", self->pName); SCWrite(pCon, pBueffel, eLog); } @@ -379,7 +379,7 @@ static void ErrReport(pEVControl self) self->pDriv->GetValues(self->pDriv, &self->fTarget, &fPos, &fDelta); if (self->iWarned == 0) { - sprintf(pBueffel, "WARNING: %s is out of range by %g", + snprintf(pBueffel, 255,"WARNING: %s is out of range by %g", self->pName, fDelta); ErrWrite(pBueffel, self->conn); self->iWarned = 1; @@ -586,7 +586,7 @@ static int EVIIsInTolerance(void *pData) if (fDelta <= tol) { self->eMode = EVMonitor; if (self->iWarned) { - sprintf(pBueffel, "Environment device %s back in tolerances again", + snprintf(pBueffel,255, "Environment device %s back in tolerances again", self->pName); ErrWrite(pBueffel, self->conn); self->iWarned = 0; @@ -598,7 +598,7 @@ static int EVIIsInTolerance(void *pData) /* deal with callbacks */ self->callCount++; if (self->callCount >= 20) { - sprintf(pBueffel, "%s = %g", self->pName, fPos); + snprintf(pBueffel,255, "%s = %g", self->pName, fPos); InvokeCallBack(self->pCall, VALUECHANGE, pBueffel); self->callCount = 0; } @@ -842,7 +842,7 @@ int EVCDrive(pEVControl self, SConnection * pCon, float fVal) iRet = StartDevice(GetExecutor(), self->pName, self->pDes, self, pCon, pCon->runLevel, fVal); if (!iRet) { - sprintf(pBueffel, "ERROR: Failure to start %s", self->pName); + snprintf(pBueffel,255, "ERROR: Failure to start %s", self->pName); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1154,11 +1154,11 @@ int EVControlWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = EVCGetPar(self, argv[1], &fPos); if (!iRet) { - sprintf(pBueffel, "ERROR: parameter %s NOT found", argv[1]); + snprintf(pBueffel,255, "ERROR: parameter %s NOT found", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } else { - sprintf(pBueffel, "%s.%s = %g", self->pName, argv[1], fPos); + snprintf(pBueffel,255, "%s.%s = %g", self->pName, argv[1], fPos); SCWrite(pCon, pBueffel, eValue); return 1; } @@ -1196,7 +1196,7 @@ int EVControlWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: %s no valid number", argv[2]); + snprintf(pBueffel, 255,"ERROR: %s no valid number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1385,7 +1385,7 @@ static pEVControl InstallCommonControllers(SicsInterp * pSics, /* install command */ iRet = AddCommand(pSics, argv[2], Wrapper, DeleteEVController, pNew); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[2]); + snprintf(pBueffel,511, "ERROR: duplicate command %s not created", argv[2]); DeleteEVController((void *) pNew); SCWrite(pCon, pBueffel, eError); return NULL; @@ -1408,7 +1408,7 @@ int RemoveEVController(SConnection * pCon, char *name) EVUnregister(FindEMON(pServ->pSics), name); iRet = RemoveCommand(pServ->pSics, name); if (!iRet) { - sprintf(pBueffel, "ERROR: %s not found, NOT deleted", name); + snprintf(pBueffel,511, "ERROR: %s not found, NOT deleted", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1474,7 +1474,7 @@ int EVControlFactory(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } } else { - sprintf(pBueffel, + snprintf(pBueffel, 511, "ERROR: environment device %s already installed, delete first", argv[2]); SCWrite(pCon, pBueffel, eError); @@ -1483,7 +1483,7 @@ int EVControlFactory(SConnection * pCon, SicsInterp * pSics, void *pData, } pCom = FindCommand(pSics, argv[2]); if (pCom) { - sprintf(pBueffel, "ERROR: command %s already exists", argv[2]); + snprintf(pBueffel,511, "ERROR: command %s already exists", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1493,7 +1493,7 @@ int EVControlFactory(SConnection * pCon, SicsInterp * pSics, void *pData, if (site != NULL) { pNew = site->InstallEnvironmentController(pSics, pCon, argc, argv); } else { - sprintf(pBueffel, + snprintf(pBueffel,511, "ERROR: %s not recognized as a valid driver type", argv[3]); SCWrite(pCon, pBueffel, eError); diff --git a/exeman.c b/exeman.c index b74ca142..2ab45540 100644 --- a/exeman.c +++ b/exeman.c @@ -438,7 +438,7 @@ static int runHdbBuffer(pExeMan self, SConnection * pCon, * prepare context */ conCon = SCCopyConnection(pCon); - strcpy(conCon->deviceID, pBueffel); + strncpy(conCon->deviceID, pBueffel,255); /* * load commands into buffer @@ -749,8 +749,8 @@ static int uploadForceSave(pExeMan self, SConnection * pCon, pPtr = self->batchPath; pPtr = stptok(pPtr, pPath, 131, ":"); if (strlen(pPath) + 1 + strlen(argv[2]) <= 256) { - strcat(pPath, "/"); - strcat(pPath, argv[2]); + strncat(pPath, "/",255); + strncat(pPath, argv[2],255); } else { strncpy(pPath, argv[2], 255); } diff --git a/fitcenter.c b/fitcenter.c index b325f97f..fd4b2981 100644 --- a/fitcenter.c +++ b/fitcenter.c @@ -339,18 +339,18 @@ int FitFactory(SConnection * pCon, SicsInterp * pSics, void *pData, pCom = FindCommand(pSics, argv[1]); if (!pCom) { - sprintf(pBueffel, "ERROR: scan command %s not found", argv[1]); + snprintf(pBueffel,sizeof(pBueffel), "ERROR: scan command %s not found", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } pDum = (pDummy) pCom->pData; if (!pDum) { - sprintf(pBueffel, "ERROR: scan command %s not found", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: scan command %s not found", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } if (strcmp(pDum->pDescriptor->name, "ScanObject") != 0) { - sprintf(pBueffel, "ERROR: %s is no scan command", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no scan command", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -366,7 +366,7 @@ int FitFactory(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = AddCommand(pSics, "peak", FitWrapper, DeleteFitCenter, self); iRet1 = AddCommand(pSics, "center", CenterWrapper, NULL, self); if (!iRet || !iRet1) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate commands peak and center not created"); SCWrite(pCon, pBueffel, eError); DeleteFitCenter((void *) self); @@ -423,7 +423,7 @@ int FitWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, if (argc > 1) { strtolower(argv[1]); if (strcmp(argv[1], "value") == 0) { - sprintf(pBueffel, "%f", self->fCenter); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", self->fCenter); SCWrite(pCon, pBueffel, eValue); return 1; } @@ -437,12 +437,12 @@ int FitWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, /* print results */ SCStartBuffering(pCon); - sprintf(pBueffel, "Estimated Peak Center: %f, StdDev: %f \n", + snprintf(pBueffel,sizeof(pBueffel)-1, "Estimated Peak Center: %f, StdDev: %f \n", self->fCenter, self->fStddev); SCWrite(pCon, pBueffel, eValue); - sprintf(pBueffel, "Maximum peak height: %ld\n", self->lPeak); + snprintf(pBueffel,sizeof(pBueffel)-1, "Maximum peak height: %ld\n", self->lPeak); SCWrite(pCon, pBueffel, eValue); - sprintf(pBueffel, "Approximate FWHM: %f\n", self->FWHM); + snprintf(pBueffel,sizeof(pBueffel)-1, "Approximate FWHM: %f\n", self->FWHM); SCWrite(pCon, pBueffel, eValue); buf = SCEndBuffering(pCon); if (buf != NULL) { diff --git a/fourmess.c b/fourmess.c index f50221d6..4c41ac18 100644 --- a/fourmess.c +++ b/fourmess.c @@ -126,7 +126,7 @@ static int FourMessStart(pSICSOBJ self, SConnection * pCon, pHdb commandNode, pHdb par[], int nPar) { pFourMess priv = NULL; - char pFilename[512], pRoot[512]; + char pFilename[1024], pRoot[512]; char pBueffel[1024]; double lambda; const double *dUB; diff --git a/frame.c b/frame.c index d9fa9a6b..bef62cba 100644 --- a/frame.c +++ b/frame.c @@ -137,13 +137,13 @@ static int readFileFrame(SConnection * pCon, status = NXopen(file, NXACC_READ, &fileHandle); if (status != NX_OK) { - sprintf(error, "ERROR: failed to open %s", file); + snprintf(error,sizeof(error)-1, "ERROR: failed to open %s", file); SCWrite(pCon, error, eError); return 0; } status = NXDinitfromfile(dictFile, &dictHandle); if (status != NX_OK) { - sprintf(error, "ERROR: failed to open dictionary %s", dictFile); + snprintf(error,sizeof(error)-1, "ERROR: failed to open dictionary %s", dictFile); NXclose(&fileHandle); SCWrite(pCon, error, eError); return 0; @@ -151,7 +151,7 @@ static int readFileFrame(SConnection * pCon, status = NXDopenalias(fileHandle, dictHandle, alias); if (status != NX_OK) { - sprintf(error, "ERROR: failed to open alias %s", alias); + snprintf(error,sizeof(error)-1, "ERROR: failed to open alias %s", alias); NXclose(&fileHandle); NXDclose(dictHandle, NULL); SCWrite(pCon, error, eError); @@ -162,7 +162,7 @@ static int readFileFrame(SConnection * pCon, if (type != NX_INT32 && type != NX_UINT32) type = -1; if (status != NX_OK || rank < 2 || type < 0) { - sprintf(error, "ERROR: Dataset does not match!"); + snprintf(error,sizeof(error)-1, "ERROR: Dataset does not match!"); NXclose(&fileHandle); NXDclose(dictHandle, NULL); SCWrite(pCon, error, eError); diff --git a/fupa.c b/fupa.c index 3db9b62c..6d4221cf 100644 --- a/fupa.c +++ b/fupa.c @@ -70,7 +70,7 @@ int EvaluateFuPa(pFuncTemplate pTemplate, int iFunc, int argc, } } if (iRet == -1) { - sprintf(pRes->pError, "ERROR: function %s not available", + snprintf(pRes->pError,sizeof(pRes->pError)-1, "ERROR: function %s not available", pCurrent->text); goto end; } @@ -85,7 +85,7 @@ int EvaluateFuPa(pFuncTemplate pTemplate, int iFunc, int argc, pRes->Arg[i].iVal = 0; goto end; } else { - sprintf(pRes->pError, + snprintf(pRes->pError,sizeof(pRes->pError)-1, "ERROR: Insufficient number of arguments to %s", pTemplate[iRet].name); iRet = -1; @@ -119,7 +119,7 @@ int EvaluateFuPa(pFuncTemplate pTemplate, int iFunc, int argc, pRes->Arg[i].iVal = (int) pCurrent->fVal; continue; } else { - sprintf(pRes->pError, "ERROR: expected integer parameter, got %s", + snprintf(pRes->pError,sizeof(pRes->pError)-1, "ERROR: expected integer parameter, got %s", pCurrent->text); iRet = -1; goto end; @@ -135,7 +135,7 @@ int EvaluateFuPa(pFuncTemplate pTemplate, int iFunc, int argc, pRes->Arg[i].fVal = pCurrent->fVal; continue; } else { - sprintf(pRes->pError, "ERROR: expected float parameter, got %s", + snprintf(pRes->pError,sizeof(pRes->pError)-1, "ERROR: expected float parameter, got %s", pCurrent->text); iRet = -1; goto end; diff --git a/gpibcontroller.c b/gpibcontroller.c index 769b9ad2..eeefb1b4 100644 --- a/gpibcontroller.c +++ b/gpibcontroller.c @@ -175,11 +175,11 @@ int GPIBAction(SConnection * pCon, SicsInterp * pSics, void *pData, status = GPIBattach(self, boardID, address, secondaryAddress, tmo, eot, eoi); if (status > 0) { - sprintf(pBuffer, "%d", status); + snprintf(pBuffer,sizeof(pBuffer)-1, "%d", status); SCWrite(pCon, pBuffer, eValue); return 1; } else { - sprintf(pBuffer, "ERROR: error %d on attach", status); + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: error %d on attach", status); SCWrite(pCon, pBuffer, eError); return 0; } @@ -202,7 +202,7 @@ int GPIBAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBuffer, "ERROR: error %d on dettach", status); + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: error %d on dettach", status); SCWrite(pCon, pBuffer, eError); return 0; } @@ -243,7 +243,7 @@ int GPIBAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBuffer, "ERROR: error %d on send", status); + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: error %d on send", status); SCWrite(pCon, pBuffer, eError); return 0; } @@ -274,7 +274,7 @@ int GPIBAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBuffer, "ERROR: error %d on send", status); + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: error %d on send", status); SCWrite(pCon, pBuffer, eError); return 0; } @@ -297,7 +297,7 @@ int GPIBAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCWrite(pCon, pBuffer, eValue); return 1; } else { - sprintf(pBuffer, "ERROR: error %d on read", status); + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: error %d on read", status); SCWrite(pCon, pBuffer, eError); return 0; } @@ -317,12 +317,12 @@ int GPIBAction(SConnection * pCon, SicsInterp * pSics, void *pData, } status = GPIBread(self, devID, &value, 4); if (status > 0) { - sprintf(pBuffer, "gpib %d = %d", devID, value); + snprintf(pBuffer,sizeof(pBuffer)-1, "gpib %d = %d", devID, value); SCWrite(pCon, pBuffer, eValue); return 1; } else { /* - sprintf(pBuffer,"ERROR: error %d on read", status); + snprintf(pBuffer,sizeof(pBuffer)-1,"ERROR: error %d on read", status); SCWrite(pCon,pBuffer,eError); */ return 0; diff --git a/histdriv.c b/histdriv.c index b227a742..e9f81763 100644 --- a/histdriv.c +++ b/histdriv.c @@ -72,7 +72,7 @@ pHistDriver CreateHistDriver(pStringDict pOption) /* initialise defaults */ StringDictAddPair(pOption, "rank", "1"); for (i = 0; i < MAXDIM; i++) { - sprintf(pDim, "dim%1.1d", i); + snprintf(pDim,sizeof(pDim)-1, "dim%1.1d", i); StringDictAddPair(pOption, pDim, "-126"); } pNew->fCountPreset = 10.; diff --git a/histmem.c b/histmem.c index 83f46a2c..166b8e34 100644 --- a/histmem.c +++ b/histmem.c @@ -191,7 +191,7 @@ static int HistStartCount(void *pData, SConnection * pCon) return iRet; } else { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "WARNING: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s ", pError); SCWrite(pCon, pBueffel, eLogError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -233,7 +233,7 @@ static int HistPause(void *pData, SConnection * pCon) return iRet; } else { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "WARNING: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s ", pError); SCWrite(pCon, pBueffel, eError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -275,7 +275,7 @@ static int HistContinue(void *pData, SConnection * pCon) return iRet; } else { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "WARNING: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s ", pError); SCWrite(pCon, pBueffel, eError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -313,7 +313,7 @@ static int HistCountStatus(void *pData, SConnection * pCon) eCt = self->pDriv->GetCountStatus(self->pDriv, pCon); if (eCt == HWFault) { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "WARNING: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s ", pError); SCWrite(pCon, pBueffel, eError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -370,7 +370,7 @@ static int HistTransfer(void *pData, SConnection * pCon) iStatus = iRet; } else { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "WARNING: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s ", pError); SCWrite(pCon, pBueffel, eError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -514,7 +514,7 @@ int MakeHistMemory(SConnection * pCon, SicsInterp * pSics, void *pData, /* check no of arguments */ if (argc < 3) { - sprintf(pBueffel, "ERROR: insufficient no of arguments to %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient no of arguments to %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -524,7 +524,7 @@ int MakeHistMemory(SConnection * pCon, SicsInterp * pSics, void *pData, strtolower(argv[2]); pNew = CreateHistMemory(argv[2]); if (!pNew) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to create Histogram Memory %s, driver %s may be invalid or no memory", argv[1], argv[2]); SCWrite(pCon, pBueffel, eError); @@ -538,7 +538,7 @@ int MakeHistMemory(SConnection * pCon, SicsInterp * pSics, void *pData, AddCommand(pSics, argv[1], HistAction, DeleteHistMemory, (void *) 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); DeleteHistMemory((void *) pNew); return 0; @@ -793,7 +793,7 @@ int SetHistogram(pHistMem self, SConnection * pCon, return 1; } else { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "ERROR: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s ", pError); SCWrite(pCon, pBueffel, eError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -849,7 +849,7 @@ int GetHistogramDirect(pHistMem self, SConnection * pCon, break; } else { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "ERROR: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s ", pError); SCWrite(pCon, pBueffel, eError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -895,7 +895,7 @@ int PresetHistogram(pHistMem self, SConnection * pCon, HistInt lVal) return 1; } else { iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "ERROR: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s ", pError); SCWrite(pCon, pBueffel, eError); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); if (iRet == COTERM) { @@ -974,31 +974,31 @@ void HMListOption(pHistMem self, SConnection * pCon) StringDictGet(self->pDriv->pOption, "driver", pValue, sizeof(pValue) - 1); if (0 < iRet) { - sprintf(pBuffer, "%s.driver = %s", name, pValue); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.driver = %s", name, pValue); SCWrite(pCon, pBuffer, eValue); } iRet = StringDictGetAsNumber(self->pDriv->pOption, "update", &fVal); if (0 < iRet) { - sprintf(pBuffer, "%s.update = %d", name, (int) rint(fVal)); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.update = %d", name, (int) rint(fVal)); } else { - sprintf(pBuffer, "%s.update = 0 (no buffering)", name); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.update = 0 (no buffering)", name); } SCWrite(pCon, pBuffer, eValue); iRet = StringDictGetAsNumber(self->pDriv->pOption, "rank", &fVal); if (0 < iRet) { iRank = (int) rint(fVal); - sprintf(pBuffer, "%s.rank = %d", name, iRank); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.rank = %d", name, iRank); SCWrite(pCon, pBuffer, eValue); } else { iRank = 0; } for (i = 0; i < iRank; i++) { - sprintf(pValue, "dim%1.1d", i); + snprintf(pValue,sizeof(pValue)-1, "dim%1.1d", i); iRet = StringDictGetAsNumber(self->pDriv->pOption, pValue, &fVal); if (0 < iRet) { - sprintf(pBuffer, "%s.dim%1.1d = %d", name, i, (int) rint(fVal)); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.dim%1.1d = %d", name, i, (int) rint(fVal)); SCWrite(pCon, pBuffer, eValue); } } @@ -1027,11 +1027,11 @@ void HMListOption(pHistMem self, SConnection * pCon) } /* Display Count Mode */ - sprintf(pBuffer, "%s.CountMode = %s", name, pMode[self->pDriv->eCount]); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.CountMode = %s", name, pMode[self->pDriv->eCount]); SCWrite(pCon, pBuffer, eValue); /* Display Preset */ - sprintf(pBuffer, "%s.preset = %f", name, self->pDriv->fCountPreset); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.preset = %f", name, self->pDriv->fCountPreset); SCWrite(pCon, pBuffer, eValue); if (self->pDriv->data->nTimeChan > 2) { @@ -1039,7 +1039,7 @@ void HMListOption(pHistMem self, SConnection * pCon) } else { tofMode = 0; } - sprintf(pBuffer, "%s.tofMode = %d", name, tofMode); + snprintf(pBuffer,sizeof(pBuffer)-1, "%s.tofMode = %d", name, tofMode); SCWrite(pCon, pBuffer, eValue); buf = SCEndBuffering(pCon); if (buf != NULL) { @@ -1116,7 +1116,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* check arguments */ if (argc < 2) { - sprintf(pBueffel, "ERROR: no arguments specified to %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: no arguments specified to %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1136,7 +1136,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* enough arguments ? */ if (argc < 4) { if (argc < 3) { - sprintf(pBueffel, "ERROR: not enough arguments to %s configure", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: not enough arguments to %s configure", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -1145,7 +1145,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, strtolower(argv[2]); iRet = HistGetOption(self, argv[2], NULL, 0); if (!iRet) { - sprintf(pBueffel, "ERROR: option %s not known", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: option %s not known", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1156,7 +1156,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } memset(pBuf, 0, iRet + 60); HistGetOption(self, argv[2], pBuf, iRet + 60); - sprintf(pBueffel, "%s.%s = %s", argv[0], argv[2], pBuf); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %s", argv[0], argv[2], pBuf); SCWrite(pCon, pBueffel, eValue); free(pBuf); return 1; @@ -1166,7 +1166,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, Arg2Text(argc - 3, &argv[3], pBueffel, 511); /* authorise */ if (!SCMatchRights(pCon, usMugger)) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: you need to be manager in order to configure %s", argv[0]); SCWrite(pCon, pBueffel, eError); @@ -1175,7 +1175,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, strtolower(argv[2]); iRet = HistSetOption(self, argv[2], pBueffel); if (!iRet) { - sprintf(pBueffel, "ERROR: option %s not known", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: option %s not known", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1184,7 +1184,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } else if (strcmp(argv[1], "preset") == 0) { /* preset */ if (argc < 3) { /* get value */ fVal = GetHistPreset(self); - sprintf(pBueffel, "%s.preset = %f", argv[0], fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.preset = %f", argv[0], fVal); SCWrite(pCon, pBueffel, eValue); return 1; } else { /* set case */ @@ -1205,7 +1205,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } } else if (strcmp(argv[1], "exponent") == 0) { /* preset */ if (argc < 3) { /* get value */ - sprintf(pBueffel, "%s.exponent = %d", argv[0], self->iExponent); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.exponent = %d", argv[0], self->iExponent); SCWrite(pCon, pBueffel, eValue); return 1; } else { /* set case */ @@ -1221,7 +1221,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } else if (strcmp(argv[1], "countmode") == 0) { /* countmode */ if (argc < 3) { /* get value */ eCount = GetHistCountMode(self); - sprintf(pBueffel, "%s.CountMode = %s", argv[0], pMode[eCount]); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.CountMode = %s", argv[0], pMode[eCount]); SCWrite(pCon, pBueffel, eValue); return 1; } else { /* set case */ @@ -1240,7 +1240,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } else if (strcmp(argv[2], "monitor") == 0) { eCount = ePreset; } else { - sprintf(pBueffel, "ERROR: %s invalid as CountMode", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s invalid as CountMode", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1336,7 +1336,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* enough arguments */ if (argc < 3) { - sprintf(pBueffel, "ERROR: insufficient number of arguments to %s %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s %s", argv[0], argv[1]); SCWrite(pCon, pBueffel, eError); return 0; @@ -1355,7 +1355,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* enough arguments */ if (argc < 3) { - sprintf(pBueffel, "ERROR: insufficient number of arguments to %s %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s %s", argv[0], argv[1]); SCWrite(pCon, pBueffel, eError); return 0; @@ -1370,7 +1370,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } else if (strcmp(argv[1], "get") == 0) { /* get a histogram */ /* check parameters, first required: no of Hist */ if (argc < 3) { - sprintf(pBueffel, "ERROR: insufficient number of arguments to %s %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s %s", argv[0], argv[1]); SCWrite(pCon, pBueffel, eError); return 0; @@ -1415,7 +1415,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, lData, iEnd * sizeof(long)); } if (!iRet) { - sprintf(pBueffel, "ERROR: cannot retrieve histogram %d", iNum); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot retrieve histogram %d", iNum); SCWrite(pCon, pBueffel, eError); free(lData); return 0; @@ -1425,7 +1425,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, Tcl_DStringInit(&tResult); Tcl_DStringAppend(&tResult, "Histogram =", -1); for (i = 0; i < iEnd - iStart; i++) { - sprintf(pNumber, " %d", lData[i]); + snprintf(pNumber,sizeof(pNumber)-1, " %d", lData[i]); Tcl_DStringAppend(&tResult, pNumber, -1); } @@ -1441,7 +1441,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, else if (strcmp(argv[1], "uuget") == 0) { /* get a histogram */ /* check parameters, first required: no of Hist */ if (argc < 3) { - sprintf(pBueffel, "ERROR: insufficient number of arguments to %s %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s %s", argv[0], argv[1]); SCWrite(pCon, pBueffel, eError); return 0; @@ -1477,7 +1477,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = GetHistogram(self, pCon, iNum, iStart, iEnd, &lData[1], iEnd * sizeof(HistInt)); if (!iRet) { - sprintf(pBueffel, "ERROR: cannot retrieve histogram %d", iNum); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot retrieve histogram %d", iNum); SCWrite(pCon, pBueffel, eError); free(lData); return 0; @@ -1499,7 +1499,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } else if (strcmp(argv[1], "zipget") == 0) { /* get a histogram */ /* check parameters, first required: no of Hist */ if (argc < 3) { - sprintf(pBueffel, "ERROR: insufficient number of arguments to %s %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s %s", argv[0], argv[1]); SCWrite(pCon, pBueffel, eError); return 0; @@ -1535,7 +1535,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = GetHistogram(self, pCon, iNum, iStart, iEnd, &lData[0], iEnd * sizeof(HistInt)); if (!iRet) { - sprintf(pBueffel, "ERROR: cannot retrieve histogram %d", iNum); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot retrieve histogram %d", iNum); SCWrite(pCon, pBueffel, eError); free(lData); return 0; @@ -1554,7 +1554,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } /* retrive no of Timebins */ else if (strcmp(argv[1], "notimebin") == 0) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.notimebin = %d", argv[0], getNoOfTimebins(self->pDriv->data)); SCWrite(pCon, pBueffel, eValue); @@ -1565,7 +1565,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, Tcl_DStringInit(&tResult); Tcl_DStringAppend(&tResult, "histogram.timebins =", -1); for (i = 0; i < self->pDriv->data->nTimeChan; i++) { - sprintf(pBueffel, "%.2f ", self->pDriv->data->timeBinning[i]); + snprintf(pBueffel,sizeof(pBueffel)-1, "%.2f ", self->pDriv->data->timeBinning[i]); Tcl_DStringAppend(&tResult, pBueffel, -1); } /* Write it */ @@ -1614,19 +1614,19 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dStart); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: Failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = Tcl_GetDouble(pSics->pTcl, argv[3], &dStep); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: Failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = Tcl_GetInt(pSics->pTcl, argv[4], &iNum); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: Failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1662,13 +1662,13 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iNum); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: Failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = Tcl_GetDouble(pSics->pTcl, argv[3], &dStep); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: Failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1718,11 +1718,11 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData, } } lVal = HistSum(self, pCon, iaStart, iaEnd); - sprintf(pBueffel, "%s.sum = %ld", argv[0], lVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.sum = %ld", argv[0], lVal); SCWrite(pCon, pBueffel, eValue); return 1; } else { - sprintf(pBueffel, "ERROR: %s does not understand command %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s does not understand command %s", argv[0], argv[1]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/hkl.c b/hkl.c index 0071e1c3..82c74d60 100644 --- a/hkl.c +++ b/hkl.c @@ -427,7 +427,7 @@ int CalculateSettings(pHKL self, float fHKL[3], float fPsi, int iHamil, } if (!status) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot calculate %4.1f %4.1f %4.1f, psi = %4.1f", fHKL[0], fHKL[1], fHKL[2], dHkl[3]); SCWrite(pCon, pBueffel, eError); @@ -687,7 +687,7 @@ static int GetCommandData(int argc, char *argv[], float fHKL[3], /* get the reflection */ for (i = 0; i < 3; i++) { if (!isNumeric(argv[i])) { - sprintf(pBueffel, "ERROR: %s is NOT recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is NOT recognized as a number", argv[i]); SCWrite(pCon, pBueffel, eError); return 0; @@ -701,7 +701,7 @@ static int GetCommandData(int argc, char *argv[], float fHKL[3], /* has psi been specicifed ? */ if (argc > 3) { if (!isNumeric(argv[3])) { - sprintf(pBueffel, "ERROR: %s is NOT recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is NOT recognized as a number", argv[3]); SCWrite(pCon, pBueffel, eError); } @@ -711,7 +711,7 @@ static int GetCommandData(int argc, char *argv[], float fHKL[3], /* has iHamil been specified ? */ if (argc > 4) { if (!isNumeric(argv[4])) { - sprintf(pBueffel, "ERROR: %s is NOT recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is NOT recognized as a number", argv[4]); SCWrite(pCon, pBueffel, eError); } @@ -829,19 +829,19 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, /*-------- handle list */ strtolower(argv[1]); if (strcmp(argv[1], "list") == 0) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "lambda = %f Normal Beam = %d Quadrant = %d HM = %d", SXGetLambda(), self->iNOR, self->iQuad, self->iHM); SCWrite(pCon, pBueffel, eValue); dUB = SXGetUB(); - sprintf(pBueffel, "UB = { %f %f %f", dUB[0], dUB[1], dUB[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "UB = { %f %f %f", dUB[0], dUB[1], dUB[2]); SCWrite(pCon, pBueffel, eValue); - sprintf(pBueffel, " %f %f %f", dUB[3], dUB[4], dUB[5]); + snprintf(pBueffel,sizeof(pBueffel)-1, " %f %f %f", dUB[3], dUB[4], dUB[5]); SCWrite(pCon, pBueffel, eValue); - sprintf(pBueffel, " %f %f %f }", dUB[6], dUB[7], dUB[8]); + snprintf(pBueffel,sizeof(pBueffel)-1, " %f %f %f }", dUB[6], dUB[7], dUB[8]); SCWrite(pCon, pBueffel, eValue); return 1; - sprintf(pBueffel, "Last HKL: %f %f %f ", + snprintf(pBueffel,sizeof(pBueffel)-1, "Last HKL: %f %f %f ", self->fLastHKL[0], self->fLastHKL[1], self->fLastHKL[2]); SCWrite(pCon, pBueffel, eValue); snprintf(pBueffel, 510, "%s.scantolerance = %f", argv[0], @@ -852,7 +852,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, /*----------- current */ else if (strcmp(argv[1], "current") == 0) { GetHKLFromAngles(self, pCon, fHKL); - sprintf(pBueffel, "Current HKL: %8.4f %8.4f %8.4f ", + snprintf(pBueffel,sizeof(pBueffel)-1, "Current HKL: %8.4f %8.4f %8.4f ", fHKL[0], fHKL[1], fHKL[2]); SCWrite(pCon, pBueffel, eValue); return 1; @@ -877,7 +877,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, for (i = 0; i < 3; i++) { fHKL[i] = dHKL[i]; } - sprintf(pBueffel, "HKL from angles: %8.4f %8.4f %8.4f ", + snprintf(pBueffel,sizeof(pBueffel)-1, "HKL from angles: %8.4f %8.4f %8.4f ", fHKL[0], fHKL[1], fHKL[2]); SCWrite(pCon, pBueffel, eValue); return 1; @@ -909,7 +909,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, } for (i = 2; i < 11; i++) { if (!isNumeric(argv[i])) { - sprintf(pBueffel, "ERROR: %s was not recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s was not recognized as a number", argv[i]); SCWrite(pCon, pBueffel, eError); return 0; @@ -927,7 +927,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, /*------------- HM mode */ else if (strcmp(argv[1], "hm") == 0) { if (argc < 3) { - sprintf(pBueffel, "%s.hm = %d", argv[0], self->iHM); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.hm = %d", argv[0], self->iHM); SCWrite(pCon, pBueffel, eValue); return 1; } @@ -935,7 +935,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } if (!isNumeric(argv[2])) { - sprintf(pBueffel, "ERROR: %s was not recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s was not recognized as a number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; @@ -955,7 +955,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } if (!isNumeric(argv[2])) { - sprintf(pBueffel, "ERROR: %s was not recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s was not recognized as a number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; @@ -982,14 +982,14 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } if (!isNumeric(argv[2])) { - sprintf(pBueffel, "ERROR: %s was not recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s was not recognized as a number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = atoi(argv[2]); if (!((iRet == 1) || (iRet == 0))) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Invalid parameter %d for quadrant, posiible: 0,1", iRet); SCWrite(pCon, pBueffel, eError); @@ -1011,7 +1011,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } if (!isNumeric(argv[2])) { - sprintf(pBueffel, "ERROR: %s was not recognized as a number", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s was not recognized as a number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; @@ -1028,11 +1028,11 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = CalculateSettings(self, fHKL, fPsi, iHamil, fSet, pCon); if (SXGetMode() == NB) { - sprintf(pBueffel, " gamma = %f, omega = %f, nu = %f", + snprintf(pBueffel,sizeof(pBueffel)-1, " gamma = %f, omega = %f, nu = %f", fSet[0], fSet[1], fSet[2]); SCWrite(pCon, pBueffel, eValue); } else { - sprintf(pBueffel, " 2-theta = %f, omega = %f, chi = %f, phi = %f", + snprintf(pBueffel,sizeof(pBueffel)-1, " 2-theta = %f, omega = %f, chi = %f, phi = %f", fSet[0], fSet[1], fSet[2], fSet[3]); SCWrite(pCon, pBueffel, eValue); } @@ -1091,7 +1091,7 @@ int HKLAction(SConnection * pCon, SicsInterp * pSics, void *pData, else if (strcmp(argv[1], "bitonb") == 0) { return HandleBiToNB(pCon, argc, argv); } else { - sprintf(pBueffel, "ERROR: subcommand --> %s <-- not recognized", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: subcommand --> %s <-- not recognized", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/hklscan.c b/hklscan.c index a33e6f46..1df19925 100644 --- a/hklscan.c +++ b/hklscan.c @@ -71,7 +71,7 @@ int HklscanFactory(SConnection * pCon, SicsInterp * pSics, void *pData, /* find scan object */ pNew->pScan = (pScanData) FindCommandData(pSics, argv[1], "ScanObject"); if (!pNew->pScan) { - sprintf(pBueffel, "ERROR: %s not found or no scan object", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not found or no scan object", argv[1]); SCWrite(pCon, pBueffel, eError); KillHklscan(pNew); return 0; @@ -81,7 +81,7 @@ int HklscanFactory(SConnection * pCon, SicsInterp * pSics, void *pData, pNew->pCalc = (pHKL) FindCommandData(pSics, argv[2], "4-Circle-Calculus"); if (!pNew->pCalc) { - sprintf(pBueffel, "ERROR: %s not found or no HKL object", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not found or no HKL object", argv[2]); SCWrite(pCon, pBueffel, eError); KillHklscan(pNew); return 0; @@ -152,45 +152,45 @@ static int WriteHklscanPoint(pScanData self, int iPoint) } /* make the data header */ - sprintf(pLine, "%-5s", "NP"); - sprintf(pInfo, "Scanning Variables: H, K, L STEP: %8.3f %8.3f %8.3f", + snprintf(pLine,sizeof(pLine)-1, "%-5s", "NP"); + snprintf(pInfo,sizeof(pInfo)-1, "Scanning Variables: H, K, L STEP: %8.3f %8.3f %8.3f", pHaSca->fStep[0], pHaSca->fStep[1], pHaSca->fStep[2]); strcat(pLine, "H K L "); for (i = 0; i < self->iScanVar; i++) { DynarGet(self->pScanVar, i, &pPtr); pVar = (pVarEntry) pPtr; if (pVar) { - sprintf(pItem, "%-6.6s ", pVar->Name); + snprintf(pItem,sizeof(pItem)-1, "%-6.6s ", pVar->Name); strcat(pLine, pItem); } } strcat(pLine, "Counts "); strcat(pLine, " Monitor1 "); - sprintf(pItem, "\n%d Points,", self->iNP); + snprintf(pItem,sizeof(pItem)-1, "\n%d Points,", self->iNP); strcat(pInfo, pItem); if (self->iMode == eTimer) { strcat(pInfo, " Mode: Timer,"); } else { strcat(pInfo, " Mode: Monitor,"); } - sprintf(pItem, " Preset %f", self->fPreset); + snprintf(pItem,sizeof(pItem)-1, " Preset %f", self->fPreset); strcat(pInfo, pItem); fprintf(self->fd, "%s\n", pInfo); fprintf(self->fd, "%s\n", pLine); /* print an addon to the status line going to the screen */ - sprintf(pLine, "NP H K L "); + snprintf(pLine,sizeof(pLine)-1, "NP H K L "); SCWrite(self->pCon, pLine, eWarning); - sprintf(pLine, "%-5d%-8.4f%-8.4f%-8.4f ", iPoint, pHaSca->fPos[0], + snprintf(pLine,sizeof(pLine)-1, "%-5d%-8.4f%-8.4f%-8.4f ", iPoint, pHaSca->fPos[0], pHaSca->fPos[1], pHaSca->fPos[2]); SCWrite(self->pCon, pLine, eWarning); /* now the scan points */ for (i = 0; i < self->iCounts; i++) { - sprintf(pLine, "%-5d", i); + snprintf(pLine,sizeof(pLine)-1, "%-5d", i); /* print HKL */ for (i2 = 0; i2 < 3; i2++) { - sprintf(pItem, " %-8.4f", + snprintf(pItem,sizeof(pItem)-1, " %-8.4f", pHaSca->fStart[i2] + i * pHaSca->fStep[i2]); strcat(pLine, pItem); } @@ -199,7 +199,7 @@ static int WriteHklscanPoint(pScanData self, int iPoint) DynarGet(self->pScanVar, i2, &pPtr); pVar = (pVarEntry) pPtr; if (pVar) { - sprintf(pItem, " %-7.2f", GetScanVarPos(pVar, i)); + snprintf(pItem,sizeof(pItem)-1, " %-7.2f", GetScanVarPos(pVar, i)); strcat(pLine, pItem); } } @@ -207,9 +207,9 @@ static int WriteHklscanPoint(pScanData self, int iPoint) DynarGet(self->pCounts, i, &pPtr); pData = (pCountEntry) pPtr; if (pData) { - sprintf(pItem, " %-13ld", pData->lCount); + snprintf(pItem,sizeof(pItem)-1, " %-13ld", pData->lCount); strcat(pLine, pItem); - sprintf(pItem, " %-12ld", pData->Monitors[0]); + snprintf(pItem,sizeof(pItem)-1, " %-12ld", pData->Monitors[0]); strcat(pLine, pItem); } fprintf(self->fd, "%s\n", pLine); @@ -302,21 +302,21 @@ int HklscanAction(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } self->fStart[0] = (float) dVal; iRet = Tcl_GetDouble(pSics->pTcl, argv[3], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[3]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[3]); SCWrite(pCon, pBueffel, eError); return 0; } self->fStart[1] = (float) dVal; iRet = Tcl_GetDouble(pSics->pTcl, argv[4], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[4]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[4]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -334,21 +334,21 @@ int HklscanAction(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } self->fStep[0] = (float) dVal; iRet = Tcl_GetDouble(pSics->pTcl, argv[3], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[3]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[3]); SCWrite(pCon, pBueffel, eError); return 0; } self->fStep[1] = (float) dVal; iRet = Tcl_GetDouble(pSics->pTcl, argv[4], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[4]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[4]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -366,7 +366,7 @@ int HklscanAction(SConnection * pCon, SicsInterp * pSics, void *pData, } iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iNP); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -376,7 +376,7 @@ int HklscanAction(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; @@ -384,7 +384,7 @@ int HklscanAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* preset */ iRet = Tcl_GetDouble(pSics->pTcl, 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; } @@ -395,7 +395,7 @@ int HklscanAction(SConnection * pCon, SicsInterp * pSics, void *pData, } return iRet; } - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not recognized as command word to hklscan", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/hmcontrol.c b/hmcontrol.c index 522c6f91..a41067d4 100644 --- a/hmcontrol.c +++ b/hmcontrol.c @@ -161,7 +161,7 @@ static int HMCTransfer(void *pData, SConnection * pCon) status = self->slaves[i]->TransferData(self->slaveData[i], pCon); if (status != OKOK) { retVal = status; - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: slave histogram %d failed to transfer data", i); SCWrite(pCon, pBueffel, eWarning); } @@ -260,14 +260,14 @@ int MakeHMControl(SConnection * pCon, SicsInterp * pSics, for (i = 2; i < argc; i++) { pCom = FindCommand(pSics, argv[i]); if (!pCom) { - sprintf(pBueffel, "ERROR: object %s not found in MakeHMcontrol", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: object %s not found in MakeHMcontrol", argv[i]); SCWrite(pCon, pBueffel, eError); continue; } pCount = GetCountableInterface(pCom->pData); if (!pCount) { - sprintf(pBueffel, "ERROR: object %s is NOT countable", argv[i]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: object %s is NOT countable", argv[i]); SCWrite(pCon, pBueffel, eError); continue; } @@ -282,7 +282,7 @@ int MakeHMControl(SConnection * pCon, SicsInterp * pSics, status = AddCommand(pSics, argv[1], HMControlAction, KillHMcontrol, pNew); if (!status) { - 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); KillHMcontrol(pNew); return 0; @@ -320,7 +320,7 @@ int HMControlAction(SConnection * pCon, SicsInterp * pSics, */ status = Tcl_GetDouble(pSics->pTcl, argv[2], &dPreset); if (status != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -330,7 +330,7 @@ int HMControlAction(SConnection * pCon, SicsInterp * pSics, else if (strcmp(argv[3], "monitor") == 0) eMode = ePreset; else { - sprintf(pBueffel, "ERROR: %s is no recognized count mode", argv[3]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no recognized count mode", argv[3]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/hmdata.c b/hmdata.c index 98492105..6e326cdb 100644 --- a/hmdata.c +++ b/hmdata.c @@ -110,10 +110,10 @@ int configureHMdata(pHMdata self, pStringDict pOpt, SConnection * pCon) self->rank = (int) rint(fVal); for (i = 0; i < self->rank; i++) { - sprintf(pValue, "dim%1.1d", i); + snprintf(pValue,sizeof(pValue)-1, "dim%1.1d", i); status = StringDictGetAsNumber(pOpt, pValue, &fVal); if (!status) { - sprintf(pValue, "ERROR dimension %d not found!!", i); + snprintf(pValue,sizeof(pValue)-1, "ERROR dimension %d not found!!", i); return 0; } self->iDim[i] = (int) rint(fVal); @@ -304,7 +304,7 @@ static int updateHMbuffer(pHistMem hist, int bank, SConnection * pCon) break; } else { status = hist->pDriv->GetError(hist->pDriv, &iErr, pError, 79); - sprintf(pBueffel, "ERROR: %s ", pError); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s ", pError); SCWrite(pCon, pBueffel, eError); status = hist->pDriv->TryAndFixIt(hist->pDriv, iErr); if (status == COTERM) { @@ -416,13 +416,13 @@ long sumHMDataRectangle(pHistMem hist, SConnection * pCon, } for (i = 0; i < myrank; i++) { if ((iStart[i] < 0) || (iStart[i] > self->iDim[i])) { - sprintf(pBueffel, "ERROR: %d is out of data dimension range", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %d is out of data dimension range", iStart[i]); SCWrite(pCon, pBueffel, eError); return -1; } if ((iEnd[i] < 0) || (iEnd[i] > self->iDim[i])) { - sprintf(pBueffel, "ERROR: %d is out of data dimension range", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %d is out of data dimension range", iEnd[i]); SCWrite(pCon, pBueffel, eError); return -1; @@ -469,7 +469,7 @@ long sumHMDataRectangle(pHistMem hist, SConnection * pCon, } break; default: - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: summing in %d dimensions not yet implemented", myrank); SCWrite(pCon, pBueffel, eError); return -1; diff --git a/ifile.c b/ifile.c index 493b33e5..c54406e4 100644 --- a/ifile.c +++ b/ifile.c @@ -119,7 +119,7 @@ IPair *IFReadConfigFile(FILE * fd) iLen = pPos - pBueffel; strncpy(pName, pBueffel, iLen); pName[iLen] = '\0'; - strcpy(pValue, (pPos + 1)); + strncpy(pValue, (pPos + 1),131); RemoveWhiteSpace(pName); RemoveWhiteSpace(pValue); pList = CreateNewEntry(pName, pValue, pList); diff --git a/intcli.c b/intcli.c index 508eff89..f26a5607 100644 --- a/intcli.c +++ b/intcli.c @@ -74,6 +74,6 @@ void SendInterrupt(int iCode) return; } - sprintf(pBueffel, "SICSINT %d", iCode); + snprintf(pBueffel,sizeof(pBueffel)-1, "SICSINT %d", iCode); UDPWrite(pChannel, pBueffel, strlen(pBueffel)); } diff --git a/lin2ang.c b/lin2ang.c index 07b8d7d4..721d6f4d 100644 --- a/lin2ang.c +++ b/lin2ang.c @@ -193,7 +193,7 @@ int MakeLin2Ang(SConnection * pCon, SicsInterp * pSics, void *pData, /* check if we got a motor */ pNew->lin = FindMotor(pSics, argv[2]); if (!pNew->lin) { - sprintf(pBueffel, "ERROR: %s is no motor!", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no motor!", argv[2]); SCWrite(pCon, pBueffel, eError); KillL2A(pNew); return 0; @@ -213,7 +213,7 @@ int MakeLin2Ang(SConnection * pCon, SicsInterp * pSics, void *pData, /* install command */ iRet = AddCommand(pSics, argv[1], Lin2AngAction, KillL2A, pNew); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate Lin2Ang command %s NOT created", argv[1]); SCWrite(pCon, pBueffel, eError); KillL2A(pNew); @@ -239,7 +239,7 @@ int Lin2AngAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* without parameter: give value */ if (argc < 2) { fVal = L2AGetValue(self, pCon); - sprintf(pBueffel, "%s = %f", argv[0], fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %f", argv[0], fVal); SCWrite(pCon, pBueffel, eError); return 1; } @@ -263,7 +263,7 @@ int Lin2AngAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBueffel, "%s.length = %f", argv[0], self->length); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.length = %f", argv[0], self->length); SCWrite(pCon, pBueffel, eValue); return 1; } @@ -287,7 +287,7 @@ int Lin2AngAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBueffel, "%s.softzero = %f", argv[0], self->zero); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.softzero = %f", argv[0], self->zero); SCWrite(pCon, pBueffel, eValue); return 1; } @@ -298,12 +298,12 @@ int Lin2AngAction(SConnection * pCon, SicsInterp * pSics, void *pData, MotorGetPar(self->lin, "softlowerlim", &fLow); fHigh = x2ang(self, fHigh); fLow = x2ang(self, fLow); - sprintf(pBueffel, "%s.limits: %f %f\n change through motor limits ", + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.limits: %f %f\n change through motor limits ", argv[0], fLow, fHigh); SCWrite(pCon, pBueffel, eValue); return 1; } - sprintf(pBueffel, "ERROR: method %s not found!", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: method %s not found!", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/lomax.c b/lomax.c index 8017d3d6..5ca7999a 100644 --- a/lomax.c +++ b/lomax.c @@ -290,18 +290,18 @@ static int checkHM(pHistMem * pHM, SicsInterp * pSics, SConnection * pCon, pCom = FindCommand(pSics, name); if (!pCom) { - sprintf(pBueffel, "ERROR: histogram memory %s not found", name); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: histogram memory %s not found", name); SCWrite(pCon, pBueffel, eError); return 0; } if (!pCom->pData) { - sprintf(pBueffel, "ERROR: histogram memory %s not found", name); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: histogram memory %s not found", name); SCWrite(pCon, pBueffel, eError); return 0; } *pHM = (pHistMem) pCom->pData; if (!iHasType(*pHM, "HistMem")) { - sprintf(pBueffel, "ERROR: %s is no histogram memory!", name); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no histogram memory!", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -310,7 +310,7 @@ static int checkHM(pHistMem * pHM, SicsInterp * pSics, SConnection * pCon, */ GetHistDim(*pHM, iDim, &nDim); if (nDim < 2) { - sprintf(pBueffel, "ERROR: %s is not 2 dimensional!", name); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is not 2 dimensional!", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -344,7 +344,7 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, we need arguments */ if (argc < 2) { - 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; @@ -356,7 +356,7 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, strtolower(argv[1]); if (strcmp(argv[1], "search") == 0) { if (argc < 3) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s.search", argv[0]); SCWrite(pCon, pBueffel, eError); @@ -380,11 +380,11 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, if (count != 0) { Tcl_DStringAppend(&result, "@", strlen("@")); } - sprintf(pNum, "%d ", i); + snprintf(pNum,sizeof(pNum)-1, "%d ", i); Tcl_DStringAppend(&result, pNum, strlen(pNum)); - sprintf(pNum, "%d ", j); + snprintf(pNum,sizeof(pNum)-1, "%d ", j); Tcl_DStringAppend(&result, pNum, strlen(pNum)); - sprintf(pNum, "%d", intensity); + snprintf(pNum,sizeof(pNum)-1, "%d", intensity); Tcl_DStringAppend(&result, pNum, strlen(pNum)); count++; } @@ -395,7 +395,7 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, return 1; } else if (strcmp(argv[1], "cog") == 0) { /* COG calculation */ if (argc < 5) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s.cog", argv[0]); SCWrite(pCon, pBueffel, eError); @@ -405,12 +405,12 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, return 0; } if (Tcl_GetInt(pSics->pTcl, argv[3], &i) != 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; } if (Tcl_GetInt(pSics->pTcl, argv[4], &j) != 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; } @@ -424,20 +424,20 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, SCWrite(pCon, "ERROR: no intensity in data", eError); return 0; } - sprintf(pNum, "%d ", i); + snprintf(pNum,sizeof(pNum)-1, "%d ", i); Tcl_DStringAppend(&result, pNum, strlen(pNum)); - sprintf(pNum, "%d ", j); + snprintf(pNum,sizeof(pNum)-1, "%d ", j); Tcl_DStringAppend(&result, pNum, strlen(pNum)); - sprintf(pNum, "%d ", intensity); + snprintf(pNum,sizeof(pNum)-1, "%d ", intensity); Tcl_DStringAppend(&result, pNum, strlen(pNum)); - sprintf(pNum, "%d ", count); + snprintf(pNum,sizeof(pNum)-1, "%d ", count); Tcl_DStringAppend(&result, pNum, strlen(pNum)); SCWrite(pCon, Tcl_DStringValue(&result), eValue); Tcl_DStringFree(&result); return 1; } else if (strcmp(argv[1], "wellformed") == 0) { /* test for wellformedness */ if (argc < 6) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s.wellformed", argv[0]); SCWrite(pCon, pBueffel, eError); @@ -447,17 +447,17 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, return 0; } if (Tcl_GetInt(pSics->pTcl, argv[3], &i) != 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; } if (Tcl_GetInt(pSics->pTcl, argv[4], &j) != 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; } if (Tcl_GetInt(pSics->pTcl, argv[5], &badMax) != 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; } @@ -465,12 +465,12 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, window = (int) ObVal(self->pParam, COGWINDOW); iRet = wellFormed(iData, iDim[0], iDim[1], i, j, window, ObVal(self->pParam, COGCONTOUR), badMax); - sprintf(pBueffel, "%5d", iRet); + snprintf(pBueffel,sizeof(pBueffel)-1, "%5d", iRet); SCWrite(pCon, pBueffel, eValue); return 1; } else if (strcmp(argv[1], "stat") == 0) { if (argc < 3) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient number of arguments to %s.search", argv[0]); SCWrite(pCon, pBueffel, eError); @@ -481,7 +481,7 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, } iData = GetHistogramPointer(pHM, pCon); calculateStatistics(iData, iDim[0], iDim[1], &average, &maximum); - sprintf(pBueffel, " %f %f", average, maximum); + snprintf(pBueffel,sizeof(pBueffel)-1, " %f %f", average, maximum); SCWrite(pCon, pBueffel, eValue); return 1; } else { @@ -489,7 +489,7 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, */ if (argc > 2) { /* set case */ if (Tcl_GetDouble(pSics->pTcl, argv[2], &dVal) != 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; } @@ -498,12 +498,12 @@ int LoMaxAction(SConnection * pCon, SicsInterp * pSics, ob = ObParFind(self->pParam, argv[1]); if (!ob) { - sprintf(pBueffel, "ERROR: parameter %s not found or wrong command", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: parameter %s not found or wrong command", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } - sprintf(pBueffel, "%s.%s = %f", argv[0], argv[1], ob->fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %f", argv[0], argv[1], ob->fVal); SCWrite(pCon, pBueffel, eError); return 1; } diff --git a/macro.c b/macro.c index 3172133e..81ed22ea 100644 --- a/macro.c +++ b/macro.c @@ -467,7 +467,7 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, } fp = fopen(argv[1], "r"); if (!fp) { - sprintf(pBueffel, " Failed to open file -> %s <- ", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, " Failed to open file -> %s <- ", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -502,7 +502,7 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, SetStatus(eEager); FirstWord(pCom, pBueffel); if (FindCommand(pInter, pBueffel) != NULL) { - sprintf(pBueffel, "%s:%d>> %s", pFile, iLine, pCom); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s:%d>> %s", pFile, iLine, pCom); SCWrite(pCon, pBueffel, eLog); if (pWhere != NULL) { free(pWhere); @@ -928,7 +928,7 @@ static int TclAction(SConnection * pCon, SicsInterp * pSics, void *pData, pTcl = InterpGetTcl(pSics); if (!SCMatchRights(pCon, self->iUser)) { - sprintf(pBueffel, "ERROR: you are not authorised to invoke %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: you are not authorised to invoke %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -976,7 +976,7 @@ int TclPublish(SConnection * pCon, SicsInterp * pSics, void *pData, /* check no of args */ if (argc < 3) { - sprintf(pBueffel, "ERROR: Insufficient no of arguments to %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Insufficient no of arguments to %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -985,7 +985,7 @@ int TclPublish(SConnection * pCon, SicsInterp * pSics, void *pData, /* try convert last parameter to user code */ iUser = decodeSICSPriv(argv[2]); if (iUser < 0) { - sprintf(pBueffel, "ERROR: cannot identify %s as a valid user code", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot identify %s as a valid user code", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; @@ -999,7 +999,7 @@ int TclPublish(SConnection * pCon, SicsInterp * pSics, void *pData, } /* check user rights */ if (!SCMatchRights(pCon, usMugger)) { - sprintf(pBueffel, "ERROR: you are not authorised to use %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: you are not authorised to use %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1009,7 +1009,7 @@ int TclPublish(SConnection * pCon, SicsInterp * pSics, void *pData, /* check user rights */ if (!SCMatchRights(pCon, usMugger)) { - sprintf(pBueffel, "ERROR: you are not authorised to use %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: you are not authorised to use %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -1017,14 +1017,14 @@ int TclPublish(SConnection * pCon, SicsInterp * pSics, void *pData, /* do a job ! */ pNew = CreatePublish(argv[1], iUser); if (!pNew) { - sprintf(pBueffel, "ERROR: memory error in %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: memory error in %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = AddCommand(pSics, argv[1], TclAction, DeletePublish, (void *) 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; } diff --git a/maximize.c b/maximize.c index 381d84d7..8be3b4ec 100644 --- a/maximize.c +++ b/maximize.c @@ -87,7 +87,7 @@ static int maxDrive(void *pObject, char *pVarName, pVarName, pDum->pDescriptor, pObject, pCon, RUNDRIVE, fPos); if (!status) { - sprintf(pBueffel, "ERROR: failed to start %s", pVarName); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to start %s", pVarName); SCWrite(pCon, pBueffel, eError); return 0; } @@ -180,7 +180,7 @@ start: return 0; } /* print a message */ - sprintf(pBueffel, "%5d %8.2f %ld", i, x[i], lCts); + snprintf(pBueffel,sizeof(pBueffel)-1, "%5d %8.2f %ld", i, x[i], lCts); SCWrite(pCon, pBueffel, eLog); /* store counts and some logic */ @@ -243,7 +243,7 @@ start: return 0; } /* print a message */ - sprintf(pBueffel, "%5d %8.2f %ld", i, x[i], lCts); + snprintf(pBueffel,sizeof(pBueffel)-1, "%5d %8.2f %ld", i, x[i], lCts); SCWrite(pCon, pBueffel, eLog); /* store counts and some logic */ @@ -299,7 +299,7 @@ start: return 0; } #ifdef DEBUG - sprintf(pBueffel, "iBot = %d, iTop = %d, lMax = %ld", iBot, iTop, lMax); + snprintf(pBueffel,sizeof(pBueffel)-1, "iBot = %d, iTop = %d, lMax = %ld", iBot, iTop, lMax); SCWrite(pCon, pBueffel, eWarning); #endif @@ -336,7 +336,7 @@ start: } } maxDrive(pVar, pVarName, fCent, pCon); - sprintf(pBueffel, "Found peak center at %8.2f, Count = %ld", fCent, + snprintf(pBueffel,sizeof(pBueffel)-1, "Found peak center at %8.2f, Count = %ld", fCent, lCts); SCWrite(pCon, pBueffel, eValue); return 1; @@ -462,19 +462,19 @@ int MaximizeAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* decode arguments */ pCom = FindCommand(pSics, argv[1]); if (!pCom) { - sprintf(pBueffel, "ERROR: object %s NOT found!", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: object %s NOT found!", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } if (!pCom->pData) { - sprintf(pBueffel, "ERROR: object %s Invalid!!", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: object %s Invalid!!", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -482,7 +482,7 @@ int MaximizeAction(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = Tcl_GetDouble(pSics->pTcl, argv[4], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[4]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to convert %s to number", argv[4]); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/motor.c b/motor.c index 6dc9433c..f5c770d9 100644 --- a/motor.c +++ b/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); diff --git a/motorsec.c b/motorsec.c index cce60b40..9bb365f4 100644 --- a/motorsec.c +++ b/motorsec.c @@ -134,20 +134,20 @@ static int SecMotorCheckBoundary(pMotor self, float fVal, float *fTarget, /* check for fixed */ if (fixed >= 0) { - sprintf(pBueffel, "Motor %s is Fixed", self->name); + snprintf(pBueffel,sizeof(pBueffel)-1, "Motor %s is Fixed", self->name); strncpy(pError, pBueffel, iErrLen); return 0; /* is this an error? */ } /* check against software boundaries */ if (fVal > upperlim) { - sprintf(pBueffel, "%f violates upper software limit %f on %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "%f violates upper software limit %f on %s", fVal, upperlim, self->name); strncpy(pError, pBueffel, iErrLen); return 0; } if (fVal < lowerlim) { - sprintf(pBueffel, "%f violates lower software limit %f on %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "%f violates lower software limit %f on %s", fVal, lowerlim, self->name); strncpy(pError, pBueffel, iErrLen); return 0; @@ -165,13 +165,13 @@ static int SecMotorCheckBoundary(pMotor self, float fVal, float *fTarget, SecMotorGetPar(self, "hardlowerlim", &hlower); SecMotorGetPar(self, "hardupperlim", &hupper); if (fHard > hupper) { - sprintf(pBueffel, "%f violates upper hardware limit %f on %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "%f violates upper hardware limit %f on %s", fVal, hupper, self->name); strncpy(pError, pBueffel, iErrLen); return 0; } if (fHard < hlower) { - sprintf(pBueffel, "%f violates lower hardware limit %f on %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "%f violates lower hardware limit %f on %s", fVal, hlower, self->name); strncpy(pError, pBueffel, iErrLen); return 0; @@ -416,7 +416,7 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData, */ SecMotorGetPar(self, "accesscode", &fVal); if (!SCMatchRights(pCon, (int) fVal)) { - 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); @@ -454,7 +454,7 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData, /* 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); diff --git a/motreg.c b/motreg.c index bdf22d19..6408130d 100644 --- a/motreg.c +++ b/motreg.c @@ -120,7 +120,7 @@ int StartRegMot(pMotReg self, SConnection * pCon, float fValue) FindDescriptor(self->motorData), self->motorData, pCon, pCon->runLevel, fValue); /* - sprintf(pBueffel,"anticollision started %s to %f",self->motorName, + snprintf(pBueffel,sizeof(pBueffel)-1,"anticollision started %s to %f",self->motorName, fValue); SCWrite(pCon,pBueffel,eValue); */ diff --git a/multicounter.c b/multicounter.c index 694b865c..fb3b85e1 100644 --- a/multicounter.c +++ b/multicounter.c @@ -258,7 +258,7 @@ static int MMCCTransfer(void *pData, SConnection * pCon) status = self->slaves[i]->TransferData(self->slaveData[i], pCon); if (status != OKOK) { retVal = status; - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: slave histogram %d failed to transfer data", i); SCWrite(pCon, pBueffel, eWarning); } @@ -480,14 +480,14 @@ int MakeMultiCounter(SConnection * pCon, SicsInterp * pSics, for (i = 2; i < argc; i++) { pCom = FindCommand(pSics, argv[i]); if (!pCom) { - sprintf(pBueffel, "ERROR: object %s not found in MakeMultiCounter", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: object %s not found in MakeMultiCounter", argv[i]); SCWrite(pCon, pBueffel, eError); continue; } pCount = GetCountableInterface(pCom->pData); if (!pCount) { - sprintf(pBueffel, "ERROR: object %s is NOT countable", argv[i]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: object %s is NOT countable", argv[i]); SCWrite(pCon, pBueffel, eError); continue; } @@ -502,7 +502,7 @@ int MakeMultiCounter(SConnection * pCon, SicsInterp * pSics, status = AddCommand(pSics, argv[1], MultiCounterAction, DeleteCounter, pNew); if (!status) { - 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); DeleteCounter(pNew); return 0; diff --git a/mumo.c b/mumo.c index 3191e810..4524f306 100644 --- a/mumo.c +++ b/mumo.c @@ -313,7 +313,7 @@ static void ListMulMot(char *name, SConnection * pCon, pMulMot self) char pMotName[132]; pMotor pMot = NULL; - sprintf(pBueffel, "Status listing for %s", name); + snprintf(pBueffel,sizeof(pBueffel)-1, "Status listing for %s", name); SCWrite(pCon, pBueffel, eValue); /* scan through all aliases */ @@ -323,11 +323,11 @@ static void ListMulMot(char *name, SConnection * pCon, pMulMot self) assert(pMot); /* has been tested on definition */ iRet = MotorGetSoftPosition(pMot, pCon, &fVal); if (!iRet) { - sprintf(pBueffel, "ERROR: Cannot read motor %s\n", pMotName); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Cannot read motor %s\n", pMotName); eOut = eError; } else { eOut = eValue; - sprintf(pBueffel, "%s.%s = %f\n", name, pNam, fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %f\n", name, pNam, fVal); } SCWrite(pCon, pBueffel, eValue); pNam = StringDictGetNext(self->pAlias, pMotName, 131); @@ -353,7 +353,7 @@ static int ParseAlias(psParser pParse, SConnection * pCon, pMulMot self) iRet = StringDictGet(self->pAlias, pParse->Token, pBueffel, 131); /* that it is alias has been tested earlier */ assert(iRet == 1); - strcat(pCommand, pBueffel); + strncat(pCommand, pBueffel,1024); /* now find the value to handle */ iToken = GetNextToken(pParse, self); @@ -383,20 +383,20 @@ static int ParseAlias(psParser pParse, SConnection * pCon, pMulMot self) assert(pMot); /* existence shoul have been verified earlier */ MotorGetSoftPosition(pMot, pCon, &fVal); fVal += iSign * fIn; - sprintf(pBueffel, " %f ", fVal); - strcat(pCommand, pBueffel); + snprintf(pBueffel,sizeof(pBueffel)-1, " %f ", fVal); + strncat(pCommand, pBueffel,1024); InterpExecute(GetInterpreter(), pCon, pCommand); return 1; } else { - sprintf(pBueffel, " %f ", iSign * fIn); - strcat(pCommand, pBueffel); + snprintf(pBueffel,sizeof(pBueffel)-1, " %f ", iSign * fIn); + strncat(pCommand, pBueffel,1024); InterpExecute(GetInterpreter(), pCon, pCommand); return 1; } return 1; break; default: - sprintf(pBueffel, "ERROR: Unexpected symbol %s", pParse->Token); + snprintf(pBueffel,1024, "ERROR: Unexpected symbol %s", pParse->Token); SCWrite(pCon, pBueffel, eError); return 0; } @@ -426,18 +426,18 @@ static int MakeCurrentNamPos(char *name, SConnection * pCon, pMulMot self) pCommand[0] = '\0'; pAlias = StringDictGetNext(self->pAlias, pMotort, 131); while (pAlias != NULL) { - strcat(pCommand, pMotort); + strncat(pCommand, pMotort,1024); pMot = FindMotor(GetInterpreter(), pMotort); assert(pMot); /* validity of alias has already been checked */ iRet = MotorGetSoftPosition(pMot, pCon, &fVal); if (!iRet) { - sprintf(pCommand, "ERROR: failure to read motor %s, %s", + snprintf(pCommand,1024, "ERROR: failure to read motor %s, %s", pMotort, " named position not created"); SCWrite(pCon, pCommand, eError); return 0; } - sprintf(pMotort, " %f ", fVal); - strcat(pCommand, pMotort); + snprintf(pMotort,sizeof(pMotort)-1, " %f ", fVal); + strncat(pCommand, pMotort,1024); pAlias = StringDictGetNext(self->pAlias, pMotort, 131); } if (StringDictExists(self->pNamPos, name)) { @@ -480,7 +480,7 @@ const char *FindNamPos(pMulMot self, SConnection * pCon) if (pMot != NULL) { iRet = MotorGetSoftPosition(pMot, pCon, &f1); if (!iRet) { - sprintf(pTestCommand, + snprintf(pTestCommand,sizeof(pTestCommand)-1, "ERROR: failed to get motor position for %s", pName); SCWrite(pCon, pTestCommand, eError); return NULL; @@ -563,7 +563,7 @@ static int ParseDropPos(psParser pParse, SConnection * pCon, pMulMot self) return 1; break; default: - sprintf(pBueffel, "ERROR: Unexpected symbol %s", pParse->Token); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Unexpected symbol %s", pParse->Token); SCWrite(pCon, pBueffel, eError); return 0; } @@ -581,7 +581,7 @@ static int CheckPermission(SConnection * pCon, pMulMot self) if (SCMatchRights(pCon, iAccess)) { return 1; } else { - sprintf(pBueffel, "ERROR: NO permission to drive %s", self->name); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: NO permission to drive %s", self->name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -609,7 +609,7 @@ static int ParseNamPos(psParser pParse, SConnection * pCon, InterpExecute(GetInterpreter(), pCon, pCommand); return 1; } else { - sprintf(pCommand, "ERROR: named position %s NOT found", pParse->Token); + snprintf(pCommand,sizeof(pCommand)-1, "ERROR: named position %s NOT found", pParse->Token); SCWrite(pCon, pCommand, eError); return 0; } @@ -628,7 +628,7 @@ static int ParseDefPos(SicsInterp * pSics, psParser pPP, iToken = GetNextToken(pPP, self); if (iToken != SYMBOL) { /* we want a name here */ - sprintf(pError, "ERROR: Invalid Token %s in ParsePos", pPP->Token); + snprintf(pError,sizeof(pError)-1, "ERROR: Invalid Token %s in ParsePos", pPP->Token); SCWrite(pCon, pError, eError); return 0; } @@ -638,21 +638,21 @@ static int ParseDefPos(SicsInterp * pSics, psParser pPP, command[0] = '\0'; while (iToken != END) { if (iToken != ALIAS) { - sprintf(command, "ERROR: expected motor alias, got: %s", pPP->Token); + snprintf(command,sizeof(command)-1, "ERROR: expected motor alias, got: %s", pPP->Token); SCWrite(pCon, command, eError); return 0; } StringDictGet(self->pAlias, pPP->Token, motorName, 79); - strcat(command, motorName); - strcat(command, " "); + strncat(command, motorName,1024); + strncat(command, " ",1024); iToken = GetNextToken(pPP, self); if (iToken != NUMBER) { - sprintf(command, "ERROR: expected number, got: %s", pPP->Token); + snprintf(command,sizeof(command)-1, "ERROR: expected number, got: %s", pPP->Token); SCWrite(pCon, command, eError); return 0; } - strcat(command, pPP->Token); - strcat(command, " "); + strncat(command, pPP->Token,1024); + strncat(command, " ",1024); iToken = GetNextToken(pPP, self); } @@ -770,9 +770,9 @@ int MultiWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, case GETPOS: pPtr = FindNamPos(self, pCon); if (pPtr != NULL) { - sprintf(pBueffel, "%s.nampos = %s", argv[0], pPtr); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.nampos = %s", argv[0], pPtr); } else { - sprintf(pBueffel, "%s.nampos = undefined", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.nampos = undefined", argv[0]); } SCWrite(pCon, pBueffel, eValue); return 1; @@ -783,7 +783,7 @@ int MultiWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, case LIST: pPtr = NULL; Tcl_DStringInit(&tString); - sprintf(pBueffel, "%s list of known named positions \n", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s list of known named positions \n", argv[0]); Tcl_DStringAppend(&tString, pBueffel, strlen(pBueffel)); StringDictKillScan(self->pNamPos); pPtr = StringDictGetNext(self->pNamPos, pError, 131); @@ -808,7 +808,7 @@ int MultiWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, SCparChange(pCon); return 1; } else { - sprintf(pError, "ERROR: %s no valid named position name", + snprintf(pError,sizeof(pError)-1, "ERROR: %s no valid named position name", MyParser.Token); SCWrite(pCon, pError, eError); return 0; @@ -828,14 +828,14 @@ int MultiWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, pPtr = NULL; pPtr = FindNamPos(self, pCon); if (pPtr) { - sprintf(pBueffel, "%s.namedposition = %s", argv[0], pPtr); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.namedposition = %s", argv[0], pPtr); } else { - sprintf(pBueffel, "%s.namedposition = UNKNOWN", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.namedposition = UNKNOWN", argv[0]); } SCWrite(pCon, pBueffel, eValue); return 1; } - sprintf(pError, "ERROR: Unknown Token %s", MyParser.Token); + snprintf(pError,sizeof(pError)-1, "ERROR: Unknown Token %s", MyParser.Token); SCWrite(pCon, pError, eError); return 0; case RECOVERNAMPOS: diff --git a/mumoconf.c b/mumoconf.c index 2b53d5fc..d0f08643 100644 --- a/mumoconf.c +++ b/mumoconf.c @@ -209,7 +209,7 @@ int MakeMulti(SConnection * pCon, SicsInterp * pSics, void *pData, pNew->name = strdup(argv[1]); iRet = AddCommand(pSics, argv[1], ConfigMulti, NULL, 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); return 0; } @@ -227,7 +227,7 @@ static int ParseAlias(SicsInterp * pSics, psParser pPP, pMulMot self, /* next token should be a motor name */ iToken = GetNextToken(pPP); if (iToken != SYMBOL) { - sprintf(pError, "ERROR: Token %s not recognized in MulMot alias", + snprintf(pError,sizeof(pError)-1, "ERROR: Token %s not recognized in MulMot alias", pPP->Token); SCWrite(pCon, pError, eError); return 0; @@ -235,7 +235,7 @@ static int ParseAlias(SicsInterp * pSics, psParser pPP, pMulMot self, /* try find the motor and verify that it is a motor */ pMot = FindMotor(pSics, pPP->Token); if (!pMot) { - sprintf(pError, "ERROR: Motor %s not found, no alias created", + snprintf(pError,sizeof(pError)-1, "ERROR: Motor %s not found, no alias created", pPP->Token); SCWrite(pCon, pError, eError); return 0; @@ -248,7 +248,7 @@ static int ParseAlias(SicsInterp * pSics, psParser pPP, pMulMot self, iToken = GetNextToken(pPP); } if (iToken != SYMBOL) { - sprintf(pError, "ERROR: Token %s not recognized in MulMot alias", + snprintf(pError,sizeof(pError)-1, "ERROR: Token %s not recognized in MulMot alias", pPP->Token); SCWrite(pCon, pError, eError); return 0; @@ -273,7 +273,7 @@ static int ParsePos(SicsInterp * pSics, psParser pPP, iToken = GetNextToken(pPP); if (iToken != SYMBOL) { /* we want a name here */ - sprintf(pError, "ERROR: Invalid Token %s in ParsePos", pPP->Token); + snprintf(pError,sizeof(pError)-1, "ERROR: Invalid Token %s in ParsePos", pPP->Token); SCWrite(pCon, pError, eError); return 0; } @@ -304,7 +304,7 @@ int ConfigMulti(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = Arg2Text(argc, argv, pBueffel, 511); if (!iRet) { - sprintf(pBueffel, "Argument string to long for %s configuration", + snprintf(pBueffel,sizeof(pBueffel)-1, "Argument string to long for %s configuration", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -336,7 +336,7 @@ int ConfigMulti(SConnection * pCon, SicsInterp * pSics, void *pData, return ParsePos(pSics, &PP, self, pCon); break; default: - sprintf(pError, "ERROR: Invalid Token %s found in %s", + snprintf(pError,sizeof(pError)-1, "ERROR: Invalid Token %s found in %s", PP.Token, argv[0]); SCWrite(pCon, pBueffel, eError); return 0; @@ -344,7 +344,7 @@ int ConfigMulti(SConnection * pCon, SicsInterp * pSics, void *pData, iToken = GetNextToken(&PP); } /* should never end here */ - sprintf(pError, "ERROR: %s was NOT understood in mumoconf", pBueffel); + snprintf(pError,sizeof(pError)-1, "ERROR: %s was NOT understood in mumoconf", pBueffel); SCWrite(pCon, pError, eError); return 0; } diff --git a/nread.c b/nread.c index 56679cc1..3c432ae4 100644 --- a/nread.c +++ b/nread.c @@ -259,7 +259,7 @@ static int NetReadRead(pNetRead self, pNetItem pItem) sscanf(pPtr, "%s %d", pMuell, &iInt); if (SCMatchRights(pItem->pCon, usUser)) { TaskSignal(self->pMain->pTasker, SICSINT, &iInt); - sprintf(pBueffel, "INTERRUPT %d issued on sock %d", + snprintf(pBueffel,sizeof(pBueffel)-1, "INTERRUPT %d issued on sock %d", iInt, pItem->pCon->pSock->sockid); WriteToCommandLog("SYS>", pBueffel); if (iInt == eEndServer) { @@ -289,7 +289,7 @@ static int NetReadRead(pNetRead self, pNetItem pItem) *pEnd = '\0'; /* do we have something in hold ? */ if (strlen(pItem->pHold) > 0) { - strcat(pItem->pHold, pPtr); + strncat(pItem->pHold, pPtr,511); iStat = CostaTop(pItem->pCon->pStack, pItem->pHold); if (!iStat) { SCWrite(pItem->pCon, "ERROR: Busy", eError); @@ -320,7 +320,7 @@ static int NetReadRead(pNetRead self, pNetItem pItem) } /* when we are here we may still have an incomplete command pending */ if (pEnd != pPtr && strlen(pPtr) > 0) { - strcpy(pItem->pHold, pPtr); + strncpy(pItem->pHold, pPtr, 511); } return 1; } @@ -449,7 +449,7 @@ static int TelnetRead(pNetRead self, pNetItem pItem) } } TaskSignal(self->pMain->pTasker, SICSINT, &iInt); - sprintf(pError, "INTERRUPT %d issued on sock %d", iInt, + snprintf(pError,sizeof(pError)-1, "INTERRUPT %d issued on sock %d", iInt, pItem->pCon->pSock->sockid); WriteToCommandLog("SYS>", pError); if (iInt == eEndServer) { @@ -603,7 +603,7 @@ static int TelnetRead(pNetRead self, pNetItem pItem) default: /* There is something wrong here! */ - sprintf(pError, "ERROR: bad telnet code %d", cChar); + snprintf(pError,sizeof(pError)-1, "ERROR: bad telnet code %d", cChar); SICSLogWrite(pError, eInternal); pItem->tStatus = tData; break; @@ -673,7 +673,7 @@ int NetReaderTask(void *pData) break; } - sprintf(num, "%d, type %d:", NItem.pSock->sockid, NItem.eType); + snprintf(num,sizeof(num)-1, "%d, type %d:", NItem.pSock->sockid, NItem.eType); if (conCount < 100) { DynStringConcat(self->conList, num); } @@ -1263,7 +1263,7 @@ static int ANETTelnetProcess(int handle, void *usData) default: /* There is something wrong here! */ - sprintf(pError, "ERROR: bad telnet code %d", cChar); + snprintf(pError,sizeof(pError)-1, "ERROR: bad telnet code %d", cChar); SICSLogWrite(pError, eInternal); self->state = tData; break; diff --git a/nserver.c b/nserver.c index 6cdfab40..4e0ecb84 100644 --- a/nserver.c +++ b/nserver.c @@ -144,7 +144,7 @@ int InitServer(char *file, pServer * pServ) pPtr = IFindOption(pSICSOptions, "RedirectFile"); if (pPtr != NULL) { myPid = getpid(); - sprintf(pBueffel, "%s%5.5d.log", pPtr, (int) myPid); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s%5.5d.log", pPtr, (int) myPid); fp = freopen(pBueffel, "w", stdout); if (!fp) { printf("Failed to redirect stdout/stderr to %s\n", pBueffel); @@ -291,7 +291,7 @@ void StopServer(pServer self) strcpy(pBueffel, "Backup "); pText = IFindOption(pSICSOptions, "statusfile"); if (pText) { - strcat(pBueffel, pText); + strncat(pBueffel, pText,511); } else { strcat(pBueffel, DEFAULTSTATUSFILE); } @@ -440,7 +440,7 @@ int UserWait(SConnection * pCon, SicsInterp * pSics, void *pData, pTask = GetTasker(); if (argc < 2) { - sprintf(pBueffel, "Insufficient number of args to %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient number of args to %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -448,7 +448,7 @@ int UserWait(SConnection * pCon, SicsInterp * pSics, void *pData, /* try convert to a number */ i = sscanf(argv[1], "%f", &fVal); if (i < 1) { - sprintf(pBueffel, "Expected numeric argument to %s, got %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "Expected numeric argument to %s, got %s", argv[0], argv[1]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/nxscript.c b/nxscript.c index ec37a2d7..11db6e25 100644 --- a/nxscript.c +++ b/nxscript.c @@ -111,10 +111,10 @@ char *makeFilename(SicsInterp * pSics, SConnection * pCon) */ strcat(pRes, "/"); strcat(pRes, pPref->text); - sprintf(pNumText, "%4.4d", iYear); + snprintf(pNumText,sizeof(pNumText)-1, "%4.4d", iYear); strcat(pRes, pNumText); strcat(pRes, "n"); - sprintf(pNumText, "%6.6d", iNum); + snprintf(pNumText,sizeof(pNumText)-1, "%6.6d", iNum); strcat(pRes, pNumText); strcat(pRes, pEnd->text); @@ -220,13 +220,13 @@ static int handleFileOperations(SConnection * pCon, pNXScript self, */ status = NXopen(argv[2], access, &self->fileHandle); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to open %s", argv[2]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to open %s", argv[2]); SCWrite(pCon, buffer, eError); return -1; } status = NXDinitfromfile(argv[3], &self->dictHandle); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to open dictionary %s", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to open dictionary %s", argv[3]); SCWrite(pCon, buffer, eError); return -1; } @@ -254,7 +254,7 @@ static void putMotor(SConnection * pCon, SicsInterp * pSics, */ brumm = (pMotor) FindCommandData(pSics, argv[3], "Motor"); if (!brumm) { - sprintf(buffer, "ERROR: motor %s not found!", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: motor %s not found!", argv[3]); SCWrite(pCon, buffer, eLogError); return; } @@ -264,13 +264,13 @@ static void putMotor(SConnection * pCon, SicsInterp * pSics, */ status = MotorGetSoftPosition(brumm, pCon, &fVal); if (!status) { - sprintf(buffer, "ERROR: failed to read position of %s", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to read position of %s", argv[3]); SCWrite(pCon, buffer, eLogError); return; } status = NXDputalias(self->fileHandle, self->dictHandle, argv[2], &fVal); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write %s with alias %s", + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write %s with alias %s", argv[3], argv[2]); SCWrite(pCon, buffer, eLogError); return; @@ -279,14 +279,14 @@ static void putMotor(SConnection * pCon, SicsInterp * pSics, /* if alias_null is available: write zero point */ - strcpy(buffer, argv[2]); - strcat(buffer, "_null"); + strncpy(buffer, argv[2],131); + strncat(buffer, "_null",131); if (NXDdefget(self->dictHandle, buffer, dummy, 255)) { MotorGetPar(brumm, "softzero", &fVal); status = NXDputalias(self->fileHandle, self->dictHandle, buffer, &fVal); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write %s zero with alias %s", + snprintf(buffer,131, "ERROR: failed to write %s zero with alias %s", argv[3], argv[2]); SCWrite(pCon, buffer, eLogError); return; @@ -317,7 +317,7 @@ static void putCounter(SConnection * pCon, SicsInterp * pSics, */ cter = (pCounter) FindCommandData(pSics, argv[3], "SingleCounter"); if (!cter) { - sprintf(buffer, "ERROR: counter %s not found!", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: counter %s not found!", argv[3]); SCWrite(pCon, buffer, eLogError); return; } @@ -326,12 +326,12 @@ static void putCounter(SConnection * pCon, SicsInterp * pSics, do preset */ fVal = GetCounterPreset(cter); - strcpy(newAlias, argv[2]); - strcat(newAlias, "_preset"); + strncpy(newAlias, argv[2],255); + strncat(newAlias, "_preset",255); status = NXDputalias(self->fileHandle, self->dictHandle, newAlias, &fVal); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write preset to %s", newAlias); + snprintf(buffer,255, "ERROR: failed to write preset to %s", newAlias); SCWrite(pCon, buffer, eLogError); } @@ -349,7 +349,7 @@ static void putCounter(SConnection * pCon, SicsInterp * pSics, status = NXDputalias(self->fileHandle, self->dictHandle, newAlias, dummy); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write counter mode to %s", newAlias); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write counter mode to %s", newAlias); SCWrite(pCon, buffer, eLogError); } @@ -357,13 +357,13 @@ static void putCounter(SConnection * pCon, SicsInterp * pSics, do time */ fVal = GetCountTime(cter, pCon); - strcpy(newAlias, argv[2]); - strcat(newAlias, "_time"); + strncpy(newAlias, argv[2],255); + strncat(newAlias, "_time",255); if (NXDdefget(self->dictHandle, newAlias, dummy, 79)) { status = NXDputalias(self->fileHandle, self->dictHandle, newAlias, &fVal); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write count time to %s", newAlias); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write count time to %s", newAlias); SCWrite(pCon, buffer, eLogError); } } @@ -373,7 +373,7 @@ static void putCounter(SConnection * pCon, SicsInterp * pSics, do counter and monitors */ for (i = 0; i < 10; i++) { - sprintf(newAlias, "%s_%2.2d", argv[2], i); + snprintf(newAlias,255, "%s_%2.2d", argv[2], i); if (NXDdefget(self->dictHandle, newAlias, dummy, 79)) { counts = GetMonitor(cter, i, pCon); icounts = (int) counts; @@ -413,7 +413,7 @@ static void putSicsData(SConnection * pCon, SicsInterp * pSics, status = NXDputalias(self->fileHandle, self->dictHandle, argv[2], data->data); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write sicsdata to %s", argv[2]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write sicsdata to %s", argv[2]); SCWrite(pCon, buffer, eLogError); } } @@ -434,14 +434,14 @@ static void putAttribute(SConnection * pCon, SicsInterp * pSics, status = NXDopenalias(self->fileHandle, self->dictHandle, argv[2]); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to open alias %s", argv[2]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to open alias %s", argv[2]); SCWrite(pCon, buffer, eLogError); return; } status = NXputattr(self->fileHandle, argv[3], (void *) argv[4], strlen(argv[4]) + 1, type); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write attribute %s", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write attribute %s", argv[3]); SCWrite(pCon, buffer, eLogError); } NXopenpath(self->fileHandle, "/"); @@ -615,8 +615,8 @@ static void updateHMDim(NXScript * self, pHistMem mem) */ GetHistDim(mem, iDim, &rank); for (i = 0; i < rank; i++) { - sprintf(dummy, "dim%1.1d", i); - sprintf(value, "%d", iDim[i]); + snprintf(dummy,sizeof(dummy)-1, "dim%1.1d", i); + snprintf(value,sizeof(value)-1, "%d", iDim[i]); status = NXDupdate(self->dictHandle, dummy, value); if (status == 0) { NXDadd(self->dictHandle, dummy, value); @@ -624,9 +624,9 @@ static void updateHMDim(NXScript * self, pHistMem mem) } timeBin = GetHistTimeBin(mem, &timeLength); if (timeLength > 2) { - sprintf(dummy, "%d", timeLength); + snprintf(dummy,sizeof(dummy)-1, "%d", timeLength); } else { - sprintf(dummy, "%d", 1); + snprintf(dummy,sizeof(dummy)-1, "%d", 1); } status = NXDupdate(self->dictHandle, "timedim", dummy); if (status == 0) { @@ -659,7 +659,7 @@ static void putHistogramMemory(SConnection * pCon, SicsInterp * pSics, */ mem = (pHistMem) FindCommandData(pSics, argv[3], "HistMem"); if (!mem) { - sprintf(buffer, "ERROR: HistMem %s not found!", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: HistMem %s not found!", argv[3]); SCWrite(pCon, buffer, eLogError); return; } @@ -679,13 +679,13 @@ static void putHistogramMemory(SConnection * pCon, SicsInterp * pSics, subset = 1; status = Tcl_GetInt(InterpGetTcl(pSics), argv[4], &start); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to integer", argv[4]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to integer", argv[4]); SCWrite(pCon, buffer, eLogError); return; } status = Tcl_GetInt(InterpGetTcl(pSics), argv[5], &length); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to integer", argv[5]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to integer", argv[5]); SCWrite(pCon, buffer, eLogError); return; } @@ -697,7 +697,7 @@ static void putHistogramMemory(SConnection * pCon, SicsInterp * pSics, if (argc > 6) { status = Tcl_GetInt(InterpGetTcl(pSics), argv[6], &bank); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to integer", argv[6]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to integer", argv[6]); SCWrite(pCon, buffer, eLogError); return; } @@ -742,7 +742,7 @@ static void putHistogramMemory(SConnection * pCon, SicsInterp * pSics, */ status = NXDputalias(self->fileHandle, self->dictHandle, argv[2], iData); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write histogram memory data"); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write histogram memory data"); SCWrite(pCon, buffer, eLogError); } @@ -779,7 +779,7 @@ static void putHistogramMemoryChunked(SConnection * pCon, */ mem = (pHistMem) FindCommandData(pSics, argv[3], "HistMem"); if (!mem) { - sprintf(buffer, "ERROR: HistMem %s not found!", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: HistMem %s not found!", argv[3]); SCWrite(pCon, buffer, eLogError); return; } @@ -797,7 +797,7 @@ static void putHistogramMemoryChunked(SConnection * pCon, */ status = Tcl_GetInt(InterpGetTcl(pSics), argv[4], &noChunks); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to integer", argv[4]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to integer", argv[4]); SCWrite(pCon, buffer, eLogError); return; } @@ -840,7 +840,7 @@ static void putHistogramMemoryChunked(SConnection * pCon, */ status = NXDputalias(self->fileHandle, self->dictHandle, argv[2], iData); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write histogram memory data"); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write histogram memory data"); SCWrite(pCon, buffer, eLogError); } @@ -943,7 +943,7 @@ static void putTimeBinning(SConnection * pCon, SicsInterp * pSics, */ mem = (pHistMem) FindCommandData(pSics, argv[3], "HistMem"); if (!mem) { - sprintf(buffer, "ERROR: HistMem %s not found!", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: HistMem %s not found!", argv[3]); SCWrite(pCon, buffer, eLogError); return; } @@ -954,12 +954,12 @@ static void putTimeBinning(SConnection * pCon, SicsInterp * pSics, */ status = NXDdefget(self->dictHandle, argv[2], buffer, 254); if (!status) { - sprintf(buffer, "ERROR: alias %s for time binning not found", argv[2]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: alias %s for time binning not found", argv[2]); SCWrite(pCon, buffer, eLogError); return; } timeBin = GetHistTimeBin(mem, &timeLength); - sprintf(defString, "%s -dim {%d} ", buffer, timeLength); + snprintf(defString,sizeof(defString)-1, "%s -dim {%d} ", buffer, timeLength); /* Divide the time binning when appropriate and write @@ -983,7 +983,7 @@ static void putTimeBinning(SConnection * pCon, SicsInterp * pSics, } if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write time binning"); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write time binning"); SCWrite(pCon, buffer, eLogError); } SCSendOK(pCon); @@ -1014,7 +1014,7 @@ static void putArray(SConnection * pCon, SicsInterp * pSics, */ status = Tcl_GetInt(tcl, argv[4], &length); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to integer in putarray", + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to integer in putarray", argv[4]); SCWrite(pCon, buffer, eLogError); return; @@ -1039,12 +1039,12 @@ static void putArray(SConnection * pCon, SicsInterp * pSics, try getting data */ for (i = 0; i < length; i++) { - sprintf(num, "%d", i); + snprintf(num,sizeof(num)-1, "%d", i); varData = (char *) Tcl_GetVar2(tcl, argv[3], num, 0); if (varData != NULL) { status = Tcl_GetDouble(tcl, varData, &dVal); if (status != TCL_OK) { - sprintf(buffer, + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to double in putarray", varData); SCWrite(pCon, buffer, eLogError); @@ -1062,7 +1062,7 @@ static void putArray(SConnection * pCon, SicsInterp * pSics, */ status = NXDdefget(self->dictHandle, argv[2], buffer, 254); if (!status) { - sprintf(buffer, "ERROR: alias %s for array not found in putarray", + snprintf(buffer,sizeof(buffer)-1, "ERROR: alias %s for array not found in putarray", argv[2]); SCWrite(pCon, buffer, eLogError); free(data); @@ -1075,7 +1075,7 @@ static void putArray(SConnection * pCon, SicsInterp * pSics, */ status = NXDputdef(self->fileHandle, self->dictHandle, defString, data); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write array in putarray"); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write array in putarray"); SCWrite(pCon, buffer, eLogError); } free(data); @@ -1106,7 +1106,7 @@ static void putIntArray(SConnection * pCon, SicsInterp * pSics, */ status = Tcl_GetInt(tcl, argv[4], &length); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to integer", argv[4]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to integer", argv[4]); SCWrite(pCon, buffer, eLogError); return; } @@ -1127,12 +1127,12 @@ static void putIntArray(SConnection * pCon, SicsInterp * pSics, try getting data */ for (i = 0; i < length; i++) { - sprintf(num, "%d", i); + snprintf(num,sizeof(num)-1, "%d", i); varData = (char *) Tcl_GetVar2(tcl, argv[3], num, 0); if (varData != NULL) { status = Tcl_GetInt(tcl, varData, &iVal); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to int", varData); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to int", varData); SCWrite(pCon, buffer, eLogError); } data[i] = iVal; @@ -1147,7 +1147,7 @@ static void putIntArray(SConnection * pCon, SicsInterp * pSics, */ status = NXDdefget(self->dictHandle, argv[2], buffer, 254); if (!status) { - sprintf(buffer, "ERROR: alias %s for array not found", argv[2]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: alias %s for array not found", argv[2]); SCWrite(pCon, buffer, eLogError); free(data); return; @@ -1159,7 +1159,7 @@ static void putIntArray(SConnection * pCon, SicsInterp * pSics, */ status = NXDputdef(self->fileHandle, self->dictHandle, defString, data); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write array"); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write array"); SCWrite(pCon, buffer, eLogError); } free(data); @@ -1206,7 +1206,7 @@ static int handlePut(SConnection * pCon, SicsInterp * pSics, } status = Tcl_GetDouble(InterpGetTcl(pSics), argv[3], &dVal); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to float", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to float", argv[3]); SCWrite(pCon, buffer, eLogError); return 1; } @@ -1214,7 +1214,7 @@ static int handlePut(SConnection * pCon, SicsInterp * pSics, status = NXDputalias(self->fileHandle, self->dictHandle, argv[2], &fVal); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write %f to alias %s", + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write %f to alias %s", fVal, argv[2]); SCWrite(pCon, buffer, eLogError); } @@ -1227,14 +1227,14 @@ static int handlePut(SConnection * pCon, SicsInterp * pSics, } status = Tcl_GetInt(InterpGetTcl(pSics), argv[3], &iVal); if (status != TCL_OK) { - sprintf(buffer, "ERROR: failed to convert %s to int", argv[3]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to convert %s to int", argv[3]); SCWrite(pCon, buffer, eLogError); return 1; } status = NXDputalias(self->fileHandle, self->dictHandle, argv[2], &iVal); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write %d to alias %s", + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write %d to alias %s", iVal, argv[2]); SCWrite(pCon, buffer, eLogError); } @@ -1250,15 +1250,15 @@ static int handlePut(SConnection * pCon, SicsInterp * pSics, trim(buffer); status = NXDdefget(self->dictHandle, argv[2], defString, 1023); if (status != NX_OK) { - sprintf(buffer, "ERROR: alias %s not found in puttext", argv[2]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: alias %s not found in puttext", argv[2]); SCWrite(pCon, buffer, eLogError); return 1; } if (strlen(defString) < 900) { - strcat(defString, " -dim {"); - sprintf(numBuf, "%d", (int) strlen(buffer) + 1); - strcat(defString, numBuf); - strcat(defString, " }"); + strncat(defString, " -dim {",1024); + snprintf(numBuf,sizeof(numBuf)-1, "%d", (int) strlen(buffer) + 1); + strncat(defString, numBuf,1024); + strncat(defString, " }",1024); } else { SCWrite(pCon, "ERROR: out of definition string space in puttext", eLogError); @@ -1267,7 +1267,7 @@ static int handlePut(SConnection * pCon, SicsInterp * pSics, status = NXDputdef(self->fileHandle, self->dictHandle, defString, buffer); if (status != NX_OK) { - sprintf(buffer, "ERROR: failed to write alias %s", argv[2]); + snprintf(buffer,sizeof(buffer)-1, "ERROR: failed to write alias %s", argv[2]); SCWrite(pCon, buffer, eLogError); } return 1; diff --git a/nxutil.c b/nxutil.c index 00dea0f3..277fe1b7 100644 --- a/nxutil.c +++ b/nxutil.c @@ -31,7 +31,7 @@ int SNXSPutMotor(SicsInterp * pSics, SConnection * pCon, strtolower(pBueffel); pMot = FindMotor(pSics, pBueffel); if (!pMot) { - sprintf(pBueffel, "WARNING: cannot find motor %s", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: cannot find motor %s", pName); SCWrite(pCon, pBueffel, eWarning); return 0; } @@ -61,7 +61,7 @@ int SNXSPutMotorNull(SicsInterp * pSics, SConnection * pCon, strtolower(pBueffel); pMot = FindMotor(pSics, pBueffel); if (!pMot) { - sprintf(pBueffel, "WARNING: cannot find motor %s", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: cannot find motor %s", pName); SCWrite(pCon, pBueffel, eWarning); return 0; } @@ -69,7 +69,7 @@ int SNXSPutMotorNull(SicsInterp * pSics, SConnection * pCon, /* get the null point */ iRet = MotorGetPar(pMot, "softzero", &fVal); if (!iRet) { /* should have been reported */ - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: failed to find zero point for motor %s", pName); SCWrite(pCon, pBueffel, eWarning); return 0; @@ -96,7 +96,7 @@ int SNXSPutVariable(SicsInterp * pSics, SConnection * pCon, strtolower(pBueffel); pVar = FindVariable(pSics, pBueffel); if (!pVar) { - sprintf(pBueffel, "WARNING: cannot find variable %s", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: cannot find variable %s", pName); SCWrite(pCon, pBueffel, eWarning); return 0; } @@ -232,25 +232,25 @@ int SNXSPutEVVar(NXhandle hfil, NXdict pDict, } if (fMean < -110) { - sprintf(pBueffel, "WARNING: %s invalid", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s invalid", pName); SCWrite(pCon, pBueffel, eWarning); } if (pStdDevAlias) { if (fStdDev < -110) { - sprintf(pBueffel, "WARNING: %s standard deviation invalid", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: %s standard deviation invalid", pName); SCWrite(pCon, pBueffel, eWarning); } } /* whatever it was, write it, even if it is shit */ iRet = NXDputalias(hfil, pDict, pValAlias, &fMean); if (iRet != NX_OK) { - sprintf(pBueffel, "WARNING: failed to write %s", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: failed to write %s", pName); SCWrite(pCon, pBueffel, eWarning); } if (pStdDevAlias) { iRet = NXDputalias(hfil, pDict, pStdDevAlias, &fStdDev); if (iRet != NX_OK) { - sprintf(pBueffel, "WARNING: failed to write %s standard deviation", + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: failed to write %s standard deviation", pName); SCWrite(pCon, pBueffel, eWarning); } @@ -275,7 +275,7 @@ int SNXSPutDrivable(SicsInterp * pSics, SConnection * pCon, if (pDriv) { /* it is drivable */ fVal = pDriv->GetValue(pCom->pData, pCon); } else { - sprintf(pBueffel, "ERROR: %s is not driveable, not written", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is not driveable, not written", pName); SCWrite(pCon, pBueffel, eError); return 0; } @@ -284,7 +284,7 @@ int SNXSPutDrivable(SicsInterp * pSics, SConnection * pCon, /* whatever it was, write it, even if it is shit */ iRet = NXDputalias(hfil, pDict, pAlias, &fVal); if (iRet != NX_OK) { - sprintf(pBueffel, "WARNING: failed to write %s", pName); + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: failed to write %s", pName); SCWrite(pCon, pBueffel, eWarning); return 0; } diff --git a/o2t.c b/o2t.c index 0ed68801..ace981e0 100644 --- a/o2t.c +++ b/o2t.c @@ -301,7 +301,7 @@ int CreateO2T(SConnection * pCon, SicsInterp * pSics, void *pData, /* make O2T */ self = MakeO2T(argv[2], argv[3], pSics); if (!self) { - sprintf(pBueffel, "ERROR: no Memory or %s %s are no valid motor names", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: no Memory or %s %s are no valid motor names", argv[2], argv[3]); SCWrite(pCon, pBueffel, eError); return 0; @@ -310,7 +310,7 @@ int CreateO2T(SConnection * pCon, SicsInterp * pSics, void *pData, /* install command */ iRet = AddCommand(pSics, argv[1], DummyO2T, DeleteO2T, self); 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); return 0; } diff --git a/obpar.c b/obpar.c index fe246344..c89ef725 100644 --- a/obpar.c +++ b/obpar.c @@ -169,21 +169,21 @@ int ObParSet(ObPar * self, char *obname, char *name, float fVal, /* find the parameter */ pPar = ObParFind(self, name); if (pPar == NULL) { - sprintf(pBueffel, "ERROR: %s.%s parameter not found", obname, name); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s.%s parameter not found", obname, name); SCWrite(pCon, pBueffel, eError); return 0; } /* are we running? */ if(DevExecLevelRunning(pServ->pExecutor, RUNDRIVE)){ - sprintf(pBueffel, "ERROR: Cannot change parameter while running"); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Cannot change parameter while running"); SCWrite(pCon, pBueffel, eError); return 0; } /* check permission */ if (!SCMatchRights(pCon, pPar->iCode)) { - sprintf(pBueffel, "ERROR: Insufficient privilege to change %s.%s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Insufficient privilege to change %s.%s", obname, name); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/ofac.c b/ofac.c index 958f2198..d87e3054 100644 --- a/ofac.c +++ b/ofac.c @@ -152,7 +152,7 @@ static int IFServerOption(SConnection * pCon, SicsInterp * pSics, /* test if sufficient arguments */ if (argc < 3) { - sprintf(pBueffel, "Syntax: %s name value ", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "Syntax: %s name value ", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -181,7 +181,7 @@ static int PWSicsUser(SConnection * pCon, SicsInterp * pSics, void *pData, /* analyse commandlist */ pList = SplitArguments(argc - 1, &argv[1]); if ((!pList) || (!pList->pNext) || (!pList->pNext->pNext)) { - sprintf(pBueffel, "Invalid Passwd Entry ::\n %s %s %s\n", argv[1], + snprintf(pBueffel,sizeof(pBueffel)-1, "Invalid Passwd Entry ::\n %s %s %s\n", argv[1], argv[2], argv[3]); SCWrite(pCon, pBueffel, eError); DeleteTokenList(pList); @@ -487,7 +487,7 @@ int InitObjectCommands(pServer pServ, char *file) /* evaluate the file */ - sprintf(pBueffel, "fileeval %s", file); + snprintf(pBueffel,sizeof(pBueffel)-1, "fileeval %s", file); iRet = InterpExecute(pSics, pCon, pBueffel); /* done */ diff --git a/optimise.c b/optimise.c index d17f55ba..c21dbfd2 100644 --- a/optimise.c +++ b/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; } diff --git a/perfmon.c b/perfmon.c index 82bddcd1..d07554ab 100644 --- a/perfmon.c +++ b/perfmon.c @@ -126,7 +126,7 @@ int IncrementPerfMon(pPerfMon self) self->tLast = tCurrent; self->tTarget = tCurrent + self->iInteg; if (self->iLog) { - sprintf(pBueffel, "PerfMon = %f", self->fCPS); + snprintf(pBueffel,sizeof(pBueffel)-1, "PerfMon = %f", self->fCPS); SICSLogWrite(pBueffel, eValue); } InvokeCallBack(self->pCall, VALUECHANGE, &self->fCPS); @@ -158,7 +158,7 @@ static int InterestCallback(int iEvent, void *pEvent, void *pUser) return -1; } - sprintf(pBueffel, "Performance = %f", *fPos); + snprintf(pBueffel,sizeof(pBueffel)-1, "Performance = %f", *fPos); SCWrite(pCon, pBueffel, eValue); return 1; } @@ -184,7 +184,7 @@ int PerfMonWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, argtolower(argc, argv); if (argc < 2) { /* print value */ - sprintf(pBueffel, "Performance = %f", self->fCPS); + snprintf(pBueffel,sizeof(pBueffel)-1, "Performance = %f", self->fCPS); SCWrite(pCon, pBueffel, eValue); return 1; } diff --git a/protocol.c b/protocol.c index 71f58e13..dcaeaf91 100644 --- a/protocol.c +++ b/protocol.c @@ -236,7 +236,7 @@ static int ProtocolOptions(SConnection * pCon, pProtocol pPro) int i; char pBuffer[80]; for (i = 0; i < pPro->iNumPros; i++) { - sprintf(pBuffer, "Protocol[%d] = %s", i, pPro->pProList[i]); + snprintf(pBuffer,sizeof(pBuffer)-1, "Protocol[%d] = %s", i, pPro->pProList[i]); SCWrite(pCon, pBuffer, eValue); } return 1; @@ -498,7 +498,7 @@ int SCWriteSycamore(SConnection * pCon, char *pBuffer, int iOut) } else { iRet = 0; } - sprintf(pBueffel, "Next line intended for socket: %d", iRet); + snprintf(pBueffel,sizeof(pBueffel)-1, "Next line intended for socket: %d", iRet); SICSLogWrite(pBueffel, eInternal); SICSLogWrite(pBuffer, iOut); @@ -529,9 +529,9 @@ int SCWriteSycamore(SConnection * pCon, char *pBuffer, int iOut) pMsgString = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH); pBueffel[0] = '\0'; - sprintf(pBueffel, "[con%4.4d:", (int) pCon->ident); /* field 1: connID */ + snprintf(pBueffel,sizeof(pBueffel)-1, "[con%4.4d:", (int) pCon->ident); /* field 1: connID */ DynStringConcat(pMsg, pBueffel); - sprintf(pBueffel, "t%6.6d:", (int) taskID); /* field 2: taskID */ + snprintf(pBueffel,sizeof(pBueffel)-1, "t%6.6d:", (int) taskID); /* field 2: taskID */ DynStringConcat(pMsg, pBueffel); /* deviceID */ DynStringConcat(pMsg, comCon.deviceID); @@ -698,7 +698,7 @@ int SCWriteJSON_String(SConnection * pCon, char *pBuffer, int iOut) } else { iRet = 0; } - sprintf(pBueffel, "Next line intended for socket: %d", iRet); + snprintf(pBueffel,sizeof(pBueffel)-1, "Next line intended for socket: %d", iRet); SICSLogWrite(pBueffel, eInternal); SICSLogWrite(pBuffer, iOut); diff --git a/reflist.c b/reflist.c index 710be214..b63b4e68 100644 --- a/reflist.c +++ b/reflist.c @@ -339,7 +339,7 @@ static int ShowCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode, } child = row->child; - strcpy(data,par[0]->value.v.text); + strncpy(data,par[0]->value.v.text,1023); strcat(data," 1"); while(child != NULL){ snprintf(num,20," %f",child->value.v.doubleValue); diff --git a/rs232controller.c b/rs232controller.c index 7568d705..3a4a2298 100644 --- a/rs232controller.c +++ b/rs232controller.c @@ -587,10 +587,10 @@ static void encodeTerminator(char *result, char *terminator) result[0] = '\0'; } len = strlen(terminator); - sprintf(pBuffer, "0x%x", (int) terminator[0]); + snprintf(pBuffer,sizeof(pBuffer)-1, "0x%x", (int) terminator[0]); strcpy(result, pBuffer); for (i = 1; i < len; i++) { - sprintf(pBuffer, "0x%x", (int) terminator[i]); + snprintf(pBuffer,sizeof(pBuffer)-1, "0x%x", (int) terminator[i]); strcat(result, pBuffer); } } @@ -646,7 +646,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics, check for arguments */ if (argc < 2) { - sprintf(pError, "ERROR: insufficient no of arguments to %s", argv[0]); + snprintf(pError,sizeof(pError)-1, "ERROR: insufficient no of arguments to %s", argv[0]); SCWrite(pCon, pError, eError); return 0; } @@ -662,7 +662,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics, return 1; } else { encodeTerminator(pBuffer, self->sendTerminator); - sprintf(pError, "%s.sendTerminator = \"%s\"", argv[0], pBuffer); + snprintf(pError,sizeof(pError)-1, "%s.sendTerminator = \"%s\"", argv[0], pBuffer); SCWrite(pCon, pError, eValue); return 1; } @@ -676,7 +676,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics, SCSendOK(pCon); return 1; } else { - sprintf(pError, "%s.Timeout = %d", argv[0], self->timeout); + snprintf(pError,sizeof(pError)-1, "%s.Timeout = %d", argv[0], self->timeout); SCWrite(pCon, pError, eValue); return 1; } @@ -694,7 +694,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics, return 1; } else { encodeTerminator(pBuffer, self->replyTerminator); - sprintf(pError, "%s.replyTerminator = \"%s\"", argv[0], pBuffer); + snprintf(pError,sizeof(pError)-1, "%s.replyTerminator = \"%s\"", argv[0], pBuffer); SCWrite(pCon, pError, eValue); return 1; } @@ -786,7 +786,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics, } else if (strcmp(argv[1], "init") == 0) { iRet = initRS232(self); if (iRet != 1) { - sprintf(pError, + snprintf(pError,sizeof(pError)-1, "ERROR: reinitializing connection to %s at %d failed", self->pHost, self->iPort); SCWrite(pCon, pError, eError); @@ -796,7 +796,7 @@ int RS232Action(SConnection * pCon, SicsInterp * pSics, return 1; } } else { - sprintf(pError, "ERROR: %s does not understand %s", argv[0], argv[1]); + snprintf(pError,sizeof(pError)-1, "ERROR: %s does not understand %s", argv[0], argv[1]); SCWrite(pCon, pError, eError); return 0; } @@ -830,7 +830,7 @@ int RS232Factory(SConnection * pCon, SicsInterp * pSics, status = initRS232(pNew); if (status != 1) { - sprintf(pError, "ERROR: failed to connect to %s at port %d", + snprintf(pError,sizeof(pError)-1, "ERROR: failed to connect to %s at port %d", pNew->pHost, pNew->iPort); SCWrite(pCon, pError, eError); } @@ -840,7 +840,7 @@ int RS232Factory(SConnection * pCon, SicsInterp * pSics, */ iRet = AddCommand(pSics, argv[1], RS232Action, KillAndFreeRS232, pNew); if (!iRet) { - sprintf(pError, "ERROR: duplicate command %s not created", argv[1]); + snprintf(pError,sizeof(pError)-1, "ERROR: duplicate command %s not created", argv[1]); SCWrite(pCon, pError, eError); KillAndFreeRS232(pNew); return 0; diff --git a/scan.c b/scan.c index 8c0e9545..a69ea5c7 100644 --- a/scan.c +++ b/scan.c @@ -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; diff --git a/scanvar.c b/scanvar.c index a9b48416..f6a9a74d 100644 --- a/scanvar.c +++ b/scanvar.c @@ -60,7 +60,7 @@ pVarEntry MakeScanVar(SicsInterp * pSics, SConnection * pCon, char } /* got everything, fill in the VarEntry structure */ - strcpy(pVar->Name, name); + strncpy(pVar->Name, name,131); pVar->pInter = pDriv; pVar->pObject = pData; pVar->fStart = start; @@ -113,7 +113,7 @@ pVarEntry MakeLogVar(SicsInterp * pSics, SConnection * pCon, char *name) } /* got everything, fill in the VarEntry structure */ - strcpy(pVar->Name, name); + strncpy(pVar->Name, name,131); pVar->pInter = pDriv; pVar->pObject = pData; pVar->logVar = 1; diff --git a/script.c b/script.c index b3ec102f..e211ac1a 100644 --- a/script.c +++ b/script.c @@ -122,7 +122,7 @@ int SetSICSInterrupt(SConnection * pCon, SicsInterp * pSics, void *pData, strtolower(argv[1]); iInt = Text2Interrupt(argv[1]); if (iInt < 0) { - sprintf(pBueffel, "ERROR: %s not recognized as Interrupt code", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not recognized as Interrupt code", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; @@ -179,7 +179,7 @@ int SetSICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBueffel, "ERROR: %s not recognized as status code", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s not recognized as status code", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -273,28 +273,28 @@ int SICSBounds(SConnection * pCon, SicsInterp * pSics, void *pData, /* argv[1] should be drivable */ pCom = FindCommand(pSics, argv[1]); if (!pCom) { - sprintf(pBueffel, "ERROR: %s is no Sics Object", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no Sics Object", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } pDum = (Dummy *) pCom->pData; if (!pDum) { - sprintf(pBueffel, "ERROR: %s is no valid Sics Object", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no valid Sics Object", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } pInt = pDum->pDescriptor->GetInterface(pDum, DRIVEID); if (!pInt) { - sprintf(pBueffel, "ERROR: %s is not drivable!", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is not drivable!", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } /* argv[2] should be a numeric */ if (!isNum(argv[2])) { - sprintf(pBueffel, "ERROR: %s is not a number!", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is not a number!", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -335,14 +335,14 @@ int SICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData, /* argv[1] should be drivable */ pCom = FindCommand(pSics, argv[1]); if (!pCom) { - sprintf(pBueffel, "ERROR: %s is no Sics Object", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no Sics Object", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } pDum = (Dummy *) pCom->pData; if (!pDum) { - sprintf(pBueffel, "ERROR: %s is no valid Sics Object", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is no valid Sics Object", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -351,16 +351,16 @@ int SICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData, pCInt = pDum->pDescriptor->GetInterface(pDum, COUNTID); if (pDInt) { iRet = pDInt->CheckStatus(pDum, pCon); - sprintf(pBueffel, "%d", iRet); + snprintf(pBueffel,sizeof(pBueffel)-1, "%d", iRet); SCWrite(pCon, pBueffel, eValue); return 1; } else if (pCInt) { iRet = pCInt->CheckCountStatus(pDum, pCon); - sprintf(pBueffel, "%d", iRet); + snprintf(pBueffel,sizeof(pBueffel)-1, "%d", iRet); SCWrite(pCon, pBueffel, eValue); return 1; } else { - sprintf(pBueffel, "ERROR: %s is neither drivable nor countable", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s is neither drivable nor countable", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/sel2.c b/sel2.c index 01652c04..8328c396 100644 --- a/sel2.c +++ b/sel2.c @@ -268,7 +268,7 @@ long tim; int sts; long err; char cmd[20] = "TIM "; - sprintf(&cmd + 4, "%5u\0", tim); + snprintf(&cmd + 4,sizeof(&cmd + 4)-1, "%5u\0", tim); sts = sele_write(cmd); if (sele_test_echo(&cmd, 3) != OK) lib$stop(-1); @@ -376,7 +376,7 @@ int rpm; print_error(fs, "nominal value within inhibited range"); return; } - sprintf(&s_dat + 4, "%5u", rpm); + snprintf(&s_dat + 4,sizeof(&s_dat + 4)-1, "%5u", rpm); sts = sele_write(s_dat); if (sele_test_echo(&cmd, 3) != OK) lib$stop(-1); diff --git a/selector.c b/selector.c index 49d2263e..023ea3ea 100644 --- a/selector.c +++ b/selector.c @@ -210,7 +210,7 @@ int MonoInit(SConnection * pCon, SicsInterp * pSics, void *pData, argtolower(argc, argv); pList = SplitArguments(argc, argv); if (!pList) { - sprintf(pBueffel, "ERROR: parsing arguments in %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: parsing arguments in %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -218,7 +218,7 @@ int MonoInit(SConnection * pCon, SicsInterp * pSics, void *pData, /* advance and search name */ pCurrent = pList->pNext; if (!pCurrent) { - sprintf(pBueffel, "ERRROR: Insufficient number of arguments to %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERRROR: Insufficient number of arguments to %s", argv[0]); SCWrite(pCon, pBueffel, eError); goto end; @@ -228,7 +228,7 @@ int MonoInit(SConnection * pCon, SicsInterp * pSics, void *pData, /* advance and find Type string */ pCurrent = pCurrent->pNext; if (!pCurrent) { - sprintf(pBueffel, "ERRROR: Insufficient number of arguments to %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERRROR: Insufficient number of arguments to %s", argv[0]); SCWrite(pCon, pBueffel, eError); goto end; @@ -238,14 +238,14 @@ int MonoInit(SConnection * pCon, SicsInterp * pSics, void *pData, /* advance and find Theta motor */ pCurrent = pCurrent->pNext; if (!pCurrent) { - sprintf(pBueffel, "ERRROR: Insufficient number of arguments to %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERRROR: Insufficient number of arguments to %s", argv[0]); SCWrite(pCon, pBueffel, eError); goto end; } pTheta = FindMotor(pSics, pCurrent->text); if (!pTheta) { - sprintf(pBueffel, "ERROR: Cannot find motor %s for driving Theta", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Cannot find motor %s for driving Theta", pCurrent->text); SCWrite(pCon, pBueffel, eError); goto end; @@ -254,14 +254,14 @@ int MonoInit(SConnection * pCon, SicsInterp * pSics, void *pData, /* advance and find Two Theta motor */ pCurrent = pCurrent->pNext; if (!pCurrent) { - sprintf(pBueffel, "ERRROR: Insufficient number of arguments to %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERRROR: Insufficient number of arguments to %s", argv[0]); SCWrite(pCon, pBueffel, eError); goto end; } pTwoTheta = FindMotor(pSics, pCurrent->text); if (!pTwoTheta) { - sprintf(pBueffel, "ERROR: Cannot find motor %s for driving Two Theta", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Cannot find motor %s for driving Two Theta", pCurrent->text); SCWrite(pCon, pBueffel, eError); goto end; @@ -273,7 +273,7 @@ int MonoInit(SConnection * pCon, SicsInterp * pSics, void *pData, if (pCurrent) { pBend1 = FindMotor(pSics, pCurrent->text); if (!pBend1) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Cannot find motor %s for driving vertical bender", pCurrent->text); SCWrite(pCon, pBueffel, eError); @@ -288,7 +288,7 @@ int MonoInit(SConnection * pCon, SicsInterp * pSics, void *pData, if (pCurrent) { pBend2 = FindMotor(pSics, pCurrent->text); if (!pBend2) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Cannot find motor %s for driving horizontal bender", pCurrent->text); SCWrite(pCon, pBueffel, eError); @@ -310,7 +310,7 @@ end: AddCommand(pSics, pName, MonoAction, DeleteSelector, (void *) pRes); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command %s not created", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate command %s not created", argv[2]); SCWrite(pCon, pBueffel, eError); DeleteTokenList(pList); @@ -336,28 +336,28 @@ static void MonoList(pSicsSelector self, SConnection * pCon) /* print known parameters */ iLen = ObParLength(self->pParams); - sprintf(pBueffel, "Parameter Listing for %s\n", self->name); + snprintf(pBueffel,sizeof(pBueffel)-1, "Parameter Listing for %s\n", self->name); 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->pParams[i].name, self->pParams[i].fVal); SCWrite(pCon, pBueffel, eValue); } /* print motornames as well */ - sprintf(pBueffel, "%s.ThetaMotor = %s\n", self->name, + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.ThetaMotor = %s\n", self->name, self->pTheta->name); SCWrite(pCon, pBueffel, eValue); - sprintf(pBueffel, "%s.TwoThetaMotor = %s\n", self->name, + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.TwoThetaMotor = %s\n", self->name, self->pTwoTheta->name); SCWrite(pCon, pBueffel, eValue); if (self->pBend1) { - sprintf(pBueffel, "%s.VerticalBenderMotor = %s\n", self->name, + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.VerticalBenderMotor = %s\n", self->name, self->pBend1->name); SCWrite(pCon, pBueffel, eValue); } if (self->pBend2) { - sprintf(pBueffel, "%s.HorizontalBenderMotor = %s\n", self->name, + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.HorizontalBenderMotor = %s\n", self->name, self->pBend2->name); SCWrite(pCon, pBueffel, eValue); } @@ -392,7 +392,7 @@ int MonoAction(SConnection * pCon, SicsInterp * pSics, void *pData, argtolower(argc, argv); pList = SplitArguments(argc, argv); if (!pList) { - sprintf(pBueffel, "ERROR: parsing arguments in %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: parsing arguments in %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -401,7 +401,7 @@ int MonoAction(SConnection * pCon, SicsInterp * pSics, void *pData, /* now we can have "list" or a parametername */ /* check for list first */ if (!pCurrent) { - 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); goto end; @@ -426,7 +426,7 @@ int MonoAction(SConnection * pCon, SicsInterp * pSics, void *pData, } else if (pCurrent->Type == eInt) { fVal = (float) pCurrent->iVal; } else { - sprintf(pBueffel, "ERROR: Illegal parameter %s given to %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Illegal parameter %s given to %s", pCurrent->text, argv[0]); SCWrite(pCon, pBueffel, eError); goto end; @@ -437,12 +437,12 @@ int MonoAction(SConnection * pCon, SicsInterp * pSics, void *pData, pPar = ObParFind(pSelf->pParams, pName); if (!pPar) { - sprintf(pBueffel, "ERROR: Parameter %s not found in %s", pName, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Parameter %s not found in %s", pName, argv[0]); SCWrite(pCon, pBueffel, eError); goto end; } else { - sprintf(pBueffel, "%s.%s = %f", argv[0], pName, pPar->fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.%s = %f", argv[0], pName, pPar->fVal); SCWrite(pCon, pBueffel, eValue); iRet = 1; DeleteTokenList(pList); @@ -514,7 +514,7 @@ int MonoLimits(pSicsSelector self, float fWaveLength, /* get Position */ sNeu = CalculatePosition(self, fWaveLength); if (sNeu.fTheta > 900.) { /* invalid wavelength or energy */ - sprintf(pBueffel, "ERROR: Invalid wavelength or energy to high: %f", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Invalid wavelength or energy to high: %f", fWaveLength); strncpy(error, pBueffel, iErrLen - 1); return 0; @@ -596,7 +596,7 @@ int MonoRun(pSicsSelector self, SConnection * pCon, float fWaveLength) /* Check authorisation */ if (!SCMatchRights(pCon, (int) ObVal(self->pParams, RIGHTS))) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: You are not authorised to move the monochromator %s", self->name); SCWrite(pCon, pBueffel, eError); @@ -606,7 +606,7 @@ int MonoRun(pSicsSelector self, SConnection * pCon, float fWaveLength) /* get Position */ sNeu = CalculatePosition(self, fWaveLength); if (sNeu.fTheta > 900.) { /* invalid wavelength or energy */ - sprintf(pBueffel, "ERROR: Invalid wavelength or energy to high: %f", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: Invalid wavelength or energy to high: %f", fWaveLength); return 0; } @@ -711,7 +711,7 @@ float GetMonoPosition(pSicsSelector self, SConnection * pCon) /* get the two positions */ iRet = MotorGetSoftPosition(self->pTheta, pCon, &fTheta); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot read Theta motor for monochromator %s\n", self->name); SCWrite(pCon, pBueffel, eError); @@ -719,7 +719,7 @@ float GetMonoPosition(pSicsSelector self, SConnection * pCon) } iRet = MotorGetSoftPosition(self->pTwoTheta, pCon, &fTwoTheta); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot read TwoTheta motor for monochromator %s\n", self->name); SCWrite(pCon, pBueffel, eError); @@ -731,7 +731,7 @@ float GetMonoPosition(pSicsSelector self, SConnection * pCon) if (fVal < 0.) fVal = -fVal; if (fVal > 0.01) { - sprintf(pBueffel, "WARNING: monochromator %s out of sync by %f\n", + snprintf(pBueffel,sizeof(pBueffel)-1, "WARNING: monochromator %s out of sync by %f\n", self->name, fVal); SCWrite(pCon, pBueffel, eWarning); } @@ -753,7 +753,7 @@ int GetMonoPositions(pSicsSelector self, SConnection * pCon, iRet = MotorGetSoftPosition(self->pTheta, pCon, fTh); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot read Theta motor for monochromator %s\n", self->name); SCWrite(pCon, pBueffel, eError); @@ -761,7 +761,7 @@ int GetMonoPositions(pSicsSelector self, SConnection * pCon, } iRet = MotorGetSoftPosition(self->pTwoTheta, pCon, f2TH); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot read TwoTheta motor for monochromator %s\n", self->name); SCWrite(pCon, pBueffel, eError); @@ -771,7 +771,7 @@ int GetMonoPositions(pSicsSelector self, SConnection * pCon, if (self->pBend1) { iRet = MotorGetSoftPosition(self->pBend1, pCon, fB1); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot read vertical bender motor for monochromator %s\n", self->name); SCWrite(pCon, pBueffel, eError); @@ -781,7 +781,7 @@ int GetMonoPositions(pSicsSelector self, SConnection * pCon, if (self->pBend2) { iRet = MotorGetSoftPosition(self->pBend2, pCon, fB2); if (!iRet) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: cannot read horizontal bender motor for monochromator %s\n", self->name); SCWrite(pCon, pBueffel, eError); diff --git a/selvar.c b/selvar.c index 883ac172..96086ad9 100644 --- a/selvar.c +++ b/selvar.c @@ -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; } diff --git a/servlog.c b/servlog.c index 0fddac65..5935a817 100644 --- a/servlog.c +++ b/servlog.c @@ -124,7 +124,7 @@ int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData, /* check no af args */ if (argc < 2) { - sprintf(pBueffel, "Insufficient number of argumenst to %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient number of argumenst to %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -159,7 +159,7 @@ int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData, i++; } if (i > iNoCodes) { - sprintf(pBueffel, "OutPutCode %s not recognized in %s", argv[1], + snprintf(pBueffel,sizeof(pBueffel)-1, "OutPutCode %s not recognized in %s", argv[1], argv[0]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/sicsdata.c b/sicsdata.c index 1d31d353..313687cc 100644 --- a/sicsdata.c +++ b/sicsdata.c @@ -336,7 +336,7 @@ static int putFloat(pSICSData self, int argc, char *argv[], status = Tcl_GetDouble(InterpGetTcl(pSics), argv[1], &dVal); if (status != TCL_OK) { snprintf(buffer, 255, - "ERROR: faiuld to convert putfloat value %s to float", + "ERROR: faild to convert putfloat value %s to float", argv[1]); SCWrite(pCon, buffer, eError); return 0; diff --git a/sicvar.c b/sicvar.c index df125971..5017a660 100644 --- a/sicvar.c +++ b/sicvar.c @@ -58,20 +58,20 @@ static int VarSave(void *pData, char *name, FILE * fd) if (pVar->iLock || pVar->iAccessCode == usInternal) { return 1; } - sprintf(pBueffel, "# Variable %s\n", name); + snprintf(pBueffel,sizeof(pBueffel)-1, "# Variable %s\n", name); switch (pVar->eType) { case veText: - sprintf(pBueffel, "%s %s\n", name, pVar->text); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s\n", name, pVar->text); break; case veInt: - sprintf(pBueffel, "%s %d\n", name, pVar->iVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %d\n", name, pVar->iVal); break; case veFloat: - sprintf(pBueffel, "%s %f\n", name, pVar->fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %f\n", name, pVar->fVal); break; } fputs(pBueffel, fd); - sprintf(pBueffel, "%s setAccess %d\n", name, pVar->iAccessCode); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s setAccess %d\n", name, pVar->iAccessCode); fputs(pBueffel, fd); return 1; } @@ -150,7 +150,7 @@ int VarFactory(SConnection * pCon, SicsInterp * pSics, void *pData, /* check if enough commands */ argtolower(argc, argv); if (argc < 4) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient no of args to %s, Usage: %s name type accescode", argv[0], argv[0]); SCWrite(pCon, pBueffel, eError); @@ -177,7 +177,7 @@ int VarFactory(SConnection * pCon, SicsInterp * pSics, void *pData, eType = veFloat; break; default: - sprintf(pBueffel, "Var %s Type --> %s <-- not recognized", + snprintf(pBueffel,sizeof(pBueffel)-1, "Var %s Type --> %s <-- not recognized", argv[1], argv[2]); SCWrite(pCon, pBueffel, eError); return 0; @@ -186,7 +186,7 @@ int VarFactory(SConnection * pCon, SicsInterp * pSics, void *pData, /* argv[3] must be the access code, check that now */ i = decodeSICSPriv(argv[3]); if (i < 0) { - sprintf(pBueffel, " %s access code %s not recognized", + snprintf(pBueffel,sizeof(pBueffel)-1, " %s access code %s not recognized", argv[1], argv[3]); SCWrite(pCon, pBueffel, eError); return 0; @@ -195,13 +195,13 @@ int VarFactory(SConnection * pCon, SicsInterp * pSics, void *pData, /* now we can actually install the variable */ pRes = VarCreate(i, eType, argv[1]); if (!pRes) { - sprintf(pBueffel, "Memory Error creating variable %s", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "Memory Error creating variable %s", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = AddCommand(pSics, argv[1], VarWrapper, (KillFunc) VarKill, pRes); 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); VarKill(pRes); return 0; @@ -354,19 +354,19 @@ static int VarInterestCallback(int iEvent, void *pEvent, void *pUser) switch (pVar->eType) { case veInt: VarGetInt(pVar, &iVal); - sprintf(pBueffel, "%s = %d", pVar->name, iVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %d", pVar->name, iVal); SCWrite(pCon, pBueffel, eValue); status = 1; break; case veFloat: VarGetFloat(pVar, &fVal); - sprintf(pBueffel, "%s = %f", pVar->name, fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %f", pVar->name, fVal); SCWrite(pCon, pBueffel, eValue); status = 1; break; case veText: VarGetText(pVar, &pText); - sprintf(pBueffel, "%s = %s", pVar->name, pText); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %s", pVar->name, pText); SCWrite(pCon, pBueffel, eValue); if (pText) { free(pText); @@ -447,19 +447,19 @@ int VarWrapper(SConnection * pCon, SicsInterp * pInterp, void *pData, switch (eTyp) { case veInt: VarGetInt(pVar, &iVal); - sprintf(pBueffel, "%s = %d", argv[0], iVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %d", argv[0], iVal); SCWrite(pCon, pBueffel, eValue); DeleteTokenList(pList); return 1; case veFloat: VarGetFloat(pVar, &fVal); - sprintf(pBueffel, "%s = %f", argv[0], fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %f", argv[0], fVal); SCWrite(pCon, pBueffel, eValue); DeleteTokenList(pList); return 1; case veText: VarGetText(pVar, &pText); - sprintf(pBueffel, "%s = %s", argv[0], pText); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %s", argv[0], pText); SCWrite(pCon, pBueffel, eValue); if (pText) { free(pText); @@ -554,7 +554,7 @@ int VarWrapper(SConnection * pCon, SicsInterp * pInterp, void *pData, if (pCurrent) { /* is it locked ? */ if (pVar->iLock) { - sprintf(pBueffel, "ERROR: variable %s is configured locked!", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: variable %s is configured locked!", argv[0]); SCWrite(pCon, pBueffel, eError); DeleteTokenList(pList); diff --git a/simchop.c b/simchop.c index 08c508f0..430f6e86 100644 --- a/simchop.c +++ b/simchop.c @@ -145,11 +145,11 @@ static int SDGetPar(pCodri self, char *parname, char *pBuffer, int iBufLen) /* are we busy driving something? */ if (time(NULL) < pPriv->tTarget) { if (strcmp(parname, "speed") == 0) { - sprintf(pBueffel, "%f", pPriv->fRot - 1.); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", pPriv->fRot - 1.); } else if (strcmp(parname, "phase") == 0) { - sprintf(pBueffel, "%f", pPriv->fPhase - 1.); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", pPriv->fPhase - 1.); } else if (strcmp(parname, "ratio") == 0) { - sprintf(pBueffel, "%f", pPriv->fRatio - 1.); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", pPriv->fRatio - 1.); } else { pPriv->iError = UNKNOWNPAR; return 0; @@ -160,11 +160,11 @@ static int SDGetPar(pCodri self, char *parname, char *pBuffer, int iBufLen) /* all normal */ if (strcmp(parname, "speed") == 0) { - sprintf(pBueffel, "%f", pPriv->fRot); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", pPriv->fRot); } else if (strcmp(parname, "phase") == 0) { - sprintf(pBueffel, "%f", pPriv->fPhase); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", pPriv->fPhase); } else if (strcmp(parname, "ratio") == 0) { - sprintf(pBueffel, "%f", pPriv->fRatio); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", pPriv->fRatio); } else { pPriv->iError = UNKNOWNPAR; return 0; diff --git a/sinqhmtcl.c b/sinqhmtcl.c index cac4ffe7..6c0e5255 100644 --- a/sinqhmtcl.c +++ b/sinqhmtcl.c @@ -128,24 +128,24 @@ static int DAQAction(ClientData pData, Tcl_Interp * interp, if (iBin == 1) { /* char's */ pPtr = (char *) pBuffer; for (i = 0; i < PaRes.Arg[2].iVal; i++, pPtr++) { - sprintf(pNumber, "%d", (int) *pPtr); - sprintf(pIndex, "%d", i); + snprintf(pNumber,sizeof(pNumber)-1, "%d", (int) *pPtr); + snprintf(pIndex,sizeof(pIndex)-1, "%d", i); Tcl_SetVar2(interp, argv[5], pIndex, pNumber, TCL_LEAVE_ERR_MSG); } free(pBuffer); } else if (iBin == 2) { pPtr16 = (SQint16 *) pBuffer; for (i = 0; i < PaRes.Arg[2].iVal; i++, pPtr16++) { - sprintf(pNumber, "%d", (int) *pPtr16); - sprintf(pIndex, "%d", i); + snprintf(pNumber,sizeof(pNumber)-1, "%d", (int) *pPtr16); + snprintf(pIndex,sizeof(pIndex)-1, "%d", i); Tcl_SetVar2(interp, argv[5], pIndex, pNumber, TCL_LEAVE_ERR_MSG); } free(pBuffer); } else if (iBin == 4) { pPtr32 = (SQint32 *) pBuffer; for (i = 0; i < PaRes.Arg[2].iVal; i++, pPtr32++) { - sprintf(pNumber, "%d", (int) *pPtr32); - sprintf(pIndex, "%d", i); + snprintf(pNumber,sizeof(pNumber)-1, "%d", (int) *pPtr32); + snprintf(pIndex,sizeof(pIndex)-1, "%d", i); Tcl_SetVar2(interp, argv[5], pIndex, pNumber, TCL_LEAVE_ERR_MSG); } free(pBuffer); @@ -179,7 +179,7 @@ static int DAQAction(ClientData pData, Tcl_Interp * interp, if (iBin == 1) { pPtr = pBuffer; for (i = 0; i < PaRes.Arg[3].iVal; i++, pPtr++) { - sprintf(pIndex, "%d", i); + snprintf(pIndex,sizeof(pIndex)-1, "%d", i); pVal = Tcl_GetVar2(interp, argv[5], pIndex, TCL_LEAVE_ERR_MSG); if (pVal) { Tcl_GetInt(interp, pVal, &iVal); @@ -189,7 +189,7 @@ static int DAQAction(ClientData pData, Tcl_Interp * interp, } else if (iBin == 2) { pPtr16 = pBuffer; for (i = 0; i < PaRes.Arg[3].iVal; i++, pPtr16++) { - sprintf(pIndex, "%d", i); + snprintf(pIndex,sizeof(pIndex)-1, "%d", i); pVal = Tcl_GetVar2(interp, argv[5], pIndex, TCL_LEAVE_ERR_MSG); if (pVal) { Tcl_GetInt(interp, pVal, &iVal); @@ -199,7 +199,7 @@ static int DAQAction(ClientData pData, Tcl_Interp * interp, } else if (iBin == 4) { pPtr32 = pBuffer; for (i = 0; i < PaRes.Arg[2].iVal; i++, pPtr32++) { - sprintf(pIndex, "%d", i); + snprintf(pIndex,sizeof(pIndex)-1, "%d", i); pVal = Tcl_GetVar2(interp, argv[5], pIndex, TCL_LEAVE_ERR_MSG); if (pVal) { Tcl_GetInt(interp, pVal, &iVal); @@ -478,7 +478,7 @@ static int ControlAction(ClientData pData, Tcl_Interp * interp, Tcl_AppendResult(interp, pBueffel, NULL); return TCL_ERROR; } - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "Mode = %d, DAQ = %d, Rank = %d, BinWidth = %d, Length = %d, NoClients = %d", iMode, iDaq, iRank, iBin, iLength, iClients); Tcl_AppendResult(interp, pBueffel, NULL); diff --git a/splitter.c b/splitter.c index 436b106c..1ef55aa1 100644 --- a/splitter.c +++ b/splitter.c @@ -157,8 +157,8 @@ TokenList *SplitText(char *pLine) eWhat = eeText; } else { i = 0; - while (!isEnd(*pChar)) { - pBueffel[i] = *pChar; + while (!isEnd(*pChar) && i < 250) { + pBueffel[i] = *pChar; i++; pChar++; } diff --git a/status.c b/status.c index 47f131a9..ab30cef0 100644 --- a/status.c +++ b/status.c @@ -194,7 +194,7 @@ static int StatusCallback(int iEvent, void *pEvent, void *pUser) return -1; } - sprintf(pBueffel, "status = %s", pText[(int) eCode]); + snprintf(pBueffel,sizeof(pBueffel)-1, "status = %s", pText[(int) eCode]); SCWrite(pCon, pBueffel, eLog); return 1; } @@ -263,7 +263,7 @@ int UserStatus(SConnection * pCon, SicsInterp * pSics, void *pData, } /* else just print value */ - sprintf(pBueffel, "status = %s", pText[(int) eCode]); + snprintf(pBueffel,sizeof(pBueffel)-1, "status = %s", pText[(int) eCode]); SCWrite(pCon, pBueffel, eValue); return 1; } diff --git a/statusfile.c b/statusfile.c index 622cb55d..ddcc0884 100644 --- a/statusfile.c +++ b/statusfile.c @@ -98,7 +98,7 @@ int BackupStatus(SConnection * pCon, SicsInterp * pSics, void *pData, motorSave = 0; else motorSave = 1; - sprintf(pBueffel, "New Value of motorSave= %d\n", motorSave); + snprintf(pBueffel,sizeof(pBueffel)-1, "New Value of motorSave= %d\n", motorSave); SCWrite(pCon, pBueffel, eValue); return 1; } else { @@ -107,7 +107,7 @@ int BackupStatus(SConnection * pCon, SicsInterp * pSics, void *pData, } if (!iRet) { - sprintf(pBueffel, "ERROR: could not open file %s\n", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: could not open file %s\n", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -232,7 +232,7 @@ int RestoreStatus(SConnection * pCon, SicsInterp * pSics, void *pData, if (argc < 2) { pFile = IFindOption(pSICSOptions, "statusfile"); if (pFile) { - sprintf(pBueffel, "%s", pFile); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s", pFile); } else { SCWrite(pCon, "ERROR: No filename given for backup, Aborted.", eError); @@ -250,7 +250,7 @@ int RestoreStatus(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } else { - sprintf(pBueffel, "%s", argv[1]); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s", argv[1]); } } diff --git a/stdscan.c b/stdscan.c index 0a2378b7..225d2512 100644 --- a/stdscan.c +++ b/stdscan.c @@ -94,25 +94,25 @@ void WriteTemplate(FILE * fd, FILE * temp, char *filename, pScanData pScan, /* find the variable */ pCom = FindCommand(pSics, pName); if (!pCom) { - sprintf(pError, "ERROR: variable %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s NOT found", pName); SCWrite(pCon, pError, eLogError); continue; } pVar = (pSicsVariable) pCom->pData; if (!pVar) { - sprintf(pError, "ERROR: variable %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s NOT found", pName); SCWrite(pCon, pError, eLogError); continue; } switch (pVar->eType) { case veFloat: - sprintf(pError, "%f", pVar->fVal); + snprintf(pError,sizeof(pError)-1, "%f", pVar->fVal); break; case veInt: - sprintf(pError, "%d", pVar->iVal); + snprintf(pError,sizeof(pError)-1, "%d", pVar->iVal); break; case veText: - sprintf(pError, "%s", pVar->text); + snprintf(pError,sizeof(pError)-1, "%s", pVar->text); break; } /* finally write */ @@ -134,19 +134,19 @@ void WriteTemplate(FILE * fd, FILE * temp, char *filename, pScanData pScan, /* find the variable */ pCom = FindCommand(pSics, pName); if (!pCom) { - sprintf(pError, "ERROR: variable %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s NOT found", pName); SCWrite(pCon, pError, eLogError); continue; } pDum = (pDummy) pCom->pData; if (!pDum) { - sprintf(pError, "ERROR: variable %s is NOT drivable", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s is NOT drivable", pName); SCWrite(pCon, pError, eLogError); continue; } pDriv = (pIDrivable) pDum->pDescriptor->GetInterface(pDum, DRIVEID); if (!pDriv) { - sprintf(pError, "ERROR: variable %s is NOT drivable", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s is NOT drivable", pName); SCWrite(pCon, pError, eLogError); continue; } @@ -169,7 +169,7 @@ void WriteTemplate(FILE * fd, FILE * temp, char *filename, pScanData pScan, /* find the motor */ pMot = FindMotor(pSics, pName); if (!pMot) { - sprintf(pError, "ERROR: motor %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: motor %s NOT found", pName); SCWrite(pCon, pError, eLogError); continue; } @@ -321,25 +321,25 @@ int WriteHeaderOld(pScanData self) /* find the variable */ pCom = FindCommand(self->pSics, pName); if (!pCom) { - sprintf(pError, "ERROR: variable %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s NOT found", pName); SCWrite(self->pCon, pError, eError); continue; } pVar = (pSicsVariable) pCom->pData; if (!pVar) { - sprintf(pError, "ERROR: variable %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s NOT found", pName); SCWrite(self->pCon, pError, eError); continue; } switch (pVar->eType) { case veFloat: - sprintf(pError, "%f", pVar->fVal); + snprintf(pError,sizeof(pError)-1, "%f", pVar->fVal); break; case veInt: - sprintf(pError, "%d", pVar->iVal); + snprintf(pError,sizeof(pError)-1, "%d", pVar->iVal); break; case veText: - sprintf(pError, "%s", pVar->text); + snprintf(pError,sizeof(pError)-1, "%s", pVar->text); break; } /* finally write */ @@ -361,19 +361,19 @@ int WriteHeaderOld(pScanData self) /* find the variable */ pCom = FindCommand(self->pSics, pName); if (!pCom) { - sprintf(pError, "ERROR: variable %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s NOT found", pName); SCWrite(self->pCon, pError, eError); continue; } pDum = (pDummy) pCom->pData; if (!pDum) { - sprintf(pError, "ERROR: variable %s is NOT drivable", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s is NOT drivable", pName); SCWrite(self->pCon, pError, eError); continue; } pDriv = (pIDrivable) pDum->pDescriptor->GetInterface(pDum, DRIVEID); if (!pDriv) { - sprintf(pError, "ERROR: variable %s is NOT drivable", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: variable %s is NOT drivable", pName); SCWrite(self->pCon, pError, eError); continue; } @@ -396,7 +396,7 @@ int WriteHeaderOld(pScanData self) /* find the motor */ pMot = FindMotor(self->pSics, pName); if (!pMot) { - sprintf(pError, "ERROR: motor %s NOT found", pName); + snprintf(pError,sizeof(pError)-1, "ERROR: motor %s NOT found", pName); SCWrite(self->pCon, pError, eError); continue; } @@ -483,65 +483,65 @@ int WriteScanPoints(pScanData self, int iPoint) } /* make the data header */ - sprintf(pLine, "%-4s ", "NP"); + snprintf(pLine,sizeof(pLine)-1, "%-4s ", "NP"); strcpy(pInfo, "Scanning Variables: "); strcpy(pSteps, "Steps: "); for (i = 0; i < self->iScanVar; i++) { DynarGet(self->pScanVar, i, &pPtr); pVar = (pVarEntry) pPtr; if (pVar) { - sprintf(pItem, "%-9.9s ", ScanVarName(pVar)); - strcat(pLine, pItem); - sprintf(pItem, "%s, ", ScanVarName(pVar)); - strcat(pInfo, pItem); - sprintf(pItem, "%f ", ScanVarStep(pVar)); - strcat(pSteps, pItem); + snprintf(pItem,sizeof(pItem)-1, "%-9.9s ", ScanVarName(pVar)); + strncat(pLine, pItem,511); + snprintf(pItem,30, "%s, ", ScanVarName(pVar)); + strncat(pInfo, pItem,1024); + snprintf(pItem,30, "%f ", ScanVarStep(pVar)); + strncat(pSteps, pItem,255); } } - strcat(pLine, " Counts "); - strcat(pLine, "Monitor1 "); - strcat(pLine, "Monitor2 "); - strcat(pLine, "Monitor3 "); - strcat(pLine, "Time "); - strcat(pInfo, pSteps); - sprintf(pItem, "\n%d Points,", self->iNP); - strcat(pInfo, pItem); + strncat(pLine, " Counts ",1024); + strncat(pLine, "Monitor1 ",1024); + strncat(pLine, "Monitor2 ",1024); + strncat(pLine, "Monitor3 ",1024); + strncat(pLine, "Time ",1024); + strncat(pInfo, pSteps,1024); + snprintf(pItem,sizeof(pItem)-1, "\n%d Points,", self->iNP); + strncat(pInfo, pItem,1024); if (self->iMode == eTimer) { - strcat(pInfo, " Mode: Timer,"); + strncat(pInfo, " Mode: Timer,",1024); } else { - strcat(pInfo, " Mode: Monitor,"); + strncat(pInfo, " Mode: Monitor,",1024); } - sprintf(pItem, " Preset %f", self->fPreset); - strcat(pInfo, pItem); + snprintf(pItem,sizeof(pItem)-1, " Preset %f", self->fPreset); + strncat(pInfo, pItem,1024); fprintf(self->fd, "%s\n", pInfo); fprintf(self->fd, "%s\n", pLine); /* now the scan points */ for (i = 0; i < self->iCounts; i++) { - sprintf(pLine, "%-4d ", i); + snprintf(pLine,sizeof(pLine)-1, "%-4d ", i); /* print vars */ for (i2 = 0; i2 < self->iScanVar; i2++) { DynarGet(self->pScanVar, i2, &pPtr); pVar = (pVarEntry) pPtr; if (pVar) { - sprintf(pItem, "%-9.3f ", GetScanVarPos(pVar, i)); - strcat(pLine, pItem); + snprintf(pItem,sizeof(pItem)-1, "%-9.3f ", GetScanVarPos(pVar, i)); + strncat(pLine, pItem,1024); } } /* print Counts & Monitor */ DynarGet(self->pCounts, i, &pPtr); pData = (pCountEntry) pPtr; if (pData) { - sprintf(pItem, " %-11ld ", pData->lCount); - strcat(pLine, pItem); - sprintf(pItem, "%-11ld ", pData->Monitors[0]); - strcat(pLine, pItem); - sprintf(pItem, "%-11ld ", pData->Monitors[1]); - strcat(pLine, pItem); - sprintf(pItem, "%-11ld ", pData->Monitors[2]); - strcat(pLine, pItem); - sprintf(pItem, "%-5.1f ", pData->fTime); - strcat(pLine, pItem); + snprintf(pItem,sizeof(pItem)-1, " %-11ld ", pData->lCount); + strncat(pLine, pItem,1024); + snprintf(pItem,sizeof(pItem)-1, "%-11ld ", pData->Monitors[0]); + strncat(pLine, pItem,1024); + snprintf(pItem,sizeof(pItem)-1, "%-11ld ", pData->Monitors[1]); + strncat(pLine, pItem,1024); + snprintf(pItem,sizeof(pItem)-1, "%-11ld ", pData->Monitors[2]); + strncat(pLine, pItem,1024); + snprintf(pItem,sizeof(pItem)-1, "%-5.1f ", pData->fTime); + strncat(pLine, pItem,1024); } fprintf(self->fd, "%s\n", pLine); } @@ -715,8 +715,8 @@ static int CollectScanDataIntern(pScanData self, int iPoint, InitCountEntry(&sCount); /* prepare output header */ - sprintf(pHead, "%-4.4s ", "NP"); - sprintf(pStatus, "%-4d ", iPoint); + snprintf(pHead,sizeof(pHead)-1, "%-4.4s ", "NP"); + snprintf(pStatus,sizeof(pStatus)-1, "%-4d ", iPoint); /* loop over all scan variables */ status = 1; @@ -726,10 +726,10 @@ static int CollectScanDataIntern(pScanData self, int iPoint, if (pVar) { fVal = pVar->pInter->GetValue(pVar->pObject, self->pCon); AppendScanVar(pVar, fVal); - sprintf(pItem, "%-9.9s ", ScanVarName(pVar)); - strcat(pHead, pItem); - sprintf(pItem, "%-9.3f ", fVal); - strcat(pStatus, pItem); + snprintf(pItem,sizeof(pItem)-1, "%-9.9s ", ScanVarName(pVar)); + strncat(pHead, pItem,2024); + snprintf(pItem,sizeof(pItem)-1, "%-9.3f ", fVal); + strncat(pStatus, pItem,2024); } } @@ -739,23 +739,23 @@ static int CollectScanDataIntern(pScanData self, int iPoint, /* format header */ - strcat(pHead, "Counts "); + strncat(pHead, "Counts ",2024); - sprintf(pItem, "%-14ld ", sCount.lCount); - strcat(pStatus, pItem); + snprintf(pItem,sizeof(pItem)-1, "%-14ld ", sCount.lCount); + strncat(pStatus, pItem,2024); - strcat(pHead, "Monitor1 "); - sprintf(pItem, "%-11ld ", sCount.Monitors[0]); - strcat(pStatus, pItem); - strcat(pHead, "Monitor2 "); - sprintf(pItem, "%-11ld ", sCount.Monitors[1]); - strcat(pStatus, pItem); - strcat(pHead, "Monitor3 "); - sprintf(pItem, "%-11ld ", sCount.Monitors[2]); - strcat(pStatus, pItem); - strcat(pHead, "Time "); - sprintf(pItem, "%-6.1f", sCount.fTime); - strcat(pStatus, pItem); + strncat(pHead, "Monitor1 ",2024); + snprintf(pItem,sizeof(pItem)-1, "%-11ld ", sCount.Monitors[0]); + strncat(pStatus, pItem,2024); + strncat(pHead, "Monitor2 ",2024); + snprintf(pItem,sizeof(pItem)-1, "%-11ld ", sCount.Monitors[1]); + strncat(pStatus, pItem,2024); + strncat(pHead, "Monitor3 ",2024); + snprintf(pItem,sizeof(pItem)-1, "%-11ld ", sCount.Monitors[2]); + strncat(pStatus, pItem,2024); + strncat(pHead, "Time ",2024); + snprintf(pItem,sizeof(pItem)-1, "%-6.1f", sCount.fTime); + strncat(pStatus, pItem,2024); /* write progress */ /* diff --git a/synchronize.c b/synchronize.c index 256d56a7..1f1d888b 100644 --- a/synchronize.c +++ b/synchronize.c @@ -47,7 +47,7 @@ static void syncLogin(void) /* try a login */ - sprintf(pBueffel, "%s %s\n", looser, password); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s\n", looser, password); test = NETWrite(connection, pBueffel, strlen(pBueffel)); if (test != 1) { printf("Failed at writing user/password\n"); @@ -136,7 +136,7 @@ int MakeSync(SConnection * pCon, SicsInterp * pSics, void *pData, */ iRet = AddCommand(pSics, "sync", Synchronize, killSync, NULL); if (!iRet) { - sprintf(pBueffel, "ERROR: duplicate command sync not created"); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate command sync not created"); killSync(NULL); SCWrite(pCon, pBueffel, eError); return 0; @@ -165,7 +165,7 @@ tryagain: if (connection == NULL) { syncLogin(); if (connection == NULL) { - sprintf(pBueffel, "ERROR: failed to connect to %s, %d for sync 'ing", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to connect to %s, %d for sync 'ing", hostname, port); SCWrite(pCon, pBueffel, eError); return 0; @@ -252,7 +252,7 @@ tryagain: } if (syncFile != NULL) { - sprintf(pBueffel, "restore %s", syncFile); + snprintf(pBueffel,sizeof(pBueffel)-1, "restore %s", syncFile); } else { strcpy(pBueffel, "restore"); } diff --git a/tasdrive.c b/tasdrive.c index 87bb6e36..36e842c4 100644 --- a/tasdrive.c +++ b/tasdrive.c @@ -417,7 +417,7 @@ static int checkQMotorLimits(ptasMot self, SConnection * pCon, if (driveTilt == 1) { status = - self->math->motors[A3]->pDrivInt->CheckLimits(self->math-> + self->math->motors[SGU]->pDrivInt->CheckLimits(self->math-> motors[SGU], angles.sgu, error, 131); diff --git a/tasscanub.c b/tasscanub.c index e204c643..27475c54 100644 --- a/tasscanub.c +++ b/tasscanub.c @@ -270,14 +270,14 @@ static int TASUBHeader(pScanData self) /* build the steps line */ - sprintf(pBueffel, "STEPS: "); + snprintf(pBueffel,sizeof(pBueffel)-1, "STEPS: "); for (i = 0; i < self->iScanVar; i++) { DynarGet(self->pScanVar, i, &pPtr); pVar = (pVarEntry) pPtr; if (pVar) { strncpy(pWork2, ScanVarName(pVar), 59); strtoupper(pWork2); - sprintf(pWork, "D%s=%8.4f, ", pWork2, ScanVarStep(pVar)); + snprintf(pWork,sizeof(pWork)-1, "D%s=%8.4f, ", pWork2, ScanVarStep(pVar)); strcat(pBueffel, pWork); } } @@ -399,7 +399,7 @@ static int TASUBHeader(pScanData self) iCount = 0; fprintf(self->fd, "\nVARIA: "); } - strcpy(pWork2, pCom->pName); + strncpy(pWork2, pCom->pName,60); strtoupper(pWork2); fprintf(self->fd, "%-8s=%8.4f, ", pWork2, fVal); iCount++; @@ -430,7 +430,7 @@ static int TASUBHeader(pScanData self) iCount = 0; fprintf(self->fd, "\nZEROS: "); } - strcpy(pWork2, pCom->pName); + strncpy(pWork2, pCom->pName,60); strtoupper(pWork2); fprintf(self->fd, "%-8s=%8.4f, ", pWork2, fVal); iCount++; @@ -485,11 +485,11 @@ static int TASUBHeader(pScanData self) DynarGet(self->pScanVar, i, &pPtr); pVar = (pVarEntry) pPtr; if (pVar) { - strcat(pBueffel, "F9.4,1X,"); + strncat(pBueffel, "F9.4,1X,",1024); strncpy(pWork2, pVar->Name, 59); strtoupper(pWork2); strcenter(pWork2, pTen, 11); - strcat(pHeader, pTen); + strncat(pHeader, pTen,1024); } } /* @@ -502,16 +502,16 @@ static int TASUBHeader(pScanData self) */ for (i = 0; i < pTAS->addCount; i++) { if (i == pTAS->addCount - 1) { - strcat(pBueffel, "F9.4"); + strncat(pBueffel, "F9.4",1024); } else { - strcat(pBueffel, "F9.4,1X,"); + strncat(pBueffel, "F9.4,1X,",1024); } - strcpy(pWork2, pTAS->out[i]); + strncpy(pWork2, pTAS->out[i],60); strtoupper(pWork2); strcenter(pWork2, pTen, 11); - strcat(pHeader, pTen); + strncat(pHeader, pTen,1024); } - strcat(pBueffel, ")"); + strncat(pBueffel, ")",1024); /* write the final bit @@ -566,9 +566,9 @@ static int TASUBScanPoint(pScanData self, int iPoint) write point number */ if (pTAS->iPOL >= 0) { - sprintf(pBueffel, "%3d %3d", iPoint + 1, pTAS->iPOL); + snprintf(pBueffel,sizeof(pBueffel)-1, "%3d %3d", iPoint + 1, pTAS->iPOL); } else { - sprintf(pBueffel, "%4d ", iPoint + 1); + snprintf(pBueffel,sizeof(pBueffel)-1, "%4d ", iPoint + 1); } /* @@ -580,7 +580,7 @@ static int TASUBScanPoint(pScanData self, int iPoint) if (pVar) { fVal = readDrivable(ScanVarName(pVar), self->pCon); } - sprintf(pWork, "%9.4f ", fVal); + snprintf(pWork,sizeof(pWork)-1, "%9.4f ", fVal); strcat(pBueffel, pWork); } @@ -592,7 +592,7 @@ static int TASUBScanPoint(pScanData self, int iPoint) m3 = GetMonitor(self->pCounterData, 3, self->pCon); cnts = GetCounts(self->pCounterData, self->pCon); fVal = GetCountTime(self->pCounterData, self->pCon); - sprintf(pWork, "%8ld %8ld %9.2f %8ld %8ld ", m1, m2, fVal, cnts, m3); + snprintf(pWork,sizeof(pWork)-1, "%8ld %8ld %9.2f %8ld %8ld ", m1, m2, fVal, cnts, m3); strcat(pBueffel, pWork); /* @@ -605,7 +605,7 @@ static int TASUBScanPoint(pScanData self, int iPoint) snprintf(pError, 131, "WARNING: problem reading %s", pTAS->out[i]); SCWrite(self->pCon, pError, eWarning); } - sprintf(pWork, "%9.4f ", fVal); + snprintf(pWork,sizeof(pWork)-1, "%9.4f ", fVal); strcat(pBueffel, pWork); } @@ -872,7 +872,7 @@ static void ParseOutput(pTASdata pTAS, SConnection * pCon) } else { strtolower(pToken); if (strcmp(pToken, "unknown") != 0) { - sprintf(pWarn, "WARNING: ignored invalid token > %s < in output", + snprintf(pWarn,sizeof(pWarn)-1, "WARNING: ignored invalid token > %s < in output", pToken); SCWrite(pCon, pWarn, eWarning); } @@ -908,10 +908,10 @@ int TASUBPrepare(pScanData self) SCWrite(self->pCon, pLine, eLog); if (GetCounterMode(pTAS->pScan->pCounterData) == eTimer) { - sprintf(pLine, " %8f Seconds per point", + snprintf(pLine,sizeof(pLine)-1, " %8f Seconds per point", GetCounterPreset(pTAS->pScan->pCounterData)); } else { - sprintf(pLine, " %8f Monitor Counts per point", + snprintf(pLine,sizeof(pLine)-1, " %8f Monitor Counts per point", GetCounterPreset(pTAS->pScan->pCounterData)); } diff --git a/tcldrivable.c b/tcldrivable.c index 460fee9c..c757698e 100644 --- a/tcldrivable.c +++ b/tcldrivable.c @@ -289,7 +289,7 @@ static int TclDrivableCheckLimits(void *data, float fVal, pTcl = InterpGetTcl(pServ->pSics); commandPart1 = getTclDrivableCommand(data, TCLCHECK); if (commandPart1 != NULL) { - sprintf(pNum, "%f", fVal); + snprintf(pNum,sizeof(pNum)-1, "%f", fVal); command = combine(commandPart1, pNum); if (command) { status = Tcl_Eval(pTcl, command); @@ -326,7 +326,7 @@ static long TclDrivableSetValue(void *data, SConnection * pCon, float fVal) /* build and check command string */ - sprintf(pNum, "%f", fVal); + snprintf(pNum,sizeof(pNum)-1, "%f", fVal); commandHead = getTclDrivableCommand(data, TCLSET); if (commandHead == NULL) { SCWrite(pCon, diff --git a/tclev.c b/tclev.c index a17074ef..b0a15d7d 100644 --- a/tclev.c +++ b/tclev.c @@ -35,7 +35,7 @@ static int TclSetValue(pEVDriver self, float fNew) assert(pPriv); /* build command line */ - sprintf(pBueffel, "%s %s %f", pPriv->pSetValue, pPriv->pArray, fNew); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s %f", pPriv->pSetValue, pPriv->pArray, fNew); iRet = Tcl_Eval(pPriv->pTcl, pBueffel); if (iRet != TCL_OK) { strncpy(pBueffel, pPriv->pTcl->result, 1023); @@ -62,7 +62,7 @@ static int TclGetValue(pEVDriver self, float *fVal) assert(pPriv); /* build command line */ - sprintf(pBueffel, "%s %s", pPriv->pGetValue, pPriv->pArray); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s", pPriv->pGetValue, pPriv->pArray); iRet = Tcl_Eval(pPriv->pTcl, pBueffel); if (iRet != TCL_OK) { strncpy(pBueffel, pPriv->pTcl->result, 1023); @@ -103,7 +103,7 @@ static int TclSend(pEVDriver self, char *pCommand, assert(pPriv); /* build command line */ - sprintf(pBueffel, "%s %s %s", pPriv->pSend, pPriv->pArray, pCommand); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s %s", pPriv->pSend, pPriv->pArray, pCommand); iRet = Tcl_Eval(pPriv->pTcl, pBueffel); if (iRet != TCL_OK) { strncpy(pBueffel, pPriv->pTcl->result, 1023); @@ -137,7 +137,7 @@ static int TclGetError(pEVDriver self, int *iCode, /* catch the stupid Tcl thing */ if (pPriv->iLastError == STUPIDTCL) { - sprintf(pBueffel, + snprintf(pBueffel,sizeof(pBueffel)-1, "Your Tcl-script returned a stupid answer:\n --> %s <--", pPriv->pTcl->result); strncpy(pReply, pBueffel, iReplyLen); @@ -145,7 +145,7 @@ static int TclGetError(pEVDriver self, int *iCode, } /* build command line */ - sprintf(pBueffel, "%s %s %d", pPriv->pGetError, pPriv->pArray, + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s %d", pPriv->pGetError, pPriv->pArray, pPriv->iLastError); iRet = Tcl_Eval(pPriv->pTcl, pBueffel); if (iRet != TCL_OK) { @@ -181,7 +181,7 @@ static int TclTryFixIt(pEVDriver self, int iCode) } /* build command line */ - sprintf(pBueffel, "%s %s %d", pPriv->pTryFixIt, pPriv->pArray, iCode); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s %d", pPriv->pTryFixIt, pPriv->pArray, iCode); iRet = Tcl_Eval(pPriv->pTcl, pBueffel); if (iRet != TCL_OK) { return DEVFAULT; @@ -211,7 +211,7 @@ static int TclInit(pEVDriver self) assert(pPriv); /* build command line */ - sprintf(pBueffel, "%s %s", pPriv->pInit, pPriv->pArray); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s", pPriv->pInit, pPriv->pArray); iRet = Tcl_Eval(pPriv->pTcl, pBueffel); if (iRet != TCL_OK) { strncpy(pBueffel, pPriv->pTcl->result, 1023); @@ -237,7 +237,7 @@ static int TclClose(pEVDriver self) assert(pPriv); /* build command line */ - sprintf(pBueffel, "%s %s", pPriv->pClose, pPriv->pArray); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s", pPriv->pClose, pPriv->pArray); iRet = Tcl_Eval(pPriv->pTcl, pBueffel); if (iRet != TCL_OK) { strncpy(pBueffel, pPriv->pTcl->result, 1023); @@ -426,7 +426,7 @@ int UpdateTclVariable(pEVDriver self, char *name, float fVal) pPriv = (pTclEv) self->pPrivate; assert(pPriv); - sprintf(pBueffel, "%f", fVal); + snprintf(pBueffel,sizeof(pBueffel)-1, "%f", fVal); pPtr = Tcl_SetVar2(pPriv->pTcl, pPriv->pArray, name, pBueffel, TCL_GLOBAL_ONLY); if (pPtr == NULL) { @@ -451,7 +451,7 @@ int TclEnvironmentWrapper(SConnection * pCon, SicsInterp * pSics, assert(pPriv); /* build command line */ - sprintf(pBueffel, "%s %s", pPriv->pWrapper, pPriv->pArray); + snprintf(pBueffel,sizeof(pBueffel)-1, "%s %s", pPriv->pWrapper, pPriv->pArray); for (i = 1; i < argc; i++) { if ((strlen(pBueffel) + strlen(argv[i])) < MAXLEN) { strcat(pBueffel, " "); diff --git a/tclintimpl.c b/tclintimpl.c index 07d860c4..4b7e47a3 100644 --- a/tclintimpl.c +++ b/tclintimpl.c @@ -134,7 +134,7 @@ int MakeTclInt(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = AddCommand(pSics, argv[1], TclIntAction, KillTclInt, (void *) pNew); if (!iRet) { - sprintf(pBuffer, "ERROR: duplicate command %s not created", argv[1]); + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: duplicate command %s not created", argv[1]); SCWrite(pCon, pBuffer, eError); return 0; } @@ -159,7 +159,7 @@ int TclIntAction(SConnection * pCon, SicsInterp * pSics, void *pData, SCWrite(pCon, pBuffer, eValue); return 1; } else { - sprintf(pBuffer, "ERROR: %s expects at least one argument!", + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: %s expects at least one argument!", argv[0]); SCWrite(pCon, pBuffer, eError); return 0; @@ -191,7 +191,7 @@ int TclIntAction(SConnection * pCon, SicsInterp * pSics, void *pData, } return 1; } else { - sprintf(pBuffer, "ERROR: keyword %s to %s not recognized", + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: keyword %s to %s not recognized", argv[1], argv[0]); SCWrite(pCon, pBuffer, eError); return 0; diff --git a/telnet.c b/telnet.c index d791c806..b1d31768 100644 --- a/telnet.c +++ b/telnet.c @@ -46,7 +46,7 @@ pTelTask CreateTelnet(SConnection * pCon) pRes->pCon = pCon; pRes->iLogin = 0; pRes->tStart = time(&shit); - strcpy(pRes->pLoginWord, pPtr); + strncpy(pRes->pLoginWord, pPtr,131); return pRes; } @@ -164,7 +164,7 @@ int TelnetTaskOld(void *pData) pPasswd = strtok(NULL, " \t\r\n"); iRet = IsValidUser(pUser, pPasswd); if (iRet < 0) { - sprintf(pBuffer, "SYSTEM ATTACK by %s / %s", pUser, pPasswd); + snprintf(pBuffer,sizeof(pBuffer)-1, "SYSTEM ATTACK by %s / %s", pUser, pPasswd); SICSLogWrite(pBuffer, eInternal); SCWrite(self->pCon, "I do not know you, I do not let you in", eError); @@ -173,7 +173,7 @@ int TelnetTaskOld(void *pData) return 1; } else { NETInfo(self->pCon->pSock, pHost, 131); - sprintf(pBuffer, "Accepted connection on socket %d from %s", + snprintf(pBuffer,sizeof(pBuffer)-1, "Accepted connection on socket %d from %s", self->pCon->pSock->sockid, pHost); SICSLogWrite(pBuffer, eInternal); WriteToCommandLog("SYS >", pBuffer); @@ -272,7 +272,7 @@ int TelnetTask(void *pData) pPasswd = strtok(NULL, " \t\r\n"); iRet = IsValidUser(pUser, pPasswd); if (iRet < 0) { - sprintf(pBuffer, "SYSTEM ATTACK by %s / %s", pUser, pPasswd); + snprintf(pBuffer,sizeof(pBuffer)-1, "SYSTEM ATTACK by %s / %s", pUser, pPasswd); SICSLogWrite(pBuffer, eInternal); SCWrite(self->pCon, "I do not know you, I do not let you in", eError); @@ -280,7 +280,7 @@ int TelnetTask(void *pData) free(pPtr); return 1; } else { - sprintf(pBuffer, "Accepted telnet connection on handle %d", + snprintf(pBuffer,sizeof(pBuffer)-1, "Accepted telnet connection on handle %d", self->pCon->sockHandle); SICSLogWrite(pBuffer, eInternal); WriteToCommandLog("SYS >", pBuffer); diff --git a/token.c b/token.c index 11c7370c..2305efb4 100644 --- a/token.c +++ b/token.c @@ -135,7 +135,7 @@ int TokenWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, } } /* default */ - sprintf(pBueffel, "ERROR: subcommand %s to token NOT understood", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: subcommand %s to token NOT understood", argv[1]); SCWrite(pCon, pBueffel, eError); return 0; diff --git a/udpquieck.c b/udpquieck.c index b9a281c2..89108235 100644 --- a/udpquieck.c +++ b/udpquieck.c @@ -64,7 +64,7 @@ int SendQuieck(int iType, char *pText) switch (iType) { case QUIECK: strcpy(pMessage, "QUIECK/"); - strcat(pMessage, pText); + strncat(pMessage, pText,512); break; default: strcpy(pMessage, "Error"); diff --git a/varlog.c b/varlog.c index a8f3f2c3..910acaa2 100644 --- a/varlog.c +++ b/varlog.c @@ -348,7 +348,7 @@ int VarlogWrapper(pVarLog self, SConnection * pCon, } self->fd = fopen(sub2, "w"); if (!self->fd) { - sprintf(pBueffel, "ERROR: failed to open temperature log file: %s", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to open temperature log file: %s", sub2); SCWrite(pCon, pBueffel, eError); return 0; @@ -393,7 +393,7 @@ int VarlogWrapper(pVarLog self, SConnection * pCon, eWarning); return 0; } - sprintf(pBueffel, "%s.Mean = %8.2f %s.StdDev = %8.2f", + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.Mean = %8.2f %s.StdDev = %8.2f", pVarName, fMean, pVarName, fStdDev); SCWrite(pCon, pBueffel, eValue); return 1; @@ -414,7 +414,7 @@ int VarlogWrapper(pVarLog self, SConnection * pCon, return 1; } else { /* print */ - sprintf(pBueffel, "%s.frequency = %d", pVarName, + snprintf(pBueffel,sizeof(pBueffel)-1, "%s.frequency = %d", pVarName, (int) self->tFrequency); SCWrite(pCon, pBueffel, eValue); return 1; @@ -462,7 +462,7 @@ int VarlogWrapper(pVarLog self, SConnection * pCon, } /* command not recognized */ else { - sprintf(pBueffel, "ERROR: %s no valid command to varlog", subcommand); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s no valid command to varlog", subcommand); SCWrite(pCon, pBueffel, eError); return 0; } diff --git a/velo.c b/velo.c index b6f2efb1..c5848f5c 100644 --- a/velo.c +++ b/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; } diff --git a/xytable.c b/xytable.c index 8c5ddfe5..1f648388 100644 --- a/xytable.c +++ b/xytable.c @@ -64,7 +64,7 @@ int XYFactory(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = AddCommand(pSics, argv[1], XYAction, KillXY, 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; } @@ -148,7 +148,7 @@ int XYList(pXYTable self, SConnection * pCon) iRet = LLDnodePtr2First(self->iList); while (iRet != 0) { LLDnodeDataTo(self->iList, &pData); - sprintf(pBueffel, " %12.4f %12.4f\n", pData.x, pData.y); + snprintf(pBueffel,sizeof(pBueffel)-1, " %12.4f %12.4f\n", pData.x, pData.y); strcat(pBuffer, pBueffel); iRet = LLDnodePtr2Next(self->iList); } @@ -205,7 +205,7 @@ int XYAction(SConnection * pCon, SicsInterp * pSics, void *pData, assert(pSics); if (argc < 2) { - sprintf(pBueffel, "ERROR: need command word for %s", argv[0]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: need command word for %s", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -223,21 +223,21 @@ int XYAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } if (argc < 4) { - sprintf(pBueffel, "ERROR: insufficient no of args to %s add", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient no of args to %s add", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } iRet = Tcl_GetDouble(pSics->pTcl, argv[2], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to conert %s to number", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to conert %s to number", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } fX = (float) dVal; iRet = Tcl_GetDouble(pSics->pTcl, argv[3], &dVal); if (iRet != TCL_OK) { - sprintf(pBueffel, "ERROR: failed to conert %s to number", argv[3]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to conert %s to number", argv[3]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -250,14 +250,14 @@ int XYAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } if (argc < 3) { - sprintf(pBueffel, "ERROR: insufficient no of args to %s write", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: insufficient no of args to %s write", argv[0]); SCWrite(pCon, pBueffel, eError); return 0; } fd = fopen(argv[2], "w"); if (fd == NULL) { - sprintf(pBueffel, "ERROR: failed to open %s for writing", argv[2]); + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: failed to open %s for writing", argv[2]); SCWrite(pCon, pBueffel, eError); return 0; } @@ -272,7 +272,7 @@ int XYAction(SConnection * pCon, SicsInterp * pSics, void *pData, XYList(self, pCon); return 1; } - sprintf(pBueffel, "ERROR: subcommand %s to %s unknonw", + snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: subcommand %s to %s unknonw", argv[1], argv[0]); SCWrite(pCon, pBueffel, eError); return 0;