Skip to content

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

Closed

Description

@jbardin
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.

Activity

  1. ianlancetaylor commented on Sep 15, 2014

    @ianlancetaylor
    Contributor

    Comment 1:

    I think we should document the behaviour.

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

  2. gopherbot commented on Sep 18, 2014

    @gopherbot
    Contributor

    Comment 2:

    CL https://golang.org/cl/143260045 mentions this issue.
  3. rsc commented on Sep 18, 2014

    @rsc
    Contributor

    Comment 3:

    This issue was closed by revision e9ec8e7.

    Status changed to Fixed.

  4. added this to the Go1.4 milestone on Apr 14, 2015
  5. locked and limited conversation to collaborators on Jun 25, 2016
  6. added a commit that references this issue on Jun 25, 2018
    d79d064
  7. added a commit that references this issue on Jul 9, 2018
    d45ed18
  8. added a commit that references this issue on Jul 30, 2018
    2198c8b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions