Overview
| Artifact ID: | 3ab3ed9a7efd2f2408c70780107e65d580467587319ef1f635913ed51dcf829e |
|---|---|
| Ticket: | b3628609ad73a105f0e51435e0e0ac5b8205fad7
concatenating strings is broken when the "bytes" field of a Tcl_Obj contains invalid data and the type is not tclStringType |
| User & Date: | pooryorick on 2023-04-21 21:25:11 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
When the following script is evaluated by trunk build of tcltest, <code>p1</code> produces the expected value, <code>2</code>, whereas <code>p2</code> produces an incorrect value, <code>1</code>. <blockquote><code><verbatim> proc p1 {} { string length [testbytestring \xc0][testbytestring \x80] } proc p2 {} { string length [list [testbytestring \xc0]][testbytestring \x80] } puts [p1] puts [p2] </verbatim></code></blockquote> For <code>p1</code>, <code>TclStringCat()</code> uses the <code>tclStringType</code> internal representation where <code>\xc0</code> is treated as a single character and so is <code>\x80</code>, and therefore character concatenation is performed producing the correct result. For <code>p2</code>, <code>tclStringCat</code> does not use <code>tclStringType</code> because it detects that there is another internal representation already in place. Instead, it simply concatenates the "bytes" fields of the values, and therefore byte concatenation is performed, so the two invalid byte sequences become a single valid byte sequence encoding one character. If the body of <code>p2</code> is evaluated directly instead of in the body of a procedure, the result is <code>2</code> instead of <code>1</code>. This happens because there is no bytecode to execute, and instead <code>TclEvalEx</code> calls <code>TclSubstTokens()</code>, which does not call <code>TclStringCat</code>, but instead calls <code>Tcl_AppendObjToObj</code>, which replaces the list internal representation with a <code>tclSringType</code> internal representation, and eventually calls <code>AppendUtfToUnicodeRep()</code>. - is_private changed to: "0"
- login: "pooryorick"
- priority changed to: "5 Medium"
- private_contact changed to: "2b2275eab1118e1fab0016cf1c5702893c6af86c"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "pooryorick"
- subsystem changed to: "- New Builtin Commands"
- title changed to:
concatening strings is broken when the "bytes" field of a Tcl_Obj contains invalid data and the type is not tclStringType
- type changed to: "Bug"