On Tue, May 19, 2020 at 7:53 PM Adrian Ratnapala
<
adrian.r...@gmail.com> wrote:
>
> I'd have expected that to work, because syntactically the slice is
> assigned to only after the new, smaller slice is fully constructed --
> including all the data copying. But it still make me twitchy about
> the possibility that the runtime shortens the slice before reading all
> the data, resulting in an out-of-bounds read.
>
> As defensive programming, you can first make an explicit slice
> variable for the tail and then do the append.
>
> tail := s[i+1:]
> s = append(s[:i], tail...)
> // tail is still in scope ... so maybe that makes a differences?
>
> I'd be interested to see if this changes anything. Because if it
> works, it smells like a bug in the runtime.
slice. E.g., see