3 ms·
I noticed a few things with the Go code that confused me. I haven't coded in Go in quite some time, so I may be way off. `copy(buf[1:], h.Pstr)` In this line,
by jamra 7y ago
I noticed a few things with the Go code that confused me. I haven't coded in Go in quite some time, so I may be way off.
`copy(buf[1:], h.Pstr)`
In this line, are you copying the entire buffer to a string? Doesn't it overflow into other data elements?
Also, and I may be wrong, in the following line, it appears that you are casting to a []byte when it's already a slice of bytes, which should still be fine.
`peers[i].Port = binary.BigEndian.Uint16([]byte(peersBin[offset+4 : offset+6])`
I really enjoyed the tone and the code. I'm not done with the article, but I love it so far.
- eat_veggies 7y agothank you for the feedback! It's really helpful. copy's arguments are like copy(destination, source) so we're copying the string into the buffer. Also, copy will never overflow because it will only copy up to the length of the shortest buffer. you're right about the unnecessary cast to []byte -- that function used to take a string as arguments, and when I changed it, I didn't change the rest of it. I've removed it.