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

ctxlock: use safe implementation of keyify #1459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions pkg/ctxlock/keyify.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
//go:build !safe

package ctxlock

import (
"hash/fnv"
"reflect"
"unsafe"
)

// Keyify returns an int64 serialized into a []byte.
func keyify(key string) []byte {
const maxsize = 0x7fff0000
l := len(key)
h := fnv.New64a()
// This is (obviously) unsafe -- it provides mutable access to "key".
// However, it doesn't outlive this Write call, and the implementation
// can be read to ensure it doesn't modify it.
h.Write((*[maxsize]byte)(unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&key)).Data))[:l:l])
h.Write([]byte(key))
b := make([]byte, 0, 8)
return h.Sum(b)
}
17 changes: 0 additions & 17 deletions pkg/ctxlock/keyify_safe.go

This file was deleted.

Loading