summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-02-13 00:42:29 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-02-13 00:42:29 -0800
commit5cb7b80bc96c4dd7929a8d9ce299af875085a7d2 (patch)
tree27cdc10815b98cc27e71e50d77a1983f35a87758
parent10e21ee8cc333b1e7d03b8ac22c4cc6bb7ca64e8 (diff)
downloadtxr-5cb7b80bc96c4dd7929a8d9ce299af875085a7d2.tar.gz
txr-5cb7b80bc96c4dd7929a8d9ce299af875085a7d2.tar.bz2
txr-5cb7b80bc96c4dd7929a8d9ce299af875085a7d2.zip
hash-uni: bugfix.
* hash.c (hash_uni): The join function must only be called for the values of keys that exist in both hashes. The broken logic here unconditionally calls the join function for all keys in the left hash (using nil as the right join value when the key doesn't exist in the right hash).
-rw-r--r--hash.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/hash.c b/hash.c
index 0b1f05a3..4242fd58 100644
--- a/hash.c
+++ b/hash.c
@@ -1380,8 +1380,12 @@ val hash_uni(val hash1, val hash2, val join_func)
if (missingp(join_func)) {
sethash(hout, car(entry), cdr(entry));
} else {
- loc ptr = gethash_l(self, hout, car(entry), nulloc);
- set(ptr, funcall2(join_func, cdr(entry), deref(ptr)));
+ val new_p;
+ loc ptr = gethash_l(self, hout, car(entry), mkcloc(new_p));
+ if (new_p)
+ sethash(hout, car(entry), cdr(entry));
+ else
+ set(ptr, funcall2(join_func, cdr(entry), deref(ptr)));
}
}