Skip to content

fix(fc): return Erange when last_hist < 0 instead of wrapping to usize::MAX - #4233

Merged
caomengxuan666 merged 1 commit into
unixwin:masterfrom
dingyi580:fix/fc-negative-last-hist-erange
Nov 27, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:masterfrom
dingyi580:fix/fc-negative-last-hist-erange

Conversation

@dingyi580

Copy link
Copy Markdown

Summary

  • Enforce if last_hist < 0 { return Err(SpecErr::Erange); } at the top of fc_gethnum in src/builtins/fc.rs, matching GNU Bash 5.3 builtins/fc.def:599-600 (fc_gethnum: if (last_hist < 0) return (-1);).
  • Also widen fc_gethnum numeric parsing and offset arithmetic to i128 (and check digits in is_number_arg without isize parse failure) so oversized numeric specs clamp cleanly instead of wrapping or misparsing as flags.
  • Previously, running fc -l 0 or fc -l 1 2 as the first interactive command (count == 1, last_hist == -1) cast -1i64 as usize (usize::MAX) and panicked with capacity overflow when collecting (histbeg..=histend).

What was removed

  • Removed unchecked last_hist as usize casts when last_hist < 0 and s.parse::<i64>().unwrap_or(0) fallback in fc_gethnum.

Verification

  • python3 scripts/check-rustfmt.py: ok
  • bash scripts/check-utf8-boundary-hygiene.sh: clean
  • python3 scripts/check-marker-literals.py: OK
  • cargo test --lib builtins::fc::tests::test_fc_negative_last_hist_on_sole_current_entry_returns_erange: 1 passed, 0 failed (macOS aarch64; fail-first panicked with capacity overflow on master)
  • Full 83-suite WSL GNU baseline: owed to CI

@caomengxuan666

Copy link
Copy Markdown
Member

CAPTAIN-VERIFY(运行时复验,devin-mac 实跑):新钉绿、fail-first 成立(摘 Erange 守卫即复现 capacity overflow panic);oracle 侧 fc 索引模型观察项已由队长另行记录、非本 PR 返工项。 证据达合入门,队长合入。

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.

2 participants