Tcl Library Source Code

View Ticket
Login
Ticket UUID: f2b25fff771bf3bf87aecd164219731c92fe6c77
Title: Trivial bug in ::csv::split2matrix?
Type: Bug Version: 2.0
Submitter: anonymous Created on: 2026-02-04 16:02:36
Subsystem: csv Assigned To:
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2026-02-04 16:03:20
Resolution: None Closed By: nobody
    Closed on:
Description:
Like other procedures in package csv also ::csv::split2matrix accepts a variable  number of arguments but there are two 4 argument clauses in the switch command body, the second of them clearly handling 5 arguments instead. The package uses a foreach command to assign variables from the argument list which seems an idiomatic form in use before lassign was introduced

--- tcllib-2.0+dfsg/modules/csv/csv.tcl	2024-09-13 20:48:12.000000000 +0200
+++ ./csv.tcl	2026-02-04 17:02:00.567735401 +0100
@@ -575,12 +575,12 @@
     set sepChar   ,
     set expand    none
 
+    lassign $args a b c d e
     switch -exact -- [llength $args] {
 	2 {
 	    foreach {m line} $args break
 	}
 	3 {
-	    foreach {a b c} $args break
 	    if {[string equal $a "-alternate"]} {
 		set alternate 1
 		set m         $b
@@ -592,7 +592,6 @@
 	    }
 	}
 	4 {
-	    foreach {a b c d} $args break
 	    if {[string equal $a "-alternate"]} {
 		set alternate 1
 		set m         $b
@@ -605,8 +604,7 @@
 		set expand  $d
 	    }
 	}
-	4 {
-	    foreach {a b c d e} $args break
+	5 {
 	    if {![string equal $a "-alternate"]} {
 		return -code error "wrong#args: Should be ?-alternate? m line ?separator? ?expand?"
 	    }