Closed
Description
This program:
package main
import (
"fmt"
"strings"
)
func main() {
var b1 strings.Builder
b1.Grow(3)
b2 := b1
b1.WriteString("foo")
s := b1.String()
fmt.Printf("string before patching: %#v\n", s)
b2.WriteString("bar")
fmt.Printf("string after patching: %#v\n", s)
}
Prints:
string before patching: "foo"
string after patching: "bar"
I think another level of indirection is needed in the implementation, so that the internal buffer is shared even after a copy has been made.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
bradfitz commentedon Dec 11, 2017
Ouch, thanks. Will fix.
gopherbot commentedon Dec 11, 2017
Change https://golang.org/cl/83255 mentions this issue:
strings: fix two Builder bugs allowing mutation of strings, remove ReadFrom