Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strings: Copying Builders allows string mutation #23084

Closed
fweimer opened this issue Dec 11, 2017 · 2 comments
Closed

strings: Copying Builders allows string mutation #23084

fweimer opened this issue Dec 11, 2017 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@fweimer
Copy link
Contributor

fweimer commented Dec 11, 2017

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.

@bradfitz
Copy link
Contributor

Ouch, thanks. Will fix.

@gopherbot
Copy link

Change https://golang.org/cl/83255 mentions this issue: strings: fix two Builder bugs allowing mutation of strings, remove ReadFrom

@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 11, 2017
@dsnet dsnet added this to the Go1.10 milestone Dec 11, 2017
@golang golang locked and limited conversation to collaborators Dec 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants