1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:47:44 +00:00

LibWeb: Fix division by zero in table columns width distribution

If total max columns width (grid_max) is zero then available width
should be divided equally between columns. Previously there was
division by zero: `column.max_width / grid_max`.
This commit is contained in:
Aliaksandr Kalenik 2023-04-28 19:26:04 +03:00 committed by Andreas Kling
parent 77a5f40736
commit 9fd51a59ff
3 changed files with 33 additions and 2 deletions

View file

@ -358,8 +358,17 @@ void TableFormattingContext::distribute_width_to_columns()
}
auto width_to_distribute = available_width - columns_total_used_width();
for (auto& column : m_columns) {
column.used_width += width_to_distribute * column.max_width / grid_max;
if (grid_max == 0) {
// If total max width of columns is zero then divide distributable width equally among them
auto column_width = width_to_distribute / m_columns.size();
for (auto& column : m_columns) {
column.used_width = column_width;
}
} else {
// Distribute width to columns proportionally to their max width
for (auto& column : m_columns) {
column.used_width += width_to_distribute * column.max_width / grid_max;
}
}
}
}