-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix: fix slice init length #24104
fix: fix slice init length #24104
Conversation
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
@rusttech the code as it exists here is correct. We're initializing a slice of len and cap equal to the correct size. There's no reason to specify the length as 0 here because we statically know the correct size for both, and this is more tedious to write and read. I'm going to be honest with you @rusttech that I see you've opened this identical PR on a half dozen other repositories. This kind of activity smells like unwelcome automated PRs. Please don't continue to do this. |
Well unfortunately on a second glance at this, I see that the code change is correct, but that you haven't then followed-up with how the original code is compensating for the empty slice items. |
We initialize this slice with a zeroed array and then append to it, which means we then have to clean out the empty strings later. Initialize to the correct capacity up front so there are no empty values. Ref: #24104
We initialize this slice with a zeroed array and then append to it, which means we then have to clean out the empty strings later. Initialize to the correct capacity up front so there are no empty values. Ref: #24104
I submitted them manually one by one, not through an automated program. |
It's okay, as long as the problem is fixed. |
The intention here should be to initialize a slice with a capacity of len(node.Attributes) rather than initializing the length of this slice.