Overview
| Artifact ID: | c9c4d0f6c91229119b82eac0c065193a45c90566 |
|---|---|
| Ticket: | 619164ffffffffffffffffffffffffffffffffff
Incorrect conversion of \000 using UTF-8 |
| User & Date: | nobody on 2002-10-06 05:47:12 |
Changes
- assignee changed to: "nijtmans"
- cmimetype changed to: "text/plain"
- 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". - foundin changed to: "obsolete ----"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "nobody"
- subsystem changed to: "44. UTF-8 Strings"
- title changed to: "Incorrect conversion of \000 using UTF-8"
- type changed to: "Bug"