Em terça-feira, 15 de outubro de 2019 07:16:35 UTC-3, Stuart Davies escreveu: > > > if p.LineCount >= len(p.Offsets) { > newLen := p.LineCount + 50 > sb := make([]int64, newLen) > for i := 0; i < p.LineCount; i++ { > sb[i] = p.Offsets[i] > } > p.Offsets = sb > } > > Note that this code executes only when p.LineCount >= len(p.Offsets), your loop is based on p.LineCount and inside the loop you try to access p.Offsets[i] (where i increments until it reaches p.LineCount). When i >= len(p.Offsets) your code tries to access beyond p.Offsets bounds and this may be the cause of the panic you reported. So, in order to copy (if you don't choose to use the builtins copy() or append() functions) you should control your loop based on the length of the smaller array/slice, like this: for i := 0; i < p.Offsets; i++ .
Best regards! Luis Otavio -- 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/b9ec8f8a-ef4f-4e8b-a7c4-b82c4dfb389e%40googlegroups.com.