From 38f1d6c19d8ec29ae5645ce677839a301f798df3 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Wed, 27 Dec 2023 15:57:51 +0100 Subject: [PATCH] add comments Change-Id: I2e9cea8d39c1d1e9df9ef7e8172060400b596dae --- src/internal/bytealg/bytealg.go | 5 +++-- src/strings/builder.go | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/internal/bytealg/bytealg.go b/src/internal/bytealg/bytealg.go index 53dfa38a93..6b79a2e1fa 100644 --- a/src/internal/bytealg/bytealg.go +++ b/src/internal/bytealg/bytealg.go @@ -112,6 +112,7 @@ func LastIndexRabinKarp[T string | []byte](s, sep T) int { } // MakeNoZero makes a slice of length n and capacity of at least n Bytes -// without zeroing the bytes. It is the caller's responsibility to -// ensure uninitialized bytes do not leak to the end user. +// without zeroing the bytes (including the bytes between len and cap). +// It is the caller's responsibility to ensure uninitialized bytes +// do not leak to the end user. func MakeNoZero(n int) []byte diff --git a/src/strings/builder.go b/src/strings/builder.go index 189dadb1e7..7c9b686241 100644 --- a/src/strings/builder.go +++ b/src/strings/builder.go @@ -15,7 +15,11 @@ import ( // Do not copy a non-zero Builder. type Builder struct { addr *Builder // of receiver, to detect copies by value - buf []byte + + // External users should never get direct access to this buffer, since + // the slice at some point will be converted to a string using unsafe, also + // data between len(buf) and cap(buf) might be uninitialized. + buf []byte } // noescape hides a pointer from escape analysis. It is the identity function