Subject: bin/6956: fold -s breaks a line too early (patch supplied)
To: None <gnats-bugs@gnats.netbsd.org>
From: Wolfgang Helbig <helbig@Informatik.BA-Stuttgart.DE>
List: netbsd-bugs
Date: 02/07/1999 12:24:27
>Number:         6956
>Category:       bin
>Synopsis:       fold -s breaks a line too early (patch supplied)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb  7 03:35:00 1999
>Last-Modified:
>Originator:     Wolfgang Helbig
>Organization:
	
>Release:        NetBSD-current Fri Feb  5 17:29:06 UTC 1999
>Environment:
System: NetBSD rvc1 1.3I NetBSD 1.3I (RVC1) #4: Sun Feb 7 10:59:47 CET 1999 helbig@rvc1:/usr/src/sys/arch/i386/compile/RVC1 i386


>Description:
	If fold has to split at word boundary (-s) the next line might be split
	way before the line width is reached.
>How-To-Repeat:
vvvvvvvvvv	example input to fold -s:
This is an example to show the bug in "fold -s". The character following this is	a tabulator. (after the last word "is") This will cause fold to compute the columns needed by "is" as 16 instead of 2. This whole text is one line!
^^^^^^^^^^	End of example input.
vvvvvvvvvv	Start of output:
This is an example to show the bug in "fold -s". The character following this 
is	a tabulator. (after the last word "is") This will cause 
fold to compute the columns needed by "is" as 16 instead of 2. This whole text 
is one line!
^^^^^^^^^^	End of output.
vvvvvvvvvv	Start of output from fixed fold:
This is an example to show the bug in "fold -s". The character following this 
is	a tabulator. (after the last word "is") This will cause fold to compute 
the columns needed by "is" as 16 instead of 2. This whole text is one line!
^^^^^^^^^^	End of output.
>Fix:
	The fix is much easier than the description of the bug:
	In fact I discovered the bug while reading the source after doing
	exercise 1-22 from K&R's "The C Programming Language" 2nd Edition.
--- /usr/src/usr.bin/fold/fold.c	Mon Oct 20 16:38:41 1997
+++ fold.c	Sat Feb  6 23:18:23 1999
@@ -173,7 +173,7 @@
 				indx -= last_space;
 				col = 0;
 				for (i = 0; i < indx; i++) {
-					col = new_column_position (col, ch);
+					col = new_column_position (col, buf[i]);
 				}
 			} else {
 				fwrite (buf, 1, indx, stdout);
>Audit-Trail:
>Unformatted: