Reader "Scratch Space" Documentation Clarification

In the documentation for the io.Reader interface:

Read reads up to len§ bytes into p. It returns the number of bytes read (0 <= n <= len§) and any error encountered. Even if Read returns n < len§, it may use all of p as scratch space during the call. If some data is available but not len§ bytes, Read conventionally returns what is available instead of waiting for more.

Does this mean that implementations can overwrite the data that is in the array outside of the slice? Can they overwrite it permanently or do they have to reset the original data before returning to the caller?

No, only Len§ data is overwritten, and yes, previous data in the slice p is overwritten, this cannot be reversed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.