From 14fd6b059e2e8ea5c2d5758b8a2800f3413e02f3 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 11 Mar 2020 15:33:28 +0000 Subject: lpop.test: added test illustrating segfault in [234d6c811d] (and small review - stability of tests depending on outside circumstances, e. g. in case of -singleproc) --- tests/lpop.test | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/lpop.test b/tests/lpop.test index 89b651c..3e28978 100644 --- a/tests/lpop.test +++ b/tests/lpop.test @@ -16,6 +16,7 @@ if {[lsearch [namespace children] ::tcltest] == -1} { namespace import -force ::tcltest::* } +unset -nocomplain no; # following tests expecting var "no" does not exists test lpop-1.1 {error conditions} -returnCodes error -body { lpop no } -result {can't read "no": no such variable} @@ -23,32 +24,36 @@ test lpop-1.2 {error conditions} -returnCodes error -body { lpop no 0 } -result {can't read "no": no such variable} test lpop-1.3 {error conditions} -returnCodes error -body { - set no "x {}x" - lpop no + set l "x {}x" + lpop l } -result {list element in braces followed by "x" instead of space} test lpop-1.4 {error conditions} -returnCodes error -body { - set no "x y" - lpop no -1 + set l "x y" + lpop l -1 } -result {index "-1" out of range} +test lpop-1.4b {error conditions (also check SF on empty list variable, bug [234d6c811d])} -body { + set l "x y" + list [lpop l] [lpop l] [catch {lpop l} v] $v [catch {lpop l 0} v] $v $l +} -result {y x 1 {index "end" out of range} 1 {index "0" out of range} {}} test lpop-1.5 {error conditions} -returnCodes error -body { - set no "x y z" - lpop no 3 + set l "x y z" + lpop l 3 } -result {index "3" out of range} ;#-errorCode {TCL OPERATION LPOP BADINDEX} test lpop-1.6 {error conditions} -returnCodes error -body { - set no "x y" - lpop no end+1 + set l "x y" + lpop l end+1 } -result {index "end+1" out of range} test lpop-1.7 {error conditions} -returnCodes error -body { - set no "x y" - lpop no {} + set l "x y" + lpop l {} } -match glob -result {bad index *} test lpop-1.8 {error conditions} -returnCodes error -body { - set no "x y" - lpop no 0 0 0 0 1 + set l "x y" + lpop l 0 0 0 0 1 } -result {index "1" out of range} test lpop-1.9 {error conditions} -returnCodes error -body { - set no "x y" - lpop no {1 0} + set l "x y" + lpop l {1 0} } -match glob -result {bad index *} test lpop-2.1 {basic functionality} -body { -- cgit v0.12 From 7cf28a1e23e36cae089d6ed13eeecf2d0b618f97 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 11 Mar 2020 15:48:07 +0000 Subject: close [234d6c811d]: fixed segfault on empty list variable by "lpop" without index --- generic/tclCmdIL.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index f74368a..94ff2cc 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -2587,6 +2587,14 @@ Tcl_LpopObjCmd( */ if (objc == 2) { + if (!listLen) { + /* empty list, throw the same error as with index "end" */ + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "index \"end\" out of range", -1)); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX" + "OUTOFRANGE", NULL); + return TCL_ERROR; + } elemPtr = elemPtrs[listLen - 1]; Tcl_IncrRefCount(elemPtr); } else { -- cgit v0.12