Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash#rehash removes @first elements from hash #14602

Closed
BlobCodes opened this issue May 21, 2024 · 0 comments · Fixed by #14606
Closed

Hash#rehash removes @first elements from hash #14602

BlobCodes opened this issue May 21, 2024 · 0 comments · Fixed by #14606

Comments

@BlobCodes
Copy link
Contributor

Bug Report

The following code should explain the issue:

hash = {"a" => 2, "b" => 3, "c" => 1}
hash.delete("a")

puts hash # => {"b" => 3, "c" => 1}
hash.rehash
puts hash # => {"c" => 1}
hash.rehash
puts hash # => {}

# ---

hash = {"a" => 2, "b" => 3, "c" => 1, "d" => 0, "e" => 6}
hash.delete("a")
hash.delete("b")

puts hash # => {"c" => 1, "d" => 0, "e" => 6}
hash.rehash
puts hash # => {"e" => 6}
hash.rehash
puts hash # => {}

The hash deletes @first elements at the beginning of of hash.

The state of the Hash seems to be invalid after the rehash as it's also possible to get segfaults:

hash = {"a" => 2, "b" => 3}
hash.delete("a")
hash.rehash
hash.first_key[0] # => Invalid memory access (signal 11) at address 0x4

$ crystal -v
Crystal 1.12.1 [4cea10199] (2024-04-11)

LLVM: 15.0.7
Default target: x86_64-unknown-linux-gnu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants