From f9f0720804f3a2ef4c08d5ded98a8c36dd302e32 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Mon, 18 May 2026 20:32:38 +0900 Subject: [PATCH] selfhost: align wwstage dirfilekeep .combined.ww predicate with cstage (#26) Wwstage dirfilekeep checked only the first 5 chars of ".combined.ww" (.comb), leaving a latent over-filter for hypothetical filenames of shape .combXXXX.ww. Cstage enumerate_dir_ww in cmd/ww/main.c uses strcmp on the full 12-char tail; mirror that here per rule-10 symmetric-stages. Extends the nested-if cascade to also gate on 'i','n','e','d' at offsets nlen-7..nlen-4; the trailing .ww is already enforced by the function's leading early-out, so re-checking those three positions would be dead and is called out in the comment. No corpus trigger today; bootstrap ww2==ww3==ww4 byte-id holds. Predecessor: #22 dir-enum (9e0816e) introduced the predicate. 115/115 ok. ww2 == ww3 == ww4 byte-id. --- selfhost/cmd/ww/main.combined.ww | 14 ++++++++++++-- selfhost/cmd/ww/main.ww | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/selfhost/cmd/ww/main.combined.ww b/selfhost/cmd/ww/main.combined.ww index 9dc35370..72c0c519 100644 --- a/selfhost/cmd/ww/main.combined.ww +++ b/selfhost/cmd/ww/main.combined.ww @@ -1205,13 +1205,23 @@ fn dirfilekeep(name: *u8, nlen: u64) bool = { }; }; if (nlen >= 12u64) { - // ".combined.ww" + // ".combined.ww" — full 12-char match mirrors cstage + // cmd/ww/main.c enumerate_dir_ww strcmp (rule 10); the + // trailing .ww is pre-guaranteed by the early-out above. if (name[nlen - 12u64] == 46u8) { // '.' if (name[nlen - 11u64] == 99u8) { // 'c' if (name[nlen - 10u64] == 111u8) { // 'o' if (name[nlen - 9u64] == 109u8) { // 'm' if (name[nlen - 8u64] == 98u8) { // 'b' - return false; + if (name[nlen - 7u64] == 105u8) { // 'i' + if (name[nlen - 6u64] == 110u8) { // 'n' + if (name[nlen - 5u64] == 101u8) { // 'e' + if (name[nlen - 4u64] == 100u8) { // 'd' + return false; + }; + }; + }; + }; }; }; }; diff --git a/selfhost/cmd/ww/main.ww b/selfhost/cmd/ww/main.ww index 4e60d32f..c8b763b7 100644 --- a/selfhost/cmd/ww/main.ww +++ b/selfhost/cmd/ww/main.ww @@ -345,13 +345,23 @@ fn dirfilekeep(name: *u8, nlen: u64) bool = { }; }; if (nlen >= 12u64) { - // ".combined.ww" + // ".combined.ww" — full 12-char match mirrors cstage + // cmd/ww/main.c enumerate_dir_ww strcmp (rule 10); the + // trailing .ww is pre-guaranteed by the early-out above. if (name[nlen - 12u64] == 46u8) { // '.' if (name[nlen - 11u64] == 99u8) { // 'c' if (name[nlen - 10u64] == 111u8) { // 'o' if (name[nlen - 9u64] == 109u8) { // 'm' if (name[nlen - 8u64] == 98u8) { // 'b' - return false; + if (name[nlen - 7u64] == 105u8) { // 'i' + if (name[nlen - 6u64] == 110u8) { // 'n' + if (name[nlen - 5u64] == 101u8) { // 'e' + if (name[nlen - 4u64] == 100u8) { // 'd' + return false; + }; + }; + }; + }; }; }; };