From cecd54df42dd66fdf8386ed461e16b725bffc827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Du=C4=87ak?= <31933626+NikolaDucak@users.noreply.github.com> Date: Wed, 17 Nov 2021 10:16:09 +0100 Subject: [PATCH] Fix gridbox segfault (#260) The problem was about --- src/ftxui/dom/gridbox.cpp | 2 +- src/ftxui/dom/gridbox_test.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ftxui/dom/gridbox.cpp b/src/ftxui/dom/gridbox.cpp index 0cd619c0..fd715121 100644 --- a/src/ftxui/dom/gridbox.cpp +++ b/src/ftxui/dom/gridbox.cpp @@ -20,7 +20,7 @@ class GridBox : public Node { for (const auto& line : lines_) x_size = std::max(x_size, (int)line.size()); for (auto& line : lines_) { - while (line.size() < (size_t)y_size) { + while (line.size() < (size_t)x_size) { line.push_back(filler()); } } diff --git a/src/ftxui/dom/gridbox_test.cpp b/src/ftxui/dom/gridbox_test.cpp index c8dae798..da9bc399 100644 --- a/src/ftxui/dom/gridbox_test.cpp +++ b/src/ftxui/dom/gridbox_test.cpp @@ -569,6 +569,25 @@ TEST(GridboxTest, Horizontal_FlexGrow_NoFlex_FlewShrink) { } } +// Regression test for https://github.com/ArthurSonzogni/FTXUI/issues/259 +TEST(GridboxTest, MissingCells) { + auto root = gridbox({ + {cell("1"), cell("2"), cell("3")}, + {cell("4"), cell("5")}, + }); + + Screen screen(20, 7); + Render(screen, root); + EXPECT_EQ(screen.ToString(), + "╭─╮╭─╮╭─╮ \r\n" + "│1││2││3│ \r\n" + "╰─╯╰─╯╰─╯ \r\n" + "╭─╮╭─╮ \r\n" + "│4││5│ \r\n" + "╰─╯╰─╯ \r\n" + " "); +} + // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in // the LICENSE file.