Artifacts Associated With Ticket 217841
Ticket change [42a4fa0b9f] (rid 116420) by nobody on 2000-10-26 00:44:44:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
OriginalBugID: 1726 RFE Version: 8.1b1 SubmitDate: '1999-04-05' LastModified: '1999-09-15' Severity: LOW Status: Closed Submitter: pat ChangedBy: hobbs RelatedBugIDs: 2145 OS: Linux-Red Hat OSVersion: 5.2 Machine: Other FixedDate: '2000-10-25' ClosedDate: '1999-09-15' Name: Bart Veer Comments: The patch is contained inside LogSyntaxError() so it will only trigger if an error has been detected already, hence correct Tcl code does not suffer any performance penalties. If an error is triggered while parsing an expression then some heuristics are used to check for an invalid octal number, and if so an alternative error message is generated. The patch will not catch every attempt to use an invalid octal number, but it should still prove useful in some cases. DesiredBehavior: Problem reports related to invalid octal numbers such as 08 are recurring and annoying. A better diagnostic might help. For example: % expr 08 syntax error in expression "08" is less informative than: % expr 08 invalid octal number in expression "08" Patch: --- tclParseExpr.c.orig Wed Nov 11 04:54:18 1998 +++ tclParseExpr.c Tue Mar 30 11:44:12 1999 @@ -1818,9 +1818,50 @@ { int numBytes = (infoPtr->lastChar - infoPtr->originalExpr); char buffer[100]; + int octal_error = 0; + char *prev_start; - sprintf(buffer, "syntax error in expression \"%.*s\"", - ((numBytes > 60)? 60 : numBytes), infoPtr->originalExpr); + /* + * Most of the time "syntax error" is a reasonable message. There + * is one exception, invalid octal numbers, which tends to confuse + * beginners. This code attempts to detect such errors. Doing the + * detection here is non-trivial, but it has the advantage that + * the code only runs after an error and hence correct Tcl code + * does not suffer any performance penalties. + * + * The way GetLexeme() above works means that an invalid octal + * number such as 08 would result in two successive LITERAL + * tokens. By the time the error is detected the first of these is + * no longer readily accessible. infoPtr->lexeme should be LITERAL + * and infoPtr->start should point at a valid digit, either 8 or + * 9. It is necessary to track back from infoPtr->start until a + * non-octal digit is encountered or the start of the expression + * is reached. Then if the next character is 0 the condition + * is satisfied. + */ + if ((LITERAL == infoPtr->lexeme) && + (('8' == *(infoPtr->start)) || ('9' == *(infoPtr->start)))) { + for (prev_start = infoPtr->start - 1; + (prev_start >= infoPtr->originalExpr) && + ('0' <= *prev_start) && ('7' >= *prev_start); + prev_start--); + prev_start++; + + /* + * Either (prev_start == infoPtr->start) + * or (isoctal(*prev_start)) + */ + if ('0' == *prev_start) { + octal_error = 1; + sprintf(buffer, "invalid octal number in expression \"%.*s\"", + ((numBytes > 52)? 52 : numBytes), infoPtr->originalExpr); + } + } + + if (!octal_error) { + sprintf(buffer, "syntax error in expression \"%.*s\"", + ((numBytes > 60)? 60 : numBytes), infoPtr->originalExpr); + } Tcl_AppendStringsToObj(Tcl_GetObjResult(infoPtr->parsePtr->interp), buffer, (char *) NULL); } PatchFiles: generic/tclParseExpr.c - foundin initialized to: "obsolete: 8.1b1"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "69. Other"
- title initialized to: "Lack of diagnostics for invalid octal numbers"
- type initialized to: "Bug"
Ticket change [35102a7f26] (rid 106856) by welch on 2000-10-26 07:59:46:
- closedate changed to: "2000-10-26T00:59:46"
- closer changed to: "welch"
- priority changed to: "2"
- resolution changed to: "Invalid"
- status changed to: "Closed"
Ticket change [f8e706cc6f] (rid 91614) by dgp on 2001-04-13 23:18:27:
- closedate changed to: "2001-04-13T16:18:27"
- closer changed to: "dgp"
- subsystem changed to: "45. Parsing and Eval"