From 5d670fc54aa45850cd23c6e64e72c466fe9f4f68 Mon Sep 17 00:00:00 2001 From: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com> Date: Thu, 13 Feb 2025 17:09:24 +0530 Subject: [PATCH] accounting: fix percentDiff calculation -- fixes #8345 Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com> --- fs/accounting/stats_groups_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/accounting/stats_groups_test.go b/fs/accounting/stats_groups_test.go index 8c02229e7..b7a817824 100644 --- a/fs/accounting/stats_groups_test.go +++ b/fs/accounting/stats_groups_test.go @@ -237,5 +237,14 @@ func TestCountError(t *testing.T) { } func percentDiff(start, end uint64) uint64 { - return (start - end) * 100 / start + if start == 0 { + return 0 // Handle zero start value to avoid division by zero + } + var diff uint64 + if end > start { + diff = end - start // Handle case where end is larger than start + } else { + diff = start - end + } + return (diff * 100) / start }