From 72e7c5746f7b65dde16f1956a8ff610feba195f5 Mon Sep 17 00:00:00 2001 From: dkf Date: Sat, 17 Jan 2004 00:52:18 +0000 Subject: Fix a shimmering bug --- ChangeLog | 5 +++++ generic/tclCmdIL.c | 10 +++++++++- tests/cmdIL.test | 6 +++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b248a1f..fcd1540 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-01-17 Donal K. Fellows + + * generic/tclCmdIL.c (Tcl_LassignObjCmd): Add more shimmering + protection for when the list is also one of the variables. + 2004-01-17 Donal K. Fellows BASIC IMPLEMENTATION OF TIP#57 diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 4eee06b..e3f42a9 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdIL.c,v 1.60 2004/01/17 00:38:56 dkf Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.61 2004/01/17 00:52:18 dkf Exp $ */ #include "tclInt.h" @@ -2080,13 +2080,21 @@ Tcl_LassignObjCmd(dummy, interp, objc, objv) } valueObj = emptyObj; } + /* + * Make sure the reference count for the value being assigned + * is greater than one (other reference minimally in the list) + * so we can't get hammered by shimmering. + */ + Tcl_IncrRefCount(valueObj); if (Tcl_ObjSetVar2(interp, objv[i+2], NULL, valueObj, TCL_LEAVE_ERR_MSG) == NULL) { + Tcl_DecrRefCount(valueObj); if (emptyObj != NULL) { Tcl_DecrRefCount(emptyObj); } return TCL_ERROR; } + Tcl_DecrRefCount(valueObj); } if (emptyObj != NULL) { Tcl_DecrRefCount(emptyObj); diff --git a/tests/cmdIL.test b/tests/cmdIL.test index 59e17c0..c7a8b65 100644 --- a/tests/cmdIL.test +++ b/tests/cmdIL.test @@ -8,7 +8,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: cmdIL.test,v 1.20 2004/01/17 00:38:57 dkf Exp $ +# RCS: @(#) $Id: cmdIL.test,v 1.21 2004/01/17 00:52:18 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -498,6 +498,10 @@ test cmdIL-6.12 {lassign command - memory leak testing} -setup { rename getbytes {} rename stress {} } +test cmdIL-6.13 {lassign command - shimmering protection} { + set x {a b c} + list [lassign $x $x y] $x [set $x] $y +} {c {a b c} a b} # cleanup ::tcltest::cleanupTests -- cgit v0.12