mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 11:41:39 +00:00
util/deephash: fix map hashing to actually hash elements
Fixes #4868 Change-Id: I574fd139cb7f7033dd93527344e6aa0e625477c7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
4005134263
commit
36ea837736
@ -342,7 +342,7 @@ func (h *hasher) hashMap(v reflect.Value) {
|
|||||||
e.SetIterValue(iter)
|
e.SetIterValue(iter)
|
||||||
mh.h.reset()
|
mh.h.reset()
|
||||||
mh.h.hashValue(k)
|
mh.h.hashValue(k)
|
||||||
mh.h.hashValue(v)
|
mh.h.hashValue(e)
|
||||||
sum.xor(mh.h.sum())
|
sum.xor(mh.h.sum())
|
||||||
}
|
}
|
||||||
h.bw.Write(append(h.scratch[:0], sum.sum[:]...)) // append into scratch to avoid heap allocation
|
h.bw.Write(append(h.scratch[:0], sum.sum[:]...)) // append into scratch to avoid heap allocation
|
||||||
|
@ -132,6 +132,15 @@ func TestDeepHash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that we actually hash map elements. Whoops.
|
||||||
|
func TestIssue4868(t *testing.T) {
|
||||||
|
m1 := map[int]string{1: "foo"}
|
||||||
|
m2 := map[int]string{1: "bar"}
|
||||||
|
if Hash(m1) == Hash(m2) {
|
||||||
|
t.Error("bogus")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getVal() []any {
|
func getVal() []any {
|
||||||
return []any{
|
return []any{
|
||||||
&wgcfg.Config{
|
&wgcfg.Config{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user