Skip to content

Commit 87730e3

Browse files
authored
Code Quality: Added protection for System.DivideByZeroException (files-community#17031)
1 parent 2747d23 commit 87730e3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Files.App.Controls/AdaptiveGridView/AdaptiveGridView.Properties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private double ItemWidth
152152

153153
private static int CalculateColumns(double containerWidth, double itemWidth)
154154
{
155-
var columns = (int)Math.Round(containerWidth / itemWidth);
155+
var columns = itemWidth > 0 ? (int)Math.Round(containerWidth / itemWidth) : 0;
156156
if (columns == 0)
157157
{
158158
columns = 1;

src/Files.App.Controls/AdaptiveGridView/AdaptiveGridView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected virtual double CalculateItemWidth(double containerWidth)
119119
_needContainerMarginForLayout = true;
120120
}
121121

122-
return (containerWidth / columns) - itemMargin.Left - itemMargin.Right;
122+
return columns > 0 ? (containerWidth / columns) - itemMargin.Left - itemMargin.Right : 0;
123123
}
124124

125125
/// <summary>

0 commit comments

Comments
 (0)