aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2014-04-23 10:13:16 +1000
committerSteve Bennett <steveb@workware.net.au>2014-04-23 14:36:24 +1000
commite436dbdf4e0c917695cacf6674ae9997faa1b6ff (patch)
tree45d7339abd977d64f23e5a12f9642cb6f858c7d1
parent1aa2d1d9e78a6b3d566a7c1cd57ac38d8bcc00f7 (diff)
downloadjimtcl-e436dbdf4e0c917695cacf6674ae9997faa1b6ff.zip
jimtcl-e436dbdf4e0c917695cacf6674ae9997faa1b6ff.tar.gz
jimtcl-e436dbdf4e0c917695cacf6674ae9997faa1b6ff.tar.bz2
array: avoid crash on unset variable
Fix the case where the variable does not exist and a pattern is specified. Courtesy of coverity Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-array.c5
-rw-r--r--regtest.tcl5
2 files changed, 10 insertions, 0 deletions
diff --git a/jim-array.c b/jim-array.c
index bf07e07..39cd168 100644
--- a/jim-array.c
+++ b/jim-array.c
@@ -109,6 +109,11 @@ static int array_cmd_unset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
objPtr = Jim_GetVariable(interp, argv[0], JIM_NONE);
+ if (objPtr == NULL) {
+ /* Doesn't exist, so nothing to do */
+ return JIM_OK;
+ }
+
if (Jim_DictPairs(interp, objPtr, &dictValuesObj, &len) != JIM_OK) {
return JIM_ERR;
}
diff --git a/regtest.tcl b/regtest.tcl
index a2a398f..3aaf3d2 100644
--- a/regtest.tcl
+++ b/regtest.tcl
@@ -233,6 +233,11 @@ proc c {} {}
catch -eval a
puts "TEST 32 PASSED"
+# REGTEST 33
+# unset array variable which doesn't exist
+array unset blahblah abc
+puts "TEST 33 PASSED"
+
# TAKE THE FOLLOWING puts AS LAST LINE
puts "--- ALL TESTS PASSED ---"