From fbdd4e3c9d1f19a9ad1fdb1ab950a68f984b939d Mon Sep 17 00:00:00 2001 From: Piotr Murach Date: Tue, 5 Dec 2023 21:19:55 +0000 Subject: [PATCH] Change size from ioctl to allocate and read window buffer with fewer objects --- CHANGELOG.md | 1 + lib/tty/screen.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ca6c3c..a5035ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changed * Change the ioctl system call support check to use the output method * Change size from ioctl to extract window buffer format and length to constants +* Change size from ioctl to allocate and read window buffer with fewer objects ### Fixed * Fix ioctl call test to stub terminal size encoding for big-endian systems diff --git a/lib/tty/screen.rb b/lib/tty/screen.rb index 93f97b5..721fd3b 100644 --- a/lib/tty/screen.rb +++ b/lib/tty/screen.rb @@ -210,14 +210,14 @@ def size_from_io_console(verbose: false) # # @api private def size_from_ioctl - buffer = ([0] * TIOCGWINSZ_BUF_LEN).pack(TIOCGWINSZ_BUF_FMT) + buffer = Array.new(TIOCGWINSZ_BUF_LEN, 0).pack(TIOCGWINSZ_BUF_FMT) if ioctl?(TIOCGWINSZ, buffer) || ioctl?(TIOCGWINSZ_PPC, buffer) || ioctl?(TIOCGWINSZ_SOL, buffer) - rows, cols, = buffer.unpack(TIOCGWINSZ_BUF_FMT)[0..1] - return [rows, cols] if nonzero_column?(cols) + rows, cols, = buffer.unpack(TIOCGWINSZ_BUF_FMT) + [rows, cols] if nonzero_column?(cols) end end