Skip to content

Wave B residuals: #1521 grep/diff clamp band, #1523 uniq overflow clamp, #1524 split ERANGE suffix, #1522 text-reader wide paths - #1525

Merged
caomengxuan666 merged 5 commits into
mainfrom
wave-b-winx-residuals
Nov 4, 2026
Merged

caomengxuan666 merged 5 commits into
mainfrom
wave-b-winx-residuals

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Wave B residuals R1–R4: #1521 / #1522 / #1523 / #1524

Refs #1521, Refs #1522, Refs #1523, Refs #1524. All four are residuals of PR #1520 (BAD-5 + #1519), landed as one PR with one commit per issue. GNU source first for every item; oracle coreutils 9.4 / grep 3.11 / diffutils 3.10 / findutils 4.9.0 sources under the audit tree, plus byte probes against the GNU 9.4 binaries.

#1521 — grep/diff xstrtoimax-clamp family

GNU: grep -m xstrtoimax with LONGINT_OVERFLOW accepted (grep.c:2681-2692); context lengths via context_length_arg (grep.c:826-841, same acceptance); diff context via strtoimax + clamp (diff.c:358-367). The (INT64_MAX, UINT64_MAX] band was dying in the shared parser because all of these were declared INT_TYPE.

  • grep: -m/-A/-B/-C/-NUM → UINT_TYPE; the context occurrence loop now reads the unsigned store through the saturating bridge (a bare get_if<int64_t> would silently drop band occurrences — the [G18 后续] 共享选项解析器缺无符号路径:(INT64_MAX, UINT64_MAX] 对 uintmax 类选项仍解析失败 #1519 trap).
  • diff: -C/-U/-NUM → UINT_TYPE, -c/-u → OPTIONAL_UINT_TYPE; all five occurrence reads go through a saturating helper. The bare -c/-u sentinel (-1) still arrives signed.
  • Negatives are byte-identical (signed-first storage): pins for grep -1: invalid context length argument (rc 2) and diff invalid context length '-5'.

#1523 — uniq past-UINT64 clamp (+ locate disposition)

GNU: uniq size_opt (uniq.c:233-250) accepts LONGINT_OK and LONGINT_OVERFLOW, then MIN(size, SIZE_MAX) (uniq.c:237-247).

  • New shared-parser declaration OptionType::UIntClamp: signed-first like UInt, but a positive digit run that overflows even uint64 stores UINT64_MAX; every reader bridge then saturates it (GNU's clamp). Grouped with UInt in all seven parse sites and the dispatcher role pre-pass.
  • uniq -f/-s/-w/-NUM → UINT_CLAMP_TYPE.
  • Locate disposition: deliberately NOT widened. locate.c:1677-1681 routes any err != LONGINT_OK — LONGINT_OVERFLOW included — to xstrtol_fatal. So locate -l past UINT64_MAX stays a parse error; the asymmetry is GNU's own, and it is pinned (locate_limit_above_uint64_still_errors_issue1523).

#1524 — split ERANGE suffix: family adjudication = APPEND, GNU-shaped

strtoint_die (split.c:1301-1305) is error(EXIT_FAILURE, errno == EINVAL ? 0 : errno, "%s: %s", msgid, quote(arg)). Adjudication across all quoted_number_error call sites:

Death GNU errno Suffix
invalid-suffix death, digit run overflowed (suffix-char-with-overflow) ERANGE append
range death on an overflowed scan (negative overflow → INTMAX_MIN) ERANGE append
pure invalid (no digits / junk on a clean scan) EINVAL none
clean range death (0, -5, 2fb) 0/EINVAL none
invalid chunk number (not strtoint_die; split.c parse_chunk plain error(..., 0, ...)) 0 none

Implementation: quoted_number_error gains an erange flag; every strtoint_die-shaped site (-b/-C/-l, both parse_chunk deaths, and the ---io-blksize validation that mirrors -b) passes number_scan_erange(arg) — the quoted text's own scan_intmax overflow bit. Byte-probed against GNU coreutils 9.4 split for the K/N-head, -l suffix-junk, and negative-overflow shapes; the pre-existing exact-match battery for clean deaths is untouched and still exact.

#1522 — text-mode narrow-ctor readers: wide path, KEEP text mode

The three remaining #342-class readers. Per-applet CRLF adjudication: all three are text readers whose current behavior includes the CRT CRLF translation, so the swap changes only the path boundary — make_api_path_operand + std::filesystem::path(operand.extended), without ios::binary:

  • dircolors: parse_db_line treats '\r' as whitespace → translation semantically invisible; wide path is the whole fix.
  • hexdump -f: format parser skips via isspace, blank/comment scan already lists '\r' → translation-neutral; kept text mode to leave byte behavior untouched.
  • hostname -F: first line is printed verbatim, so the translation is observable — a binary open would leak '\r' into the printed name; text mode preserves it exactly.

Each pin uses a U+00FF filename and CRLF content, proving both the open and the unchanged CRLF semantics.

本 PR 删除了什么

  • grep/diff/uniq 数值选项的旧 INT_TYPE/UINT_TYPE 声明(被 UINT_TYPE / UINT_CLAMP_TYPE 声明取代,不是新增并行路径)。
  • grep 上下文 occurrence 循环与 diff 五处对 occurrence 值的裸 get_if<int64_t> 读(被饱和桥读取代——带值此前会被静默丢弃)。
  • dircolors/hexdump/hostname 三处窄构造 std::ifstream(normalize_api_operand(...)) 打开(被宽路径打开取代)。
  • split 的「errno 文本永不追加」这一旧消息形状(quoted_number_error 的无条件裸形)——按全族裁定删除,改为仅 ERANGE 死亡带后缀。
  • 净行对账:全分支 +517/−60(19 文件);其中产品码 +169/−60、测试 +348/−0(新钉)。删除面如上四条,无平行实现新增——UIntClamp 是声明层的一个新符号性,不是第二条解析路径(与 UInt 共用同一 signed-first 扫描)。

Pins (all named by issue)

grep ×3, diff ×3, uniq ×3, locate ×1 (#1523 asymmetry), split ×2, dircolors ×1, hexdump ×1, hostname ×1 — 15 new tests. Per-stem Passed lines from the build-windows (x64, x64, x64, default) ctest log are listed in the lane report (only that job runs ctest).

i18n

No new user-visible strings. The #1524 suffix is an assembled fragment of an existing message; verified locally with scripts/check_i18n_drift.py against a fresh unixwin/winuxcmd-i18n clone: drift OK, no new recorded items (the split error strings are not legacy-extracted), so no baseline update and no catalog sync arise from this PR.

Format

Files hand-formatted to surrounding style; the VM's clang-format (pip 23.1.3) is not the repo-pinned formatter, so scripts/format.py was not run — same recorded skip as the #1520 lane.

…Refs #1523)

GNU uniq's size_opt (uniq.c:233-250) accepts LONGINT_OK and
LONGINT_OVERFLOW from xstrtoumax and clamps via MIN(size, SIZE_MAX)
(uniq.c:237-247), so uniq counts past UINT64_MAX are accepted.
The shared parser's UInt path (#1519) still died there.

- cmd_meta: OptionType::UIntClamp (+ help suffix grouping, macro
  UINT_CLAMP_TYPE).
- opt: parse_int_value now takes the OptionType; UIntClamp stores
  UINT64_MAX when the uint64 parse itself overflows on a pure digit
  run. Signed-first storage is unchanged, so negative diagnostics
  keep their shape. All seven parse sites and the dispatcher role
  pre-pass group UIntClamp with UInt.
- uniq: -f/-s/-w/-NUM declare UINT_CLAMP_TYPE; the existing get<int>
  reads saturate the clamped store, reproducing SIZE_MAX clamping.
- locate is deliberately NOT migrated: locate.c:1677-1681 sends any
  err != LONGINT_OK (overflow included) to xstrtol_fatal, so -l past
  UINT64_MAX stays a parse error; pinned as the asymmetry face.

Pins: uniq_skip_fields_above_uint64_clamps_issue1523,
uniq_skip_chars_above_uint64_clamps_issue1523,
uniq_obsolete_num_above_uint64_clamps_issue1523,
locate_limit_above_uint64_still_errors_issue1523.

Format: files hand-formatted to surrounding style; the VM's
clang-format (pip 23.1.3) is not the repo-pinned formatter, so
scripts/format.py was not run (same skip as the #1520 lane).
GNU grep parses -m via xstrtoimax accepting LONGINT_OVERFLOW
(grep.c:2681-2692) and context lengths via context_length_arg
(grep.c:826-841, same acceptance); diff parses -U/-C/-NUM and the
-c/-u attached values with strtoimax and clamps (diff.c:358-367).
Both families therefore accept the (INT64_MAX, UINT64_MAX] band,
clamping to INTMAX_MAX; WinuxCmd still declared them INT_TYPE and
died in the shared parser.

- grep: -m/-A/-B/-C/-NUM declare UINT_TYPE. The context occurrence
  loop now reads the unsigned store through the saturating bridge
  (a bare get_if<int64_t> would silently drop band occurrences --
  the #1519 trap); -m already read via get<int64_t>.
- diff: -C/-U/-NUM declare UINT_TYPE, -c/-u OPTIONAL_UINT_TYPE, and
  all five occurrence reads go through a saturating helper lambda.
  The bare -c/-u sentinel (-1) still arrives in the signed store.

Negatives keep their consumer diagnostics byte-identically
(signed-first storage): grep "-1: invalid context length argument"
(rc 2) and diff "invalid context length '-5'" both pinned.

Pins: grep_max_count_unsigned_band_issue1521,
grep_context_unsigned_band_issue1521,
grep_negative_max_count_shape_kept_issue1521,
diff_unified_context_unsigned_band_issue1521,
diff_context_forms_unsigned_band_issue1521,
diff_negative_context_still_errors_issue1521.

Format: hand-formatted; repo-pinned formatter not run (VM
clang-format 23.1.3 is not the pinned one, as in the #1520 lane).
Family adjudication against GNU source: strtoint_die
(split.c:1301-1305) is error(EXIT_FAILURE, errno == EINVAL ? 0 :
errno, "%s: %s", msgid, quote(arg)) -- so the ": Numerical result
out of range" suffix appears exactly when the failing xstrtoimax
scan left errno == ERANGE: an invalid-suffix death whose digit run
also overflowed, or a range death on an overflowed scan (negative
overflow clamped to INTMAX_MIN). Pure-invalid deaths (EINVAL) and
clean range deaths (0, -5, 2fb) get no suffix, and "invalid chunk
number" never routes through strtoint_die at all.

- quoted_number_error gains an erange flag appending the suffix.
- Every strtoint_die-shaped call site (-b/-C/-l, both parse_chunk
  deaths via fail_chunks, and the ---io-blksize validation that
  mirrors -b) passes number_scan_erange(arg): the quoted text's own
  scan_intmax overflow bit. Probe-verified against GNU coreutils
  9.4 split for the K/N head, -l suffix-junk, and negative-overflow
  shapes (byte-identical); the pre-existing exact-match battery for
  clean deaths is untouched and still exact.

Pins: split_overflow_deaths_carry_erange_suffix_issue1524,
split_non_overflow_deaths_have_no_erange_suffix_issue1524.

i18n note: verified locally with scripts/check_i18n_drift.py
against a fresh winuxcmd-i18n clone -- drift OK, no new recorded
items (the assembled split error strings are not legacy-extracted).

Format: hand-formatted; repo-pinned formatter not run (VM
clang-format 23.1.3 is not the pinned one, as in the #1520 lane).
…1522)

The three remaining #342-class readers fed a UTF-8 std::string from
normalize_api_operand into std::ifstream's narrow ctor (ANSI code
page decoding). Per-applet CRLF adjudication: all three are TEXT
readers whose current behavior includes the CRT CRLF translation,
so the fix swaps only the path boundary -- make_api_path_operand +
std::filesystem::path(operand.extended), WITHOUT ios::binary:

- dircolors: parse_db_line treats '\r' as whitespace, so the
  translation is semantically invisible; the wide path is the fix.
- hexdump -f: the format parser skips via isspace and the blank/
  comment scan already lists '\r'; translation-neutral either way,
  kept in text mode to leave byte behavior untouched.
- hostname -F: the first line is printed verbatim, so the
  translation IS observable -- a binary open would leak '\r' into
  the printed name; text mode preserves it exactly.

Each applet gets a U+00FF filename pin whose file content is CRLF,
proving the name opens and the CRLF semantics are unchanged.

Pins: dircolors_opens_non_ascii_filename_issue1522,
hexdump_f_opens_non_ascii_filename_issue1522,
hostname_file_opens_non_ascii_filename_issue1522.

Format: hand-formatted; repo-pinned formatter not run (VM
clang-format 23.1.3 is not the pinned one, as in the #1520 lane).
@caomengxuan666 caomengxuan666 reopened this Nov 4, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 4, 2026 10:49
@caomengxuan666
caomengxuan666 marked this pull request as draft November 4, 2026 10:50
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