I take the first three bytes of a frame as a header and append a checksum to it: buf := []byte{1, 2, 3, 4, 5}; head := buf[:3]; head = append(head, 0xFF). Afterwards buf is [1 2 3 255 5]: the fourth byte of my original frame has been overwritten. But when I append three bytes instead of one, buf stays intact and head seems to become independent.
What are the rules here? I thought a slice was a separate value. How do I take a sub-slice that I can safely append to, and how do I join two slices without side effects?




