#1027442 coreutils: stty: soft-wrapping broken, wraps to cols+1

Package:
coreutils
Source:
coreutils
Description:
GNU core utilities
Submitter:
наб
Date:
2022-12-31 17:03:04 UTC
Severity:
normal
#1027442#5
Date:
2022-12-31 15:12:48 UTC
From:
To:
Dear Maintainer,

On all three versions, at my usual teletype size, I get:
-- >8 --
$ stty -a
speed 38400 baud; rows 54; columns 172; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
-- >8 --

Or, more to the point:
-- >8 --
$ COLUMNS=172 stty -a | wc -L
173
-- >8 --

Cf. screenshot.

stty -g for easy repro:
  500:5:bf:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

Best,
наб

#1027442#10
Date:
2022-12-31 16:58:07 UTC
From:
To:
good catch!

This off by one bug was introduced in v5.3 (2005)

I'll apply the following upstream:

index b4c2cbecd..f3c7915e1 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -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;

thanks,
Pádraig