Skip to content
Tcl Source Code History Of Ticket 619164ffffffffffffffffffffffffffffffffff
Login

History Of Ticket 619164ffffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 619164ffffffffffffffffffffffffffffffffff

  1. Ticket change [c9c4d0f6c9] (rid 122344) by nobody on 2002-10-06 05:47:12:

    1. assignee initialized to: "nijtmans"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized 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 initialized to: "obsolete ----"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "44. UTF-8 Strings"
    10. title initialized to: "Incorrect conversion of \000 using UTF-8"
    11. type initialized to: "Bug"
  2. Ticket change [8662fbb1f4] (rid 131500) by hobbs on 2002-10-07 23:51:11:

    1. assignee changed to: "hobbs"
  3. Ticket change [3710710930] (rid 107212) by dkf on 2002-10-08 16:58:32:

    1. assignee changed to: "dkf"
    2. closedate changed to: "2002-10-08T09:58:32"
    3. closer changed to: "dkf"
    4. foundin changed to: "obsolete: 8.4.0"
    5. icomment:
      Logged In: YES 
      user_id=79902
      
      This is correct and intentional. Tcl encodes \u0000 as a
      multi-byte sequence because this allows (pseudo-)UTF8
      strings to be manipulated for many purposes with the
      standard C string processing functions, which keeps a lot of
      code much simpler.  Without that, you have to start passing
      lengths of things *everywhere* and many APIs become a lot
      more complex (and just to deal with an extremely rare edge
      case.)
      
      Unless someone can exhibit a case where this causes a real
      problem, I can't see this as anything that needs further
      action.
      
      
    6. login: "dkf"
    7. mimetype: "text/plain"
    8. resolution changed to: "Invalid"
    9. status changed to: "Closed"
    10. username: "dkf"
  4. Ticket change [e882e3bfdd] (rid 104657) by wangj1234 on 2002-10-08 23:31:00:

    1. icomment:
      Logged In: YES 
      user_id=624034
      
      Thanks a lot for the explanation.
      
      
    2. login: "wangj1234"
    3. mimetype: "text/plain"
    4. username: "wangj1234"