Skip to content

Linked list uses positional disambiguation instead of value-level disambiguation for null pointers #79

@thedavidmeister

Description

@thedavidmeister

Summary

The corporate action linked list uses 0 as both "null pointer" (no next/prev/head/tail) and as a valid array index (the "sentinel" at position 0). The ambiguity is resolved by physical position (reserving index 0 via an array length bump) rather than by making values unambiguous.

Problem

prev = 0 could mean "no previous node" or "the node at array index 0." The code works because:

  1. Index 0 is reserved (sentinel push)
  2. Traversal checks current != 0 before indexing
  3. Convention: no code follows a 0 pointer

This is fragile — any new code that indexes s.nodes[pointer] without checking pointer != 0 silently reads a zero-initialized slot that looks like a cancelled node.

Alternative

Use type(uint256).max as the null sentinel value instead of 0. Then:

  • prev = type(uint256).max → unambiguously "no previous node"
  • prev = 0 → unambiguously "the node at index 0"
  • Index 0 available for real data (no sentinel push needed)
  • Value-level disambiguation, not positional

Trade-offs

Priority

Low — current design works correctly. This is a design purity concern, not a bug. Worth considering for a v2 of the data structure.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions