Skip to content

Commit

Permalink
Fix critical bug in hashmap that would cause crash with clang++
Browse files Browse the repository at this point in the history
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++
  • Loading branch information
edubart committed Dec 5, 2024
1 parent 038c45f commit 841e6e9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/hashmap.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ local INVALID_INDEX: usize <comptime> = (@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

--[[
Expand Down

0 comments on commit 841e6e9

Please sign in to comment.