From d0eab413442d084d15a328c53fb132814daa58f3 Mon Sep 17 00:00:00 2001 From: robobuggy Date: Thu, 4 Feb 2021 09:32:05 +0100 Subject: [PATCH] Fixed infinite loop in Screen::ToString() for non-printable chars (#69) --- src/ftxui/screen/screen.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index e2b83ad1..f98cc506 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -164,8 +164,15 @@ std::string Screen::ToString() { auto& pixel = pixels_[y][x]; wchar_t c = pixel.character; UpdatePixelStyle(ss, previous_pixel, pixel); + + auto width = wchar_width(c); + if (width <= 0) { + // Avoid an infinite loop for non-printable characters + c = L' '; + width = 1; + } ss << c; - x += wchar_width(c); + x += width; } }