util/deephash: fix unexported time.Time hashing

Updates tailscale/corp#6311

Change-Id: I33cd7e4040966261c2f2eb3d32f29936aeb7f632
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-07-27 09:10:22 -07:00
committed by Brad Fitzpatrick
parent 51c3d74095
commit 04cf46a762
3 changed files with 56 additions and 2 deletions
+4 -2
View File
@@ -544,9 +544,11 @@ func (h *hasher) hashComplex128v(v reflect.Value) bool {
func (h *hasher) hashTimev(v reflect.Value) bool {
var t time.Time
if v.CanAddr() {
t = *(v.Addr().Interface().(*time.Time))
} else {
t = *(*time.Time)(v.Addr().UnsafePointer())
} else if v.CanInterface() {
t = v.Interface().(time.Time)
} else {
return false
}
b := t.AppendFormat(h.scratch[:1], time.RFC3339Nano)
b[0] = byte(len(b) - 1) // more than sufficient width; if not, good enough.