From 817b9b601b9d9554766f2d5993eff50a07a733d6 Mon Sep 17 00:00:00 2001 From: hobbs Date: Fri, 31 Aug 2001 17:53:57 +0000 Subject: * tests/compile.test: added compile-11.* interp result checks * generic/tclUtil.c (TclGetIntForIndex): added Tcl_ResetResult before Tcl_AppendStringsToObj to prevent shared object crash when called from bcc instruction. The Tcl_Append* calls that append to the result object that are invoked by bcc insts must remember to call Tcl_ResetResult because the bcc doesn't do this for us. [Bug #456892] --- ChangeLog | 10 ++++++++++ generic/tclUtil.c | 7 ++++++- tests/compile.test | 57 ++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e891de..d7be1b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2001-08-31 Jeff Hobbs + + * tests/compile.test: added compile-11.* interp result checks + * generic/tclUtil.c (TclGetIntForIndex): added Tcl_ResetResult + before Tcl_AppendStringsToObj to prevent shared object crash when + called from bcc instruction. The Tcl_Append* calls that append to + the result object that are invoked by bcc insts must remember to + call Tcl_ResetResult because the bcc doesn't do this for us. + [Bug #456892] + 2001-08-30 Jeff Hobbs * generic/tclIndexObj.c: fixed some casting problems that upset diff --git a/generic/tclUtil.c b/generic/tclUtil.c index daab08c..96deda9 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtil.c,v 1.21 2001/07/31 19:12:07 vincentdarley Exp $ + * RCS: @(#) $Id: tclUtil.c,v 1.22 2001/08/31 17:53:57 hobbs Exp $ */ #include "tclInt.h" @@ -2182,6 +2182,7 @@ TclGetIntForIndex(interp, objPtr, endValue, indexPtr) } else { intforindex_error: if ((Interp *)interp != NULL) { + Tcl_ResetResult(interp); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "bad index \"", bytes, "\": must be integer or end?-integer?", (char *) NULL); @@ -2239,6 +2240,10 @@ TclCheckBadOctal(interp, value) if (*p == '\0') { /* Reached end of string */ if (interp != NULL) { + /* + * Don't reset the result here because we want this result + * to be added to an existing error message as extra info. + */ Tcl_AppendResult(interp, " (looks like invalid octal number)", (char *) NULL); } diff --git a/tests/compile.test b/tests/compile.test index 2a8d6b8..5e81a5c 100644 --- a/tests/compile.test +++ b/tests/compile.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: compile.test,v 1.10 2001/08/22 13:57:53 msofer Exp $ +# RCS: @(#) $Id: compile.test,v 1.11 2001/08/31 17:53:57 hobbs Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -197,7 +197,47 @@ test compile-10.1 {BLACKBOX: exception stack overflow} { } } {} - +test compile-11.1 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { + # shared object - Interp result && Var 'r' + set r [list foobar] + # command that will add error to result + lindex a bogus + } + list [catch {p} msg] $msg +} {1 {bad index "bogus": must be integer or end?-integer?}} +test compile-11.2 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; string index a bogus } + list [catch {p} msg] $msg +} {1 {bad index "bogus": must be integer or end?-integer?}} +test compile-11.3 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; string index a 09 } + list [catch {p} msg] $msg +} {1 {bad index "09": must be integer or end?-integer? (looks like invalid octal number)}} +test compile-11.4 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; array set var {one two many} } + list [catch {p} msg] $msg +} {1 {list must have an even number of elements}} +test compile-11.5 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; incr foo } + list [catch {p} msg] $msg +} {1 {can't read "foo": no such variable}} +test compile-11.6 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; incr foo bogus } + list [catch {p} msg] $msg +} {1 {expected integer but got "bogus"}} +test compile-11.7 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; expr !a } + list [catch {p} msg] $msg +} {1 {syntax error in expression "!a"}} +test compile-11.8 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; expr {!a} } + list [catch {p} msg] $msg +} {1 {syntax error in expression "!a"}} +test compile-11.9 {Tcl_Append*: ensure Tcl_ResetResult is used properly} { + proc p {} { set r [list foobar] ; llength "\{" } + list [catch {p} msg] $msg +} {1 {unmatched open brace in list}} # cleanup catch {rename p ""} @@ -207,16 +247,3 @@ catch {unset y} catch {unset a} ::tcltest::cleanupTests return - - - - - - - - - - - - - -- cgit v0.12