aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2015-04-07 21:28:05 +0200
committerSverker Eriksson <[email protected]>2015-04-07 21:28:05 +0200
commite3f21d4911117b80e80ea4a07f3532ad39ede16b (patch)
tree7f904979e2d096a12455b692760e0868a8e30a54
parent6492bf35902f476ef0eac972ef49c424fa6d8bc6 (diff)
downloadotp-e3f21d4911117b80e80ea4a07f3532ad39ede16b.tar.gz
otp-e3f21d4911117b80e80ea4a07f3532ad39ede16b.tar.bz2
otp-e3f21d4911117b80e80ea4a07f3532ad39ede16b.zip
erts: Fix bug in map_from_list when keys clash in both value and hash
Subtle bug in qsort callback. Cast from Sint to int does not retain sign.
-rw-r--r--erts/emulator/beam/erl_map.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/erts/emulator/beam/erl_map.c b/erts/emulator/beam/erl_map.c
index 4acf830655..14a8afe3a6 100644
--- a/erts/emulator/beam/erl_map.c
+++ b/erts/emulator/beam/erl_map.c
@@ -860,7 +860,12 @@ static Eterm hashmap_from_chunked_array(ErtsHeapFactory *factory, hxnode_t *hxns
#undef HALLOC_EXTRA
static int hxnodecmpkey(hxnode_t *a, hxnode_t *b) {
- return CMP_TERM(CAR(list_val(a->val)), CAR(list_val(b->val)));
+ Sint c = CMP_TERM(CAR(list_val(a->val)), CAR(list_val(b->val)));
+#if ERTS_SIZEOF_ETERM <= SIZEOF_INT
+ return c;
+#else
+ return c > 0 ? 1 : (c < 0 ? -1 : 0);
+#endif
}
static int hxnodecmp(hxnode_t *a, hxnode_t *b) {