Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 9737d09940213855e8579da8487919a8e6450bca
Ticket: 32b6159246574b9480f83800d4347126c3998af9
lreplace where idx2 < idx1 not compiled correctly
User & Date: anonymous on 2015-02-19 02:50:19
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    % lreplace {1 2 3} 2 0
    1 2 2 3
    
    It looks like TclCompileLreplaceCommand doesn't handle idx2 < idx1 properly.  Similar errors with >3 arguments too.
    
    Hopefully the following patch formats correctly - chiselapp's struggling to sync.
    
    Index: generic/tclCompCmdsGR.c
    ==================================================================
    --- generic/tclCompCmdsGR.c
    +++ generic/tclCompCmdsGR.c
    @@ -1498,10 +1498,14 @@
    
         tokenPtr = TokenAfter(tokenPtr);
         if (GetIndexFromToken(tokenPtr, &idx2) != TCL_OK) {
            return TCL_ERROR;
         }
    +
    +    if(idx2 != INDEX_END && idx2 < idx1) {
    +       idx2 = idx1-1;
    +    }
         
         /*
          * Work out what this [lreplace] is actually doing.
          */
    
    ==================================================================
    --- tests/lreplace.test
    +++ tests/lreplace.test
    @@ -135,14 +135,23 @@
     } {}
     # Note that this test will fail in 8.5
     test lreplace-4.2 {Bug ccc2c2cc98: lreplace edge case} {
         lreplace { } 1 1
     } {}
    +test lreplace-4.3 {lreplace edge case} {
    +    lreplace {1 2 3} 2 0
    +} {1 2 3}
    +test lreplace-4.4 {lreplace edge case} {
    +    lreplace {1 2 3 4 5} 3 1
    +} {1 2 3 4 5}
    +test lreplace-4.4 {lreplace edge case} {
    +    lreplace {1 2 3 4 5} 3 0 _
    +} {1 2 3 _ 4 5}
     
     # cleanup
     catch {unset foo}
     ::tcltest::cleanupTests
     return
     
     # Local Variables:
     # mode: tcl
     # End:
    
  5. foundin changed to: "8.6.3"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "cb02a4a25e8da92f2790bc307bf01ef24ce6053e"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "47. Bytecode Compiler"
  15. title changed to: "lreplace where idx2 < idx1 not compiled correctly"
  16. type changed to: "Bug"