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: use a closure for FieldsFunc may result in a panic #8738

Closed
jbardin opened this issue Sep 15, 2014 · 3 comments
Closed

strings: use a closure for FieldsFunc may result in a panic #8738

jbardin opened this issue Sep 15, 2014 · 3 comments

Comments

@jbardin
Copy link
Contributor

jbardin commented Sep 15, 2014

go1.3.1

FieldsFunc runs over the runes twice. If a closure is used, and the underlying state
does't match the first run, there may be a panic.

The following panics (http://play.golang.org/p/P1MKh8GKaF)

    state := false
    f := func(c rune) bool {
        switch c {
        case '1':
            fmt.Println(state)
            state = !state
            return state
        default:
            fmt.Println("true")
            return true
        }
    }
    strings.FieldsFunc(" 1", f)




This should be safe from panics, or at least clearly document that FieldsFunc is run
twice.
@ianlancetaylor
Copy link
Contributor

Comment 1:

I think we should document the behaviour.

Labels changed: added repo-main, release-go1.4, documentation.

@gopherbot
Copy link

Comment 2:

CL https://golang.org/cl/143260045 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Sep 18, 2014

Comment 3:

This issue was closed by revision e9ec8e7.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants