You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#13671 was filed to add a note in the documentation that the Buffer.Bytes() slice may become invalid if the buffer is later reused. The docs now look like:
// Bytes returns a slice of length b.Len() holding the unread portion of the buffer.
// The slice is valid for use only until the next buffer modification (that is,
// only until the next call to a method like Read, Write, Reset, or Truncate).
// The slice aliases the buffer content at least until the next buffer modification,
// so immediate changes to the slice will affect the result of future reads.
I think this is inaccurate. As far as I can tell, Read, Reset and Truncate are all safe - their use alone never changes the contents of the buffer.
There are two ways I can see the data becoming invalid:
a Bytes() call modifies the slice contents directly (already mentioned in the last sentence)
Truncate() is called and any write happens (writes without truncation can't harm)
So I think the doc should reflect that. Perhaps something like:
// The slice is valid for use only until the next buffer modification (that is,
// only until the next call to a method like Truncate or Reset and any writes).
The text was updated successfully, but these errors were encountered:
#13671 was filed to add a note in the documentation that the
Buffer.Bytes()
slice may become invalid if the buffer is later reused. The docs now look like:I think this is inaccurate. As far as I can tell,
Read
,Reset
andTruncate
are all safe - their use alone never changes the contents of the buffer.There are two ways I can see the data becoming invalid:
Bytes()
call modifies the slice contents directly (already mentioned in the last sentence)Truncate()
is called and any write happens (writes without truncation can't harm)So I think the doc should reflect that. Perhaps something like:
The text was updated successfully, but these errors were encountered: