Skip to content

net/netip: Prefix.Bits and Prefix.IsValid are inconsistent #54525

@dsnet

Description

@dsnet

The documentation for Prefix.Bits says:

Bits returns p's prefix length.
It reports -1 if invalid.

The documentation for Prefix.IsValid says:

IsValid reports whether p.Bits() has a valid range for p.IP().
If p.Addr() is the zero Addr, IsValid returns false.
Note that if p is the zero Prefix, then p.IsValid() == false.

Thus, we expect the zero Prefix to be invalid, but also report -1 bits.
Instead, we get 0 bits.

https://go.dev/play/p/rsc2Uy_jMX1

Either the behavior or the documentation should be adjusted.

\cc @bradfitz @josharian

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions