Artifacts Associated With Ticket 619164ffffffffffffffffffffffffffffffffff
Ticket change [c9c4d0f6c9] (rid 122344) by nobody on 2002-10-06 05:47:12:
- assignee initialized to: "nijtmans"
- cmimetype initialized to: "text/plain"
- 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". - foundin initialized to: "obsolete ----"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "44. UTF-8 Strings"
- title initialized to: "Incorrect conversion of \000 using UTF-8"
- type initialized to: "Bug"
Ticket change [8662fbb1f4] (rid 131500) by hobbs on 2002-10-07 23:51:11:
- assignee changed to: "hobbs"
Ticket change [3710710930] (rid 107212) by dkf on 2002-10-08 16:58:32:
- assignee changed to: "dkf"
- closedate changed to: "2002-10-08T09:58:32"
- closer changed to: "dkf"
- foundin changed to: "obsolete: 8.4.0"
- 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.
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
- username: "dkf"
Ticket change [e882e3bfdd] (rid 104657) by wangj1234 on 2002-10-08 23:31:00:
- icomment:
Logged In: YES user_id=624034 Thanks a lot for the explanation.
- login: "wangj1234"
- mimetype: "text/plain"
- username: "wangj1234"
- icomment: