szn

Bug 527 — FreeBSD VMIN/VTIME indices are wrong

527. setRaw uses the Linux-style indices for FreeBSD

Severity: LOW Status: ✅ FIXED Files: src/client/raw.zig:12, src/client/raw.zig:18, src/client/raw.zig:66-69

Verification status: the index values were checked against documented FreeBSD sys/_termios.h constants, but the code was not compiled or run on FreeBSD.

Problem

// src/client/raw.zig:12, 18
.freebsd => 4,   // VMIN
.freebsd => 5,   // VTIME

FreeBSD defines VMIN 16 and VTIME 17 in sys/_termios.h — the same values as macOS, OpenBSD and NetBSD. Indices 4 and 5 are VWERASE and VKILL.

On FreeBSD, setRaw therefore overwrites the wrong control characters and leaves VMIN/VTIME at their cooked values, so raw-mode reads may block or return 0 — the client would appear to hang or drop input.

The unit test at :66-69 asserts the current (wrong) values, so it locks the defect in rather than catching it.

Proposed Fix

.freebsd => 16,   // VMIN
.freebsd => 17,   // VTIME

and update the test. If FreeBSD is not an intended target, remove the arm and the claim rather than shipping a wrong constant.

Fix

// src/client/raw.zig
const VMIN: u6 = switch (@import("builtin").os.tag) {
    .linux => 6,
    .macos, .ios => 16,
    .freebsd => 16,   // was 4 (VWERASE)
    else => 6,
};
const VTIME: u6 = switch (@import("builtin").os.tag) {
    .linux => 5,
    .macos, .ios => 17,
    .freebsd => 17,   // was 5 (VKILL)
    else => 5,
};

The existing test VMIN and VTIME match the target platform (src/client/raw.zig:56) asserted the wrong FreeBSD values, so it locked the defect in; it now asserts 16/17. The values are only reachable on a FreeBSD build, so this fix is verified by inspection against the BSD termios layout plus the corrected assertion — not by execution on FreeBSD.

Verified with the full suite on Zig 0.16.0 and 0.17.0 (the FreeBSD arm is inactive on both): 1050/1050 passing.

Bug #100 (VMIN/VTIME were macOS values on Linux — CRITICAL) and bug #497 (the test helper setRaw hardcoded macOS indices, wrong on Linux) are the same defect class. FreeBSD was not covered by either fix.