Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c9c4d0f6c91229119b82eac0c065193a45c90566
Ticket: 619164ffffffffffffffffffffffffffffffffff
Incorrect conversion of \000 using UTF-8
User & Date: nobody on 2002-10-06 05:47:12
Changes

  1. assignee changed to: "nijtmans"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    When to convert \000 (0x00, \0d00, \0o00), the routtine 
    Tcl_UniCharToUtf(ch, str) under tcl/generic/tclUtf.c did not 
    process correctly for the case when ch == 0. This code 
    segment below is from the latest on the tree when this 
    report  is written. 
    
    INLINE int
    Tcl_UniCharToUtf(ch, str)
        int ch;/* The Tcl_UniChar to be stored 
    in the
     * buffer. */
        char *str;/* Buffer in which the 
    UTF-8 representation
     * of the Tcl_UniChar is 
    stored.  Buffer must
     * be large enough to 
    hold the UTF-8 character
     * (at most 
    TCL_UTF_MAX bytes). */
    {
        if ((ch > 0) && (ch < UNICODE_SELF)) {
    str[0] = (char) ch;
    return 1;
        }
        if (ch <= 0x7FF) {
    str[1] = (char) ((ch | 0x80) & 0xBF);
    str[0] = (char) ((ch >> 6) | 0xC0);
    return 2;
        }
        if (ch <= 0xFFFF) {
    three:
    str[2] = (char) ((ch | 0x80) & 0xBF);
    str[1] = (char) (((ch >> 6) | 0x80) & 0xBF);
    str[0] = (char) ((ch >> 12) | 0xE0);
    return 3;
        }
    
    #if TCL_UTF_MAX > 3
        if (ch <= 0x1FFFFF) {
    str[3] = (char) ((ch | 0x80) & 0xBF);
    str[2] = (char) (((ch >> 6) | 0x80) & 0xBF);
    str[1] = (char) (((ch >> 12) | 0x80) & 0xBF);
    str[0] = (char) ((ch >> 18) | 0xF0);
    return 4;
        }
        if (ch <= 0x3FFFFFF) {
    str[4] = (char) ((ch | 0x80) & 0xBF);
    str[3] = (char) (((ch >> 6) | 0x80) & 0xBF);
    str[2] = (char) (((ch >> 12) | 0x80) & 0xBF);
    str[1] = (char) (((ch >> 18) | 0x80) & 0xBF);
    str[0] = (char) ((ch >> 24) | 0xF8);
    return 5;
        }
        if (ch <= 0x7FFFFFFF) {
    str[5] = (char) ((ch | 0x80) & 0xBF);
    str[4] = (char) (((ch >> 6) | 0x80) & 0xBF);
    str[3] = (char) (((ch >> 12) | 0x80) & 0xBF);
    str[2] = (char) (((ch >> 18) | 0x80) & 0xBF);
    str[1] = (char) (((ch >> 24) | 0x80) & 0xBF);
    str[0] = (char) ((ch >> 30) | 0xFC);
    return 6;
        }
    #endif
    
        ch = 0xFFFD;
        goto three;
    }
    
    The code above does not consider correctly the case when 
    ch == 0. The case for ch == 0 should be same as the one 
    for ((ch > 0) && (ch < UNICODE_SELF)). Also the routine 
    UtfCount(ch) just above also have the same problem. 
    
    To reproduce the problem, I just write a simple c extension 
    as below,
    
    void testchar(char c) {
      printf("char: %x\n", c);
    }
    
    swigged, and load the library inside the tclsh and type 
    "testchar \000". If always prints "char: ffffffc0".
    
    
    
    
    
  4. foundin changed to: "obsolete ----"
  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: "44. UTF-8 Strings"
  10. title changed to: "Incorrect conversion of \000 using UTF-8"
  11. type changed to: "Bug"