Hi,

the attached diff fixes 2 issues with line wrappings in wall(1).

* The 79th character is skipped and not printed because of the line
  wrapping.
  => Go back one character in the buffer, if we were not printing a new
  line.

* The line wrapping counter is reset after line wrapping and also after
  reading 100 bytes from STDIN. So if we wrapped at 79, the counter is
  reset after 20 again and we will write 99 instead of 79.
  => Only reset the counter after we explicitly do the line wrapping.

Both issues can be reproduced with "jot 100 | tr '\n' ' ' | wall".


Best regards

Anton Borowka

Index: usr.bin/wall/wall.c
===================================================================
RCS file: /mount/cvsdev/openbsd/cvs/src/usr.bin/wall/wall.c,v
retrieving revision 1.35
diff -u -p -r1.35 wall.c
--- usr.bin/wall/wall.c	12 Jul 2021 15:09:20 -0000	1.35
+++ usr.bin/wall/wall.c	19 Apr 2022 17:27:06 -0000
@@ -229,14 +229,16 @@ makemsg(char *fname)
 			err(1, "can't read %s", fname);
 		setegid(egid);
 	}
+	cnt = 0;
 	while (fgets(lbuf, sizeof(lbuf), stdin))
-		for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
+		for (p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
 			if (cnt == 79 || ch == '\n') {
 				for (; cnt < 79; ++cnt)
 					putc(' ', fp);
 				putc('\r', fp);
 				putc('\n', fp);
 				cnt = -1;
+				if (ch != '\n') p--;
 			} else if (!isu8cont(ch))
 				putc(isprint(ch) || isspace(ch) || ch == '\a' ?
 				    ch : '?', fp);

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to