Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 42a4fa0b9f5706dc21fb33fa59c04acd3f2bdf58
Ticket: 217841ffffffffffffffffffffffffffffffffff
Lack of diagnostics for invalid octal numbers
User & Date: nobody on 2000-10-26 00:44:44
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed 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
    
    
    
    
    
  4. foundin changed to: "obsolete: 8.1b1"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to: "Lack of diagnostics for invalid octal numbers"
  11. type changed to: "Bug"