hash.wyhash: fix memory errors (#10051)

pull/10052/head
ka-weihe 2021-05-08 20:09:58 +02:00 committed by GitHub
parent c16d4911c2
commit 0d205510d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import hash as wyhash
module hash
struct WyHashTest {
s string
@ -13,9 +13,13 @@ fn test_wyhash() {
WyHashTest{'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 5, 0xe062dfda99413626},
]
for test in tests {
got := wyhash.sum64(test.s.bytes(), test.seed)
got := wyhash64(test.s.str, u64(test.s.len), test.seed)
// println(' # GOT: $got | $got.hex()')
// println(' # EXPECTED: $test.expected | $test.expected.hex()')
assert got == test.expected
}
s := '/v/vmaster/vlib/v/fmt/tests/maps_of_fns_with_string_keys_keep.vv'
x := sum64_string(s, 5).hex_full()
println(x)
}

View File

@ -25,15 +25,16 @@ const (
[inline]
pub fn sum64_string(key string, seed u64) u64 {
return wyhash64(key.str, u64(key.len), seed)
return wyhash_c(key.str, u64(key.len), seed)
}
[inline]
pub fn sum64(key []byte, seed u64) u64 {
return wyhash64(&byte(key.data), u64(key.len), seed)
return wyhash_c(&byte(key.data), u64(key.len), seed)
}
[inline]
// This is an outdated version of wyhash with memory errors!
[deprecated; inline]
fn wyhash64(key &byte, len u64, seed_ u64) u64 {
if len == 0 {
return 0