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

Rewrite unsafeStringToBytes to satisfy 1.16 vet check #466

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

robbertvanginkel
Copy link
Contributor

Fixes #465.

According to https://golang.org/pkg/unsafe/#Pointer (6), one of the only safe ways to use pointers:

Conversion of a reflect.SliceHeader or reflect.StringHeader Data field to or from Pointer.
...
In general, reflect.SliceHeader and reflect.StringHeader should be used only as *reflect.SliceHeader and *reflect.StringHeader pointing at actual slices or strings, never as plain structs. A program should not declare or allocate variables of these struct types.

This rewrites the unsafe to only modify to not allocate a reflect.SliceHeader manually making the vet check happy.

@codecov
Copy link

codecov bot commented Feb 17, 2021

Codecov Report

Merging #466 (2632889) into dev (b7d2a80) will increase coverage by 0.10%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #466      +/-   ##
==========================================
+ Coverage   78.86%   78.96%   +0.10%     
==========================================
  Files         125      125              
  Lines       16001    15981      -20     
==========================================
+ Hits        12619    12620       +1     
+ Misses       2077     2056      -21     
  Partials     1305     1305              
Impacted Files Coverage Δ
wire/unsafe.go 100.00% <100.00%> (ø)
wire/type_string.go 0.00% <0.00%> (ø)
ast/basetypeid_string.go 75.00% <0.00%> (+51.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7d2a80...2632889. Read the comment docs.

@robbertvanginkel robbertvanginkel changed the title Rewrit unsafeStringToBytes to satisfy 1.16 vet check Rewrite unsafeStringToBytes to satisfy 1.16 vet check Feb 17, 2021
Copy link
Contributor

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

@robbertvanginkel robbertvanginkel merged commit 98f1a23 into dev Feb 17, 2021
@robbertvanginkel robbertvanginkel deleted the robbert/116fix branch February 17, 2021 17:57
r-hang pushed a commit that referenced this pull request Feb 18, 2021
Fixes #465.

According to https://golang.org/pkg/unsafe/#Pointer (6), one of the only safe ways to use pointers:
> Conversion of a reflect.SliceHeader or reflect.StringHeader Data field to or from Pointer.
...
> In general, reflect.SliceHeader and reflect.StringHeader should be used only as *reflect.SliceHeader and *reflect.StringHeader pointing at actual slices or strings, never as plain structs. A program should not declare or allocate variables of these struct types.

This rewrites the unsafe to only modify to not allocate a `reflect.SliceHeader ` manually making the vet check happy.
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.

Fix possible misuse of reflect.SliceHeader vet error
2 participants