From 903a472f47e3ca7cf6befca9f6a9de9413c426f4 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 29 Nov 2012 09:28:16 +1100 Subject: [PATCH] check all targets for valid numbers before driving any --- drive.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/drive.c b/drive.c index ef076664..bd2179f8 100644 --- a/drive.c +++ b/drive.c @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------- Implementation file for the drive command - + This version as Test for Device Executor. Mark Koennecke, December 1996 @@ -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)) { - snprintf(pBueffel, 511, "Insuficient Privilege to drive %s", name); + snprintf(pBueffel, 511, "Insufficient Privilege to drive %s", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -160,7 +160,7 @@ int Start2Run(SConnection * pCon, SicsInterp * pInter, char *name, /* check if user is allowed to drive */ if (!SCMatchRights(pCon, usUser)) { - snprintf(pBueffel,511, "Insuficient Privilege to drive %s", name); + snprintf(pBueffel,511, "Insufficient Privilege to drive %s", name); SCWrite(pCon, pBueffel, eError); return 0; } @@ -301,7 +301,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } - /* interprete arguments as pairs name value and try to start */ + /* interpret arguments as pairs (name, value) and check */ SetStatus(eDriving); for (i = 1; i < argc; i += 2) { if (argv[i + 1] == NULL) { @@ -313,7 +313,22 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget); if (iRet == TCL_ERROR) { SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError); - StopExe(GetExecutor(), "ALL"); + SetStatus(eOld); + return 0; + } else if (!isfinite(dTarget)) { + snprintf(pBueffel, 511, + "ERROR: target %s value for %s is not a finite number", + argv[i + 1], argv[i]); + SCWrite(pCon, pBueffel, eError); + SetStatus(eOld); + return 0; + } + } + /* interpret arguments as pairs (name, value) and try to start */ + for (i = 1; i < argc; i += 2) { + iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget); + if (iRet == TCL_ERROR) { + SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError); SetStatus(eOld); return 0; } @@ -360,7 +375,7 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, SetStatus(eOld); return 0; } - SCWrite(pCon, "Driving finished sucessfully", eValue); + SCWrite(pCon, "Driving finished successfully", eValue); SetStatus(eOld); return 1; } @@ -398,7 +413,7 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } - /* interprete arguments as pairs name value and try to start */ + /* interpret arguments as pairs name value and try to start */ SetStatus(eDriving); for (i = 1; i < argc; i += 2) { if (argv[i + 1] == NULL) {