Skip to content

Commit

Permalink
hash.wyhash: fix memory errors (#10051)
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-weihe committed May 8, 2021
1 parent c16d491 commit 0d20551
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions vlib/hash/hash_wyhash_test.v
@@ -1,4 +1,4 @@
import hash as wyhash
module hash

struct WyHashTest {
s string
Expand All @@ -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)
}
7 changes: 4 additions & 3 deletions vlib/hash/wyhash.v
Expand Up @@ -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
Expand Down

0 comments on commit 0d20551

Please sign in to comment.