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

Set the byte slice cap correctly when unsafely converting string. #3487

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

cyriltovena
Copy link
Contributor

Fixes #3485

Should also unblock #3481

When unsafely converting string to bytes the cap of the bytes is lost but not when doing bytes to string.
It seems that this is only a problem when using go 1.16 or when using delve.

Signed-off-by: Cyril Tovena cyril.tovena@gmail.com

Fixes grafana#3485

Should also unblock grafana#3481

When unsafely converting string to bytes the cap of the bytes is lost but not when doing bytes to string.
It seems that this is only a problem when using go 1.16 or when using delve.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
var buf []byte
p := unsafe.Pointer(&buf)
*(*string)(p) = s
(*reflect.SliceHeader)(p).Cap = len(s)
Copy link
Contributor

Choose a reason for hiding this comment

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

OMG yes! This would always give me issues when using delve

@cyriltovena cyriltovena merged commit d6ecfd2 into grafana:master Mar 16, 2021
perrinjerome pushed a commit to perrinjerome/loki that referenced this pull request Jun 10, 2021
…afana#3487)

Fixes grafana#3485

Should also unblock grafana#3481

When unsafely converting string to bytes the cap of the bytes is lost but not when doing bytes to string.
It seems that this is only a problem when using go 1.16 or when using delve.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test_HeadIteratorReverse, Test_Iterator failing in 2.2.0 release
2 participants