Skip to content

Clamp GetCommandsInRange against the remaining commands so a large count cannot overflow [patch] - #106

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-105-range-overflow
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-105-range-overflow

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #105

What changed

StackManager.GetCommandsInRange computed Math.Min(startIndex + count, _commands.Count). With a non-zero start and count = int.MaxValue, the sum wrapped negative, Math.Min picked it, and List<T>.GetRange threw ArgumentException. The method now compares count against the commands remaining after startIndex, so the addition that overflowed is gone.

Test

Added GetCommandsInRange_CountOfIntMaxValueFromNonZeroStart_ReturnsRemainingCommands. It covers starts at 1 and 2 with int.MaxValue, plus an ordinary in-range count.

  • Without the fix, the new test fails with the ArgumentException from GetRange described in the issue.
  • With the fix, all 95 tests pass on net10.0.

🤖 Generated with Claude Code

https://claude.ai/code/session_013xQ2dceFuWS8VLEn2xLuZE


Generated by Claude Code

…unt cannot overflow [patch]

GetCommandsInRange(1, int.MaxValue) summed startIndex + count, which
wrapped negative and made List.GetRange throw. Compare count against the
commands remaining after startIndex instead.

Fixes #105

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013xQ2dceFuWS8VLEn2xLuZE
@sonarqubecloud

Copy link
Copy Markdown

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.

StackManager.GetCommandsInRange(start, int.MaxValue) throws ArgumentException instead of returning the remaining commands (int overflow)

2 participants