From 26b7dc6cfe26e29f19301da17ac8677263c14c3b Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Tue, 21 Jun 2011 22:19:09 +1000 Subject: Fix crash on dup of object with script rep Signed-off-by: Steve Bennett --- jim.c | 10 ++++++---- regtest.tcl | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/jim.c b/jim.c index 776b91b..3ef60be 100644 --- a/jim.c +++ b/jim.c @@ -136,6 +136,8 @@ static const Jim_HashTableType JimVariablesHashTableType; /* Fast access to the int (wide) value of an object which is known to be of int type */ #define JimWideValue(objPtr) (objPtr)->internalRep.wideValue +#define JimObjTypeName(O) (objPtr->typePtr ? objPtr->typePtr->name : "none") + static int utf8_tounicode_case(const char *s, int *uc, int upper) { int l = utf8_tounicode(s, uc); @@ -2153,17 +2155,17 @@ Jim_Obj *Jim_DuplicateObj(Jim_Interp *interp, Jim_Obj *objPtr) else { Jim_InitStringRep(dupPtr, objPtr->bytes, objPtr->length); } + + /* By default, the new object has the same type as the old object */ + dupPtr->typePtr = objPtr->typePtr; if (objPtr->typePtr != NULL) { if (objPtr->typePtr->dupIntRepProc == NULL) { dupPtr->internalRep = objPtr->internalRep; } else { + /* The dup proc may set a different type, e.g. NULL */ objPtr->typePtr->dupIntRepProc(interp, objPtr, dupPtr); } - dupPtr->typePtr = objPtr->typePtr; - } - else { - dupPtr->typePtr = NULL; } return dupPtr; } diff --git a/regtest.tcl b/regtest.tcl index 49a3d53..7561a60 100644 --- a/regtest.tcl +++ b/regtest.tcl @@ -135,6 +135,13 @@ puts "TEST 20 PASSED" subst "abc\0def" puts "TEST 21 PASSED" +# REGTEST 22 +# 21 June 2011 - crashes on lappend to to value with script rep +set x rand +eval $x +lappend x b +puts "TEST 22 PASSED" + # TAKE THE FOLLOWING puts AS LAST LINE puts "--- ALL TESTS PASSED ---" -- cgit v1.1