From dca2b08daf4b0c0cd16dfdf7d6b449c0448907d2 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 16 Mar 2011 14:13:32 +0000 Subject: Rewrites to eliminate isspace() calls. --- ChangeLog | 6 ++++++ generic/tclBasic.c | 18 +++++++++--------- generic/tclParse.c | 21 ++++++++------------- generic/tclProc.c | 11 +++++------ 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d14435..e175366 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-16 Don Porter + + * generic/tclBasic.c: Some rewrites to eliminate calls to + * generic/tclParse.c: isspace() and their /* INTL */ risk. + * generic/tclProc.c: + 2011-03-16 Jan Nijtmans * unix/tcl.m4: Make SHLIB_LD_LIBS='${LIBS}' the default and diff --git a/generic/tclBasic.c b/generic/tclBasic.c index ea1be61..596254d 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -6481,16 +6481,16 @@ ExprAbsFunc( goto unChanged; } else if (l == (long)0) { const char *string = objv[1]->bytes; - if (!string) { - /* There is no string representation, so internal one is correct */ - goto unChanged; - } - while (isspace(UCHAR(*string))) { - ++string; - } - if (*string != '-') { - goto unChanged; + if (string) { + while (*string != '0') { + if (*string == '-') { + Tcl_SetObjResult(interp, Tcl_NewLongObj(0)); + return TCL_OK; + } + string++; + } } + goto unChanged; } else if (l == LONG_MIN) { TclBNInitBignumFromLong(&big, l); goto tooLarge; diff --git a/generic/tclParse.c b/generic/tclParse.c index 158ff42..94d9c50 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -524,28 +524,23 @@ Tcl_ParseCommand( */ nextElem = tokenPtr[1].start; - while (isspace(UCHAR(*nextElem))) { - nextElem++; - } while (nextElem < listEnd) { + int quoted, brace; + tokenPtr->type = TCL_TOKEN_SIMPLE_WORD; tokenPtr->numComponents = 1; - tokenPtr->start = nextElem; tokenPtr++; tokenPtr->type = TCL_TOKEN_TEXT; tokenPtr->numComponents = 0; TclFindElement(NULL, nextElem, listEnd - nextElem, &(tokenPtr->start), &nextElem, - &(tokenPtr->size), NULL); - if (tokenPtr->start + tokenPtr->size == listEnd) { - tokenPtr[-1].size = listEnd - tokenPtr[-1].start; - } else { - tokenPtr[-1].size = tokenPtr->start - + tokenPtr->size - tokenPtr[-1].start; - tokenPtr[-1].size += (isspace(UCHAR( - tokenPtr->start[tokenPtr->size])) == 0); - } + &(tokenPtr->size), &brace); + + quoted = brace || tokenPtr->start[-1] == '"'; + tokenPtr[-1].start = tokenPtr->start - quoted; + tokenPtr[-1].size = tokenPtr->start + tokenPtr->size + - tokenPtr[-1].start + quoted; tokenPtr++; } diff --git a/generic/tclProc.c b/generic/tclProc.c index 978c5f7..c63337c 100644 --- a/generic/tclProc.c +++ b/generic/tclProc.c @@ -320,6 +320,8 @@ Tcl_ProcObjCmd( } if ((procArgs[0] == 'a') && (strncmp(procArgs, "args", 4) == 0)) { + int numBytes; + procArgs +=4; while(*procArgs != '\0') { if (*procArgs != ' ') { @@ -332,12 +334,9 @@ Tcl_ProcObjCmd( * The argument list is just "args"; check the body */ - procBody = TclGetString(objv[3]); - while (*procBody != '\0') { - if (!isspace(UCHAR(*procBody))) { - goto done; - } - procBody++; + procBody = Tcl_GetStringFromObj(objv[3], &numBytes); + if (TclParseAllWhiteSpace(procBody, numBytes) < numBytes) { + goto done; } /* -- cgit v0.12