-
Notifications
You must be signed in to change notification settings - Fork 18k
spec: append
doesn't specify zero values when growing underlying array
#56684
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
Comments
I noticed also that the spec doesn't actually say |
Yes, that part is on purpose - we don't want to be too specific and constrain an implementation. But we should probably say that the array may possibly be larger than absolutely necessary. |
When I was thinking about #56086, I came across this issue, and I think the Go spec does guarantee it. Appending to and copying slices says:
The zero value says:
I interpreted the list in "the zero value" section as non-exhaustive and that allocations from |
@dsnet I agree. The thought occurred to me as well, afterwards. Perhaps all that's needed to make this more explicit is making "allocates" link to the appropriate section. |
Change https://go.dev/cl/452619 mentions this issue: |
When
append
is called on a slice and the underlying array is not large enough, a new underlying array is allocated, possibly increasing the slice's capacity significantly (typically doubling it). The spec doesn't specify the value of any slice elements past the slice length and up to the capacity.The text was updated successfully, but these errors were encountered: