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

fix: fix slice init length #24104

Closed
wants to merge 1 commit into from
Closed

fix: fix slice init length #24104

wants to merge 1 commit into from

Conversation

rusttech
Copy link

@rusttech rusttech commented Oct 2, 2024

The intention here should be to initialize a slice with a capacity of len(node.Attributes) rather than initializing the length of this slice.

Copy link

hashicorp-cla-app bot commented Oct 2, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

CLA assistant check

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.

@tgross
Copy link
Member

tgross commented Oct 2, 2024

@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.

@tgross
Copy link
Member

tgross commented Oct 2, 2024

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.

tgross added a commit that referenced this pull request Oct 2, 2024
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
tgross added a commit that referenced this pull request Oct 2, 2024
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
@rusttech
Copy link
Author

rusttech commented Oct 3, 2024

@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.

I submitted them manually one by one, not through an automated program.

@rusttech
Copy link
Author

rusttech commented Oct 3, 2024

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.

It's okay, as long as the problem is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants