Skip to content

fix(stl): allow an empty iterator range when constructing span #4523

Closed

Description

@zackees

Context

The dynamic span iterator-pair constructor unconditionally evaluates &(*begin). For an empty range, begin == end, so this dereferences the end iterator; an empty fl::vector can make that a null dereference.

Repro: fl::vector<int> v; fl::span<int> s(v.begin(), v.end()); should create a zero-length span but invokes undefined behavior.

Proposal

Handle the empty range before dereferencing an iterator, preserving a valid zero-length span.

Acceptance criteria

  • Add a focused RED→GREEN test for equal non-null pointers and empty-vector iterators, including the debug sanitizer path.
  • Both forms yield size() == 0 and begin() == end() without dereferencing the end iterator.

Decisions

  • Scope is the iterator-pair constructor; other span constructors can be audited but are not presumed broken.
  • Priority: medium; empty ranges are routine and undefined behavior is unacceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions