Skip to content

Commit b42b592

Browse files
committed
runtime: fix runtime hashing algorithm handling memory addresses dangerously and foes not supports uintptr type
1 parent 900880a commit b42b592

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

std/runtime/maphash.jule

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,18 @@ fn maphash[K](k: K, seed: uintptr): uintptr {
122122
ret unsafe { integ::Emit[uintptr]("{}.type->hash(&{}.data, {})", k, k, seed) }
123123
| comptime::Str:
124124
ret strhash(str(k), seed)
125-
| comptime::Ptr | comptime::SmartPtr:
126-
ret unsafe { memhash((*unsafe)(uintptr(k)), _ptrSize, seed) }
125+
| comptime::Uintptr | comptime::Ptr | comptime::SmartPtr:
126+
z := uintptr(k)
127+
ret unsafe { memhash(&z, _ptrSize, seed) }
127128
| comptime::Bool:
128129
ret boolhash(bool(k), seed)
129130
| comptime::Array:
130131
ret arrayhash(k, seed)
131132
| comptime::Struct:
132133
ret structhash(k, seed)
133134
| comptime::Chan:
134-
ret unsafe { memhash((*unsafe)(uintptr(*(*&hchan)(&k))), _ptrSize, seed) }
135+
z := unsafe { uintptr(*(*&hchan)(&k)) }
136+
ret unsafe { memhash(&z, _ptrSize, seed) }
135137
}
136138
panic("unreachable")
137139
}

0 commit comments

Comments
 (0)