Skip to content

Commit 5e9b7b1

Browse files
authored
Only use console window size if ioctl(TIOCGWINSZ) succeeded. (#418)
This avoids potentially using uninitialized data if ioctl fails. Also, zero-initialize the winsize struct to begin with.
1 parent 3afe76f commit 5e9b7b1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/boost/histogram/detail/term_info.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ inline bool utf8() {
6969
inline int width() {
7070
int w = 0;
7171
#if defined TIOCGWINSZ
72-
struct winsize ws;
73-
ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
74-
w = (std::max)(static_cast<int>(ws.ws_col), 0); // not sure if ws_col can be less than 0
72+
struct winsize ws{};
73+
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
74+
w = (std::max)(static_cast<int>(ws.ws_col), 0); // not sure if ws_col can be less than 0
7575
#endif
7676
env_t env("COLUMNS");
7777
const int col = (std::max)(static_cast<int>(env), 0);

0 commit comments

Comments
 (0)