Repository navigation
fix(fc): align sole-current-entry index clamp and fc -s rejection with GNU fc.def (Fixes #4247) - #4257
Merged
Conversation
… with GNU fc.def (Fixes #4247)
Member
Author
|
队长只读复核:达合入门,可进运行时复验(不合并不代表已验证,运行时仍须真 oracle 探针 + fail-first)。 GNU 锚点逐项核对(vendored GNU bash 5.3.20 fc.def,third_party/bash 子模块内容)
改动面仅 新钉覆盖 #4247 全部面
CI 名字集差分(run 46097268210)
运行时复验待办(队长另派 devin-mac)
|
Member
Author
|
订正上一条评论的一行(shell 反引号吞字):fc.def:91 行应为 |
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
Align
fcsole-current-entry index resolution with GNU Bash 5.3.20 (Fixes #4247):GNU C Specification
third_party/bash/builtins/fc.def:91:HIST_INVALIDisINT_MIN(not-1).third_party/bash/builtins/fc.def:334-350(fc_builtin()): computeslast_hist = i - rh - hist_last_line_added, backs up over the null tail slot, and clamps its ownlast_hist < 0to0("per POSIX").third_party/bash/builtins/fc.def:593-600(fc_gethnum()): recomputes the rawlast_histand returns the ordinary signed integer-1(NOTHIST_INVALID/HIST_ERANGE) whenlast_hist < 0.third_party/bash/builtins/fc.def:379-399(fc_builtin()): sentinel checks (HIST_INVALID,HIST_ERANGE,HIST_NOTFOUND) run first, then ordinary negative indices (-1) are clamped to0.third_party/bash/builtins/fc.def:679-684(fc_gethist()): accepts only non-negative indices (i >= 0), so the execute form (fc -s, including barefc -s) reportsfc: no command foundinstead of recursively re-executing the in-flightfc -sentry.Changes
src/builtins/fc.rs:fc_gethnum()to returnResult<i64, SpecErr>, returningOk(-1)whenraw_last_hist < 0(fc.def:599-600).raw_last_hist(passed tofc_gethnumand barefc -s) from POSIX-clampedlast_hist = raw_last_hist.max(0)(fc.def:349-350).execute(fc -s): reject negative resolution (both-1and sentinels) withfc: no command found(fc.def:679-684), fixing both explicit specs and the barefc -sself-recursion hang.histbeg/histendto0after sentinel checks (fc.def:395-399).SpecErr::ErangetoSpecErr::Invalidto reflectHIST_INVALID.tests/issues_4200_4299.rs+tests/issues_4200_4299/issue4247_fc_sole_current_entry.rs:fc -l,fc -l 0,fc -l 1 2,fc -l -1,fc -l 99,fc -l -99,fc -l nosuchcmd), execute forms (fc -s,fc -s 0,fc -s 1,fc -s nosuchcmd), prior-entry controls, history-off shapes, and command substitution.What this PR deletes
Err(SpecErr::Erange)early return infc_gethnumwhenlast_hist < 0and the misleadingSpecErr::Erangeenum variant (src/builtins/fc.rs).last_hist.max(0)bypass for barefc -sthat caused sole-current-entryfc -sto re-execute itself recursively.test_fc_negative_last_hist_on_sole_current_entry_returns_erangeunit test from fix(fc): return Erange when last_hist < 0 instead of wrapping to usize::MAX #4233 with GNU-conforming unit tests.Verification
/usr/local/bin/bash) matrix: 95/95 noninteractive cases byte-exact (set -o historysole-entry & prior-entry,set +o history0/1/2 entries,HISTIGNORE='fc*', command substitution, edge specs).RUSTFLAGS="-D warnings" cargo check --lib --locked: clean (0 warnings).cargo test --lib builtins::fc --locked: 34/34 passed.cargo test --test issues_4200_4299 --locked: 7/7 passed.cargo test --lib builtins::fc --locked: 34/34 passed.cargo test --test issues_4200_4299 --locked: 7/7 passed.python scripts/check-rustfmt.py: ok (226 targets).python scripts/check-marker-literals.py: OK.python scripts/check-api-ledger.py: OK (298 symbols).Fixes #4247