Skip to content

Commit 5d670fc

Browse files
darthShadowncw
authored andcommitted
accounting: fix percentDiff calculation -- fixes rclone#8345
Signed-off-by: Anagh Kumar Baranwal <[email protected]>
1 parent b5e72e2 commit 5d670fc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/accounting/stats_groups_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,14 @@ func TestCountError(t *testing.T) {
237237
}
238238

239239
func percentDiff(start, end uint64) uint64 {
240-
return (start - end) * 100 / start
240+
if start == 0 {
241+
return 0 // Handle zero start value to avoid division by zero
242+
}
243+
var diff uint64
244+
if end > start {
245+
diff = end - start // Handle case where end is larger than start
246+
} else {
247+
diff = start - end
248+
}
249+
return (diff * 100) / start
241250
}

0 commit comments

Comments
 (0)