From 407d4944c05f15c09b6a933236873720fc67decb Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 26 Nov 2025 16:21:53 +0300 Subject: [PATCH] Only use console window size if ioctl(TIOCGWINSZ) succeeded. This avoids potentially using uninitialized data if ioctl fails. Also, zero-initialize the winsize struct to begin with. --- include/boost/histogram/detail/term_info.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/histogram/detail/term_info.hpp b/include/boost/histogram/detail/term_info.hpp index 8d34a4ba..8eb19666 100644 --- a/include/boost/histogram/detail/term_info.hpp +++ b/include/boost/histogram/detail/term_info.hpp @@ -69,9 +69,9 @@ inline bool utf8() { inline int width() { int w = 0; #if defined TIOCGWINSZ - struct winsize ws; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws); - w = (std::max)(static_cast(ws.ws_col), 0); // not sure if ws_col can be less than 0 + struct winsize ws{}; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0) + w = (std::max)(static_cast(ws.ws_col), 0); // not sure if ws_col can be less than 0 #endif env_t env("COLUMNS"); const int col = (std::max)(static_cast(env), 0);