You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
strings: use a closure for FieldsFunc may result in a panic #8738
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
ianlancetaylor commentedon Sep 15, 2014
Comment 1:
Labels changed: added repo-main, release-go1.4, documentation.
gopherbot commentedon Sep 18, 2014
Comment 2:
rsc commentedon Sep 18, 2014
Comment 3:
This issue was closed by revision e9ec8e7.
Status changed to Fixed.
bytes, strings: document that FieldsFunc f must not be stateful
bytes, strings: document that FieldsFunc f must not be stateful
bytes, strings: document that FieldsFunc f must not be stateful