diff options
author | dgp <dgp@users.sourceforge.net> | 2014-12-04 22:10:57 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2014-12-04 22:10:57 (GMT) |
commit | 3041f3f9a1d8a242105ffe99eebae201a7079549 (patch) | |
tree | ca5b53d4a09396ccb6458f4999e411a421a36961 /generic/tclParse.c | |
parent | 886a7575564f8e4e164cb67dff4554778650868e (diff) | |
parent | 640e5762bc7e0aa585f1135dde28e2fa9434e79e (diff) | |
download | tcl-3041f3f9a1d8a242105ffe99eebae201a7079549.zip tcl-3041f3f9a1d8a242105ffe99eebae201a7079549.tar.gz tcl-3041f3f9a1d8a242105ffe99eebae201a7079549.tar.bz2 |
[d2ffcca163] Limit parsing results that are documented to accept only
ASCII chars to actually follow that constraint. This requires not trusting
isalnum(.) and isalpha(.) to deliver portable identical results.
Diffstat (limited to 'generic/tclParse.c')
-rw-r--r-- | generic/tclParse.c | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/generic/tclParse.c b/generic/tclParse.c index e475fb8..025304c 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -628,6 +628,47 @@ TclIsSpaceProc( /* *---------------------------------------------------------------------- * + * TclIsBareword-- + * + * Report whether byte is one that can be part of a "bareword". + * This concept is named in expression parsing, where it determines + * what can be a legal function name, but is the same definition used + * in determining what variable names can be parsed as variable + * substitutions without the benefit of enclosing braces. The set of + * ASCII chars that are accepted are the numeric chars ('0'-'9'), + * the alphabetic chars ('a'-'z', 'A'-'Z') and underscore ('_'). + * + * Results: + * Returns 1, if byte is in the accepted set of chars, 0 otherwise. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TclIsBareword( + char byte) +{ + if (byte < '0' || byte > 'z') { + return 0; + } + if (byte <= '9' || byte >= 'a') { + return 1; + } + if (byte == '_') { + return 1; + } + if (byte < 'A' || byte > 'Z') { + return 0; + } + return 1; +} + +/* + *---------------------------------------------------------------------- + * * ParseWhiteSpace -- * * Scans up to numBytes bytes starting at src, consuming white space @@ -1343,9 +1384,7 @@ Tcl_ParseVarName( { Tcl_Token *tokenPtr; register const char *src; - unsigned char c; - int varIndex, offset; - Tcl_UniChar ch; + int varIndex; unsigned array; if ((numBytes == 0) || (start == NULL)) { @@ -1428,22 +1467,12 @@ Tcl_ParseVarName( tokenPtr->numComponents = 0; while (numBytes) { - if (Tcl_UtfCharComplete(src, numBytes)) { - offset = Tcl_UtfToUniChar(src, &ch); - } else { - char utfBytes[TCL_UTF_MAX]; - - memcpy(utfBytes, src, (size_t) numBytes); - utfBytes[numBytes] = '\0'; - offset = Tcl_UtfToUniChar(utfBytes, &ch); - } - c = UCHAR(ch); - if (isalnum(c) || (c == '_')) { /* INTL: ISO only, UCHAR. */ - src += offset; - numBytes -= offset; + if (TclIsBareword(*src)) { + src += 1; + numBytes -= 1; continue; } - if ((c == ':') && (numBytes != 1) && (src[1] == ':')) { + if ((src[0] == ':') && (numBytes != 1) && (src[1] == ':')) { src += 2; numBytes -= 2; while (numBytes && (*src == ':')) { |