From 280190248bfbadaec4575932dc956401f7bb6390 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 20 Jun 2026 11:09:03 +0200 Subject: lib: harden scoped attributes --- ttwhy/scoped_attributes.cppm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ttwhy/scoped_attributes.cppm') diff --git a/ttwhy/scoped_attributes.cppm b/ttwhy/scoped_attributes.cppm index c68ab01..080bca7 100644 --- a/ttwhy/scoped_attributes.cppm +++ b/ttwhy/scoped_attributes.cppm @@ -56,9 +56,15 @@ namespace ttwhy export struct scoped_attributes { explicit scoped_attributes(int file_descriptor) - : m_file_descriptor{::dup(file_descriptor)} - , m_attributes{read_attributes(file_descriptor)} - {} + : m_file_descriptor{-1} + , m_attributes{} + { + if (isatty(file_descriptor)) + { + m_file_descriptor = dup(file_descriptor); + m_attributes = read_attributes(m_file_descriptor); + } + } scoped_attributes(scoped_attributes const &) = delete; -- cgit v1.2.3