]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
stty: fix off by one column wrapping on output
authorPádraig Brady <P@draigBrady.com>
Sat, 31 Dec 2022 17:03:39 +0000 (17:03 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 31 Dec 2022 19:01:59 +0000 (19:01 +0000)
* src/stty.c (wrapf): Adjust the comparison by 1,
to account for the space we're adding.
* tests/misc/stty.sh: Add a test case.
* NEWS: Mention the fix.
Reported in https://bugs.debian.org/1027442

NEWS
src/stty.c
tests/misc/stty.sh

diff --git a/NEWS b/NEWS
index 0beaef506607a3a71627d0d58ce0f2e8cc58a894..6b05c8d35a7eedb9c2a621ed5e539bda8fbb416a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   and the system supported set of valid speeds.
   [This bug was present in "the beginning".]
 
+  stty now wraps output appropriately for the terminal width.
+  Previously it may have output 1 character too wide for certain widths.
+  [bug introduced in coreutils-5.3]
+
   `wc -c` will again efficiently determine the size of large files
   on all systems.  It no longer redundantly reads data from certain
   sized files larger than SIZE_MAX.
index b4c2cbecd68ce34fca0832f5f605e5e8490bed0e..f3c7915e113a6f3d2b8c9af0e508aa43991c9891 100644 (file)
@@ -519,7 +519,7 @@ wrapf (char const *message,...)
 
   if (0 < current_col)
     {
-      if (max_col - current_col < buflen)
+      if (max_col - current_col <= buflen)
         {
           putchar ('\n');
           current_col = 0;
index bcdc80e87846c57dae2b3b0752ed3a472c43f4a1..7abcec5af29e8ae297200510f9623b6e145c7ee8 100755 (executable)
@@ -89,4 +89,10 @@ returns_ 1 strace -o log2 -e ioctl stty -blahblah || fail=1
 n_ioctl2=$(wc -l < log2) || framework_failure_
 test "$n_ioctl1" = "$n_ioctl2" || fail=1
 
+# Ensure we wrap output appropriately
+for W in $(seq 80 90); do
+  output_width=$(COLUMNS="$W" stty -a | wc -L)
+  test "$output_width" -le "$W" || fail=1
+done
+
 Exit $fail