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

Bug: Incorrect Use of Append Function in StoreKeys Method #469

Open
yuxuan-xie opened this issue Mar 21, 2024 · 0 comments · May be fixed by #470
Open

Bug: Incorrect Use of Append Function in StoreKeys Method #469

yuxuan-xie opened this issue Mar 21, 2024 · 0 comments · May be fixed by #470

Comments

@yuxuan-xie
Copy link

Hello Team,
During a recent code review, I found a persistent bug in the StoreKeys method of our Store struct.

func (rs *Store) StoreKeys() []types.StoreKey {
	res := make([]types.StoreKey, len(rs.keysByName))
	for _, sk := range rs.keysByName {
		res = append(res, sk)
	}
	return res
}

The code can be found at

res := make([]types.StoreKey, len(rs.keysByName))

This is a common bug with respect to append. The original code piece are actually appending new keys at the end of some zero-values, thus doubling the slice size.

@yuxuan-xie yuxuan-xie linked a pull request Mar 21, 2024 that will close this issue
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 a pull request may close this issue.

1 participant