Skip to content

Inconsistency in the single-linked list implementation #4786

@Kouteki

Description

@Kouteki

Severity: Informational

Description

In mempackage_type:gnovm/pkg/gnolang/values.go:673–690, the Append function manages the insertion of elements into a singly linked list used to iterate over values stored in a hashmap. The implementation follows a conventional “head and tail” pattern.

However, when appending to an initially empty list, where the Head is nil, the inserted item is assigned to both the Head and Tail. While the list’s size is correctly updated to reflect a single element, this dual assignment introduces a subtle inconsistency: the Head is exclusively used for marshalling operations, while the Tail is only used during unmarshalling.

Although this divergence currently has no functional impact, it reflects an imprecise handling of the edge case and may introduce confusion or bugs in future modifications.

Recommendation

We recommend explicitly handling the empty list case to maintain consistency in list structure. Furthermore, consider refactoring the append logic to more clearly follow the conventional head–tail insertion pattern.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions