Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

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

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. 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>.
    
  5. is_private changed to: "0"
  6. login: "pooryorick"
  7. priority changed to: "5 Medium"
  8. private_contact changed to: "2b2275eab1118e1fab0016cf1c5702893c6af86c"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "pooryorick"
  13. subsystem changed to: "- New Builtin Commands"
  14. title changed to:
    concatening strings is broken when the "bytes" field of a Tcl_Obj contains invalid data and the type is not tclStringType
    
  15. type changed to: "Bug"