Open
Description
go version devel go1.24-140308837f Mon Oct 21 15:30:47 2024 +0200 darwin/arm64
When the lengths of two slices are "paired" (dst = dst[:len(src)]
), the compiler is smart enough to apply ifs to both, but if you reslice them the pairing is lost.
func foo(src, dst []byte) {
dst = dst[:len(src)]
for len(src) >= 50 {
_ = (*[50]byte)(src) // no bounds check
_ = (*[50]byte)(dst) // no bounds check
}
}
func bar(src, dst []byte) {
dst = dst[:len(src)]
for len(src) >= 50 {
src = src[50:] // no bounds check
dst = dst[50:] // bounds check!
}
}