Skip to content

Apply TigerStyle: 70-line functions, assertions, bounded loops - #49

Open
endel wants to merge 4 commits into
mainfrom
tiger-style
Open

endel wants to merge 4 commits into
mainfrom
tiger-style

Conversation

@endel

@endel endel commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Applies the part of TigerStyle we chose to adopt, across src/, apps/, tools/ and build.zig. CLAUDE.md records the rules and where we differ (camelCase, per-connection allocation, libxev, shell tooling, no 100-column reflow).

The refactor (first commit, no behaviour change)

  • Functions end at 70 lines. About 100 were over (processFrame 779, packSinglePacket 475, build 405). The parent keeps the control flow; private helpers carry its name as a prefix.
  • Assertions: 34 before, about 1,160 now, including comptime checks on constants and type sizes. None is on peer, file, argv or public-API input.
  • Loops carry a bound or a progress assert, or say why they have none.
  • Ignored errors say why. Handling is unchanged.
  • Sized integers for private counters and fields. No pub type changed.

No public signature, wire output, CLI contract or zig build step changes (zig build -l and --help are byte-identical).

Fixes (their own commits, each with a test that failed first)

  • tls13: four handshake messages crashed a safe build: a ClientHello ending inside its session id, and u16 overflows on the ALPN, pre_shared_key and CertificateRequest list lengths.
  • quic: HANDSHAKE_DONE was resent on every PTO to a client acknowledging with plain ACK frames.

Suspected bugs, not fixed

docs/tigerstyle_suspected_bugs.md lists what looked wrong while reading, marked reproduced or read-only.

Verified

  • zig build test in Debug and ReleaseSafe, zig build fuzz, zig build, on macOS.
  • Loopback before/after: interop client/server pairs, 21/21 WPT cases, 18/18 MoQ cases on both transports.
  • bench-quic: +0.4% instructions retired. Wall-clock was too noisy on the machine used to resolve under 3%.

Not verified

  • Linux and Windows beyond cross-compiling; the Linux GSO send path's new asserts have not run locally.
  • The Docker interop and MoQ runners, browsers, routez and netcode-io against this tree.
  • interop-wt-server / interop-wt-client at runtime.

🤖 Generated with Claude Code

Every non-test function now ends within 70 lines: the parent keeps the
control flow, private helpers named after it take the rest. Asserts cover
what our own code guarantees and nothing a peer, a file or a caller of the
public API can make false. Loops carry a bound or say why they have none,
and ignored errors say why.

No public signature, wire output or build step changes. bench-quic retires
0.4% more instructions. CLAUDE.md records the rules and where we differ
(camelCase, per-connection allocation, libxev).

Assisted-by: Claude Fable 5.2
One message crashed a safe build, and read out of bounds or wrapped in
ReleaseFast: a ClientHello ending inside its session id, and list lengths
near 0xFFFF in a ClientHello's ALPN and pre_shared_key or a server's
CertificateRequest, each summed in u16.

Assisted-by: Claude Fable 5.2
Only the ACK_ECN path cleared the pending flag, so a client acknowledging
without ECN counts was sent HANDSHAKE_DONE again on every PTO.

Assisted-by: Claude Fable 5.2
The pass changed no behaviour, so what looked wrong while reading is
listed here, marked reproduced or read-only.

Assisted-by: Claude Fable 5.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant