1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

LibWeb: Fix division by zero in distribute_any_remaining_free_space

This change fixes division by zero in case flex container has
"justify-content: space-between" and only single item.
This commit is contained in:
Aliaksandr Kalenik 2023-07-25 13:51:16 +02:00 committed by Andreas Kling
parent 6088374ad2
commit 849cf894d8
3 changed files with 17 additions and 1 deletions

View file

@ -0,0 +1,9 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x17.46875 children: not-inline
Box <div.container> at (8,8) content-size 784x17.46875 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (8,8) content-size 14.265625x17.46875 flex-item [BFC] children: inline
line 0 width: 14.265625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 1, rect: [8,8 14.265625x17.46875]
"A"
TextNode <#text>

View file

@ -0,0 +1,6 @@
<style>
.container {
display: flex;
justify-content: space-between;
}
</style><div class="container"><div>A</div></div>

View file

@ -1331,7 +1331,8 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
} else { } else {
initial_offset = 0; initial_offset = 0;
} }
space_between_items = flex_line.remaining_free_space / (number_of_items - 1); if (number_of_items > 1)
space_between_items = flex_line.remaining_free_space / (number_of_items - 1);
break; break;
case CSS::JustifyContent::SpaceAround: case CSS::JustifyContent::SpaceAround:
space_between_items = flex_line.remaining_free_space / number_of_items; space_between_items = flex_line.remaining_free_space / number_of_items;