Repository navigation
fix(builtins,executor): #704 printf numeric validation (R6.1), command -v no-operand + substitution status (R6.2 residue) - #869
Merged
Merged
Conversation
…d -v no-operand + substitution status (R6.2 residue)
R6.1 printf numeric validation. GNU getintmax/getuintmax/getdouble
(printf.def:1427/1450/1472) hand operands to strtoimax/strtoumax/strtod,
which skip only LEADING C-locale white space, convert the longest valid
subject, and RETURN that value even when chk_converror
(printf.def:1388-1395) rejects the trailing bytes and sets
conversion_error (exit 1, processing continues). rubash's parse_* trimmed
BOTH sides (so '5 ' passed silently for %d/%i/%u/%x/%X/%o) and Rust's
f64 parse dropped suffixed operands to 0.0 for %f. number.rs now scans
the strtod/strtoimax subject sequence:
- trailing-white-space operands report sh_invalidnum
(builtins/common.c:214-225) while keeping the converted value:
'printf %d "5 "' -> 5 + "5 : invalid number", rc 1
- chk_converror order: the *ep != 0 branch wins over ERANGE, so
99999999999999999999x reports "invalid number", not erange
- sh_invalidnum classification mirrored on the full original operand:
0Xzz -> "invalid number" (lowercase x only is hex), 01z and
suffixed 055-/08-forms -> octal, 0x-forms -> hex
- base-0 0b/0B binary literals convert like glibc 2.38+ strto*
(oracle-verified: 0b101 -> 5; 0b2 -> 0 + "invalid number")
- asciicode (printf.def:1519-1544) runs BEFORE any numeric parse and
does no chk_converror: a lone quote is the NUL at arg[1] (0, silent),
"'a " stays 97
- getdouble's subject scan adds hexadecimal floats (0x1, 0x1p3,
0x.8p1) and inf/infinity/nan(n-char-sequence); non-finite results
render per conversion case (inf/nan vs INF/NAN for %F/%E/%G/%A),
keep the sign bit as "-nan", and still take %+ ("+inf") — the
pre-fix engine could never deliver a nan operand to the renderer
R6.2 residue. builtins/command.def:95-96: 'if (list == 0) return
EXECUTION_SUCCESS' — the no-operand early return precedes the describe
loop. The executor's command -v/-V path (type_builtin.rs) fell through
to the any_found accumulator and returned 1 for bare 'command -v'; now
it takes the early success. The substitution entry point
(command_substitution_values.rs) switches from an all-found accumulator
to GNU's any_found rule (command.def:111-121) and routes the -V
per-operand "not found" diagnostic to stderr (oracle:
$(command -V echo nosuch) captures the description on stdout, prints
"command: nosuch: not found" on stderr, rc 0).
Verification: WSL GNU bash 5.3.0 (/usr/local/bin/bash) oracle,
script-file byte compare over a 110-case matrix (ticket reproforms plus
leading/trailing-white-space, suffix, radix-prefix, overflow, char-
constant, float-subject and command -v operand shapes): 107/110 byte
identical. The 3 remaining are pre-existing engine divergences outside
this facet, reproducible on master: '%f' 1e999 (oracle strtofltmax
long-double expansion vs f64 inf) and '%a' mantissa style (0xap-1 vs
0x1.4p+2; 'printf %a 5' diverges on master unchanged).
Tests: src/builtins/printf_tests.rs mod numeric_validation_704 (14
cases); tests/regression.rs issue_704 gains 704.2b no-operand success
and 704.2c substitution any-found + -V stderr. printf family 52 green,
command -v family green. Full suite --test-threads=1 --no-fail-fast:
failure set identical to pristine master (34 machine-state failures,
0 new). cargo fmt clean; clippy clean on all touched code.
Member
Author
独立评审结论:APPROVE-WITH-NITS评审对象 9ced20a(= origin/fix/704,含 merge bd24cf8,merge-base==origin/master,merge 零带入),base bd24cf8。评审在独立 worktree 1. GNU 契约核对(vendored bash @b4608166,逐坐标实读)
2. WSL GNU bash 5.3.0(glibc 2.39)双侧逐字节 oracle(118 形,stdout+rc+stderr 正文)
3. 重写面回归与性能
4. command -v/-V/-p/type
5. 测试与卫生
6. GPL 红线number.rs/float.rs/value.rs 为原创 Rust 实现;注释仅 file:line 坐标与行为引用,无 C 结构/表达式镜像 ✓ NITS(不阻塞)
不合并,留给 maintainer。 |
This was referenced Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two facets of #704. R6.2's multi-operand rc rule landed earlier (5da6421); this closes its two residue holes and the whole R6.1 printf numeric-validation facet.
R6.1 — printf numeric validation
GNU
getintmax/getuintmax/getdouble(printf.def:1427/1450/1472) hand operands tostrtoimax/strtoumax/strtod: only leading C-locale white space is skipped, the longest valid subject sequence is converted, and that value is returned even whenchk_converror(printf.def:1388-1395) rejects the trailing bytes and setsconversion_error(exit 1, processing continues — POSIX contract quoted in the source). rubash previouslytrim()-ed both sides ('5 'silently passed for %d) and Rust'sf64::from_strdropped suffixed operands to 0.0 for %f.src/builtins/printf/number.rsnow scans the actual subject sequence:printf: 5 : invalid number+ rc 1 (all of %d %i %u %x %X %o %f %e %g %a)chk_converrorbranch order:*ep != 0wins overERANGE(99999999999999999999xreports "invalid number", not erange)sh_invalidnumclassification (builtins/common.c:214-225) mirrored on the full original operand:0Xzz→ "invalid number" (only lowercasexis hex),01zand suffixed055␠/08-forms → octal,0x-forms → hex,0␠→ number0b/0Bbinary literals (0b101→ 5;0b2→ 0 + "invalid number") — oracle-verifiedasciicode(printf.def:1519-1544) runs before any numeric parse with nochk_converror: lone quote'→ NUL (0, silent),'a␠→ 970x1,0x1p3,0x.8p1) andinf/infinity/nan(n-char-seq); non-finite results render per conversion case (inf/nanvsINF/NANfor %F/%E/%G/%A), keep the sign bit (-nan), and still take%+(+inf) — the old engine could never deliver a nan operand to the renderer at allR6.2 residue — command -v
builtins/command.def:95-96:if (list == 0) return EXECUTION_SUCCESS;— the no-operand early return precedes the describe loop. The executor'scommand -v/-Vpath (type_builtin.rs) fell through to the any_found accumulator and returned 1 for barecommand -v. The substitution entry point (command_substitution_values.rs) still used an all-found accumulator —$(command -v echo nosuch)wrongly exited 1 — and dropped the-V"not found" diagnostic; now any-found + stderr routing (oracle: stdout captures the description, stderr getscommand: nosuch: not found, rc 0).typeis the all-found builtin and keeps its rule (control-tested).Verification
/usr/local/bin/bash), script-file byte compare, 110-case matrix (all five R6.1 ticket reproforms + white-space/suffix/radix-prefix/overflow/char-constant/float-subject/command-operand boundaries): 107/110 byte-identical. The 3 remaining are pre-existing engine divergences outside this facet, reproducible on master unchanged:%f1e999 (oraclestrtofltmaxlong-double expansion vs f64inf) and%amantissa style (0xap-1vs0x1.4p+2; plainprintf '%a\n' 5diverges on master).src/builtins/printf_tests.rsmod numeric_validation_704(14 cases);tests/regression.rsissue_704gains 704.2b (no-operand success, direct + substituted) and 704.2c (substitution any-found + -V stderr). printf family 52/52,issue_7043/3, fulltests/regression.rs78/78 — no printf or command -v family regression.cargo test --no-fail-fast -- --test-threads=1on this branch vs pristine master (45f537e) in a separate worktree: failure sets identical (34 machine-state failures both sides, 0 new, 0 flapped).cargo fmt --checkclean; clippy: no warnings in any touched code region (tree-wide pre-existing warnings unchanged, count 557 → 556 after merging master's 注释/文档漂移清扫:#838 删除的断言引用、subst.c 坐标漂移、clippy cast(#841/#838/#426 CR nits 打包) #849 hygiene sweep).Closes #704 R6.1; R6.2 fully closed (multi-operand 5da6421 + residue here). R6.3/R6.4/R6.5 remain open in the issue thread.