aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2021-12-13 16:43:06 +1000
committerSteve Bennett <steveb@workware.net.au>2021-12-13 21:04:18 +1000
commit24b234543c7322d2dd20339b45367fa3f4c53495 (patch)
treeb3353c74bbd4104442438c00ebf84573da1a1b98 /tests
parentececa1d3b24dc4298b831675f597a4a84a14e69a (diff)
downloadjimtcl-24b234543c7322d2dd20339b45367fa3f4c53495.zip
jimtcl-24b234543c7322d2dd20339b45367fa3f4c53495.tar.gz
jimtcl-24b234543c7322d2dd20339b45367fa3f4c53495.tar.bz2
dict: Fix possible duplicate entries when setting
Due to the way hash collisions are managed it is possible to have a sequence where an entry is removed and then another entry is replaced, however the replacement adds an additional entry instead of updating the existing entry. Can be reproduced like this as there is a hash collision between these two keys: dict set d 0,13 X dict set d 8,4 Y dict unset d 0,13 dict set d 8,4 Z Should result in one entry in the dictionary, but instead ends with two. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/dict2.test13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/dict2.test b/tests/dict2.test
index 2a36dc1..99cf605 100644
--- a/tests/dict2.test
+++ b/tests/dict2.test
@@ -1279,5 +1279,18 @@ test dict-23.6 {dict with baddict} -body {
dict with dictbad {}
} -returnCodes error -result {missing value to go with key}
+test dict-24.1 {dict hash collision} {
+ set d {}
+ # 0,13 and 8,4 product a hash collision
+ # add both
+ dict set d 0,13 X
+ dict set d 8,4 Y
+ # Now remove the first and update the second
+ dict unset d 0,13
+ dict set d 8,4 Z
+ # There should be 1 entry, not 2
+ dict size $d
+} 1
+
testreport