Skip to content

fix: prevent crash in Chart.Render when repository has no commits#2504

Merged
love-linger merged 1 commit into
sourcegit-scm:developfrom
JC-Chung:fix/statistics-crash-empty-repo
Jul 1, 2026
Merged

fix: prevent crash in Chart.Render when repository has no commits#2504
love-linger merged 1 commit into
sourcegit-scm:developfrom
JC-Chung:fix/statistics-crash-empty-repo

Conversation

@JC-Chung

@JC-Chung JC-Chung commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Opening the Statistics view in an empty repository (no commits) crashes
with ArgumentOutOfRangeException in NextSampleTime.

When there are no commits, StatisticsReport._minSampleTime stays at
DateTime.MaxValue and _maxSampleTime stays at DateTime.MinValue.
For StatisticsMode.All, Count is calculated as
(end.Year - start.Year) * 12 + ..., which yields a large negative number.
The guard samples.Count == 0 in Chart.Render does not catch negative
values, so rendering proceeds with time = DateTime.MinValue (year 1,
month 1). NextSampleTime then tries new DateTime(0, 12, 1), which
throws ArgumentOutOfRangeException.

Fix by changing samples.Count == 0 to samples.Count <= 0.

@love-linger love-linger self-assigned this Jul 1, 2026
@love-linger love-linger added the bug Something isn't working label Jul 1, 2026
@love-linger love-linger merged commit bb9a360 into sourcegit-scm:develop Jul 1, 2026
14 checks passed
@JC-Chung JC-Chung deleted the fix/statistics-crash-empty-repo branch July 1, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants