Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Apr 1996 05:50:01 -0700 (PDT)
From:      "matthew c. mead" <mmead@Glock.COM>
To:        freebsd-bugs
Subject:   Re: bin/1153: fmt segfaults
Message-ID:  <199604221250.FAA02558@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/1153; it has been noted by GNATS.

From: "matthew c. mead" <mmead@Glock.COM>
To: mmead@Glock.COM
Cc: FreeBSD-gnats-submit@freebsd.org, bugs@freebsd.org
Subject: Re: bin/1153: fmt segfaults
Date: Mon, 22 Apr 1996 08:44:51 -0400 (EDT)

 	The patch in the previous report would not work fully.  I
 failed to test it on blank lines preceeding a the first line with
 text.  The patch I sent in will cause blank lines preceeding the
 first line with text to be eaten.  This patch corrects this
 behavior.  This patch is against the *original*
 /usr/src/usr.bin/fmt/fmt.c, *not* the one obtained after using my
 first patch.
 
 
 --- /usr/src/usr.bin/fmt/fmt.c-dist	Mon Apr 22 00:43:43 1996
 +++ /usr/src/usr.bin/fmt/fmt.c	Mon Apr 22 08:40:06 1996
 @@ -172,7 +172,9 @@
  			*cp++ = c;
  			c = getc(fi);
  		}
 -		*cp = '\0';
 +		if (cp != NULL) {
 +			*cp = '\0';
 +		}
  
  		/*
  		 * Toss anything remaining on the input line.
 @@ -186,7 +188,7 @@
  		col = 0;
  		cp = linebuf;
  		cp2 = canonb;
 -		while (cc = *cp++) {
 +		while ((cp != NULL) && (cc = *cp++)) {
  			if (cc != '\t') {
  				col++;
  				if (cp2 - canonb >= cbufsize) {
 @@ -217,12 +219,17 @@
  		/*
  		 * Swipe trailing blanks from the line.
  		 */
 -		for (cp2--; cp2 >= canonb && *cp2 == ' '; cp2--)
 -			;
 -		*++cp2 = '\0';
 -		prefix(canonb);
 -		if (c != EOF)
 +		if (cp != NULL) {
 +			for (cp2--; cp2 >= canonb && *cp2 == ' '; cp2--)
 +				;
 +			*++cp2 = '\0';
 +			prefix(canonb);
 +			if (c != EOF)
 +				c = getc(fi);
 +		} else {
 +			putchar('\n');
  			c = getc(fi);
 +		}
  	}
  }
  
 
 -matt
 
 -- 
 Matthew C. Mead
 
 mmead@Glock.COM
 http://www.Glock.COM/~mmead/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604221250.FAA02558>