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

unsafeBytesToString: Fix Go 1.16 SliceHeader vet warnings #13

Merged
merged 1 commit into from
Nov 5, 2021
Merged

unsafeBytesToString: Fix Go 1.16 SliceHeader vet warnings #13

merged 1 commit into from
Nov 5, 2021

Conversation

evanj
Copy link
Collaborator

@evanj evanj commented Nov 4, 2021

Go 1.16 added new vet warnings to check for unsafe uses of
reflect.SliceHeader. To fix them, create an empty slice, then alter
that slice using *reflect.SliceHeader/Stringheader. This is
apparently safer because it works with escape analysis and garbage
collection [1]. The pattern used here is also used in
golang.org/x/sys, so I think this should be safe.

[1] golang/go#40701

Fixes:

value.go:149:35: possible misuse of reflect.StringHeader

Go 1.16 added new vet warnings to check for unsafe uses of
reflect.SliceHeader. To fix them, create an empty slice, then alter
that slice using *reflect.SliceHeader/Stringheader. This is
apparently safer because it works with escape analysis and garbage
collection [1]. The pattern used here is also used in
golang.org/x/sys, so I think this should be safe.

[1] golang/go#40701

Fixes:

value.go:149:35: possible misuse of reflect.StringHeader
Copy link
Owner

@richardartoul richardartoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@richardartoul richardartoul merged commit 61e9275 into richardartoul:master Nov 5, 2021
@evanj evanj deleted the evan.jones/unsafe-string branch November 12, 2021 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants