From 841e6e9cf2cd64cabff87f1387d681df1818e4a6 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 5 Dec 2024 17:06:05 -0300 Subject: [PATCH] Fix critical bug in hashmap that would cause crash with clang++ The code before this fix was relying in undocumented behavior how the C compiler order evaluation of function arguments, and was crashing code compiled with Clang++ --- lib/hashmap.nelua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/hashmap.nelua b/lib/hashmap.nelua index d4303820..16bc3ebd 100644 --- a/lib/hashmap.nelua +++ b/lib/hashmap.nelua @@ -295,7 +295,10 @@ local INVALID_INDEX: usize = (@usize)(-1) *Complexity*: Average case O(1). ]] function hashmapT:__atindex(key: K): *V - return &self.nodes[self:_at(key)].value + -- compute node index first, because it may trigger a rehash that relocate self.nodes + local node_index: usize = self:_at(key) + -- now we can access self.nodes + return &self.nodes[node_index].value end --[[