Fixed infinite loop in Screen::ToString() for non-printable chars (#69)

This commit is contained in:
robobuggy 2021-02-04 09:32:05 +01:00 committed by GitHub
parent 92ec5ab4ca
commit d0eab41344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
}