On Sun, May 26, 2019 at 11:30 AM Sergey Kamardin <gob...@gmail.com> wrote: > > func ReadHeader(r io.Reader) (Header, error) { > var ( > b [16]byte > bts []byte > ) > h := (*reflect.SliceHeader)(unsafe.Pointer(&bts)) > *h = reflect.SliceHeader{ > Data: uintptr(unsafe.Pointer(&b)), > Len: len(b), > Cap: len(b), > }
This is not valid. The rule is that SliceHeader is only valid when inspecting an actual slice header. You have to write h.Data = uintptr(unsafe.Pointer(&b)) h.Len = len(b) h.Cap = len(b) I assume this is reduced greatly from the real code, as you could also just write bts = b[:] Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXoGsja8GH5CtrqhR6dnKuSSFT%3DWbt1p668SwXQKvXRDQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.