From 55a0a1c9c2a6df4f05d539f0fc67a8c7052a338f Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Thu, 18 Feb 2021 17:51:05 +0100 Subject: fixed unexpected reflect behavior After tls.Unmarshal() an empty slice is not assigned the nil value, but rather a slice of zero length. It is in contrast to NewTreeHeadV1(), which assigns a nil value. Therefore, reflect.DeepEqual() considers them to be different. Fixed by assigning an empty tree head extension as `make([]byte, 0)`, and not looking for nil values but rather zero-length values with len(). Further read: "Note that a non-nil empty slice and a nil slice [...] are not deeply equal." (https://golang.org/pkg/reflect/#DeepEqual). --- type.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'type.go') diff --git a/type.go b/type.go index 72aeecc..db9ddc6 100644 --- a/type.go +++ b/type.go @@ -282,7 +282,7 @@ func NewTreeHeadV1(lr *types.LogRootV1) *TreeHeadV1 { uint64(lr.TimestampNanos / 1000 / 1000), uint64(lr.TreeSize), NodeHash{lr.RootHash}, - nil, + make([]byte, 0), } } -- cgit v1.2.3