Skip to content

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

@yuxuan-xie

Description

@yuxuan-xie

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions