whyrusleeping / cbor

Other
14 stars 8 forks source link

Fix decoding tags into nil pointers #8

Open lmars opened 7 years ago

lmars commented 7 years ago

I spotted this as I was trying to decode IPLD links into fields of type *cid.Cid, e.g:

dec := cbor.NewDecoder(...)
dec.TagDecoders[cbornode.CBORTagLink] = &cbornode.IpldLinkDecoder{}
dec.Decode(&struct { Link *cid.Cid })

which lead to the following panic:

panic: reflect: call of reflect.Value.Set on zero Value [recovered]
        panic: reflect: call of reflect.Value.Set on zero Value

Initialising the Link field so that it is not a nil pointer fixes this.

I've also run gofmt on the source files.