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

is it safe to add //go:noescape for function Sprintf(format string, a ...interface{}) string please #31387

Closed
superajun opened this issue Apr 10, 2019 · 1 comment

Comments

@superajun
Copy link

when a package fmt's function was called, such as func Sprintf(format string, a ...interface{}) string, it will result in input variables escape to heap. But the fmt function actually is
synchronization semantic, I think it's safe despite its input variables allocated in stack. So if we try to add //go:noescape for function Sprintf, which avoid input variables escape, is there any correctness issue or safe risk please?

@superajun superajun changed the title is it safe to add //go:escape for function Sprintf(format string, a ...interface{}) string please is it safe to add //go:escape for function Sprintf(format string, a ...interface{}) string please Apr 10, 2019
@superajun superajun changed the title is it safe to add //go:escape for function Sprintf(format string, a ...interface{}) string please is it safe to add //go:noescape for function Sprintf(format string, a ...interface{}) string please Apr 10, 2019
@randall77
Copy link
Contributor

No, it is not safe.
See #8618 or #19720.
TL; DR arguments to fmt.Sprintf might escape if they implement Stringer or Formatter and the implementations of those methods escape their arguments.

@golang golang locked and limited conversation to collaborators Apr 9, 2020
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

3 participants