From owner-freebsd-bugs Mon Apr 22 05:50:02 1996 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id FAA02576 for bugs-outgoing; Mon, 22 Apr 1996 05:50:02 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id FAA02558 Mon, 22 Apr 1996 05:50:01 -0700 (PDT) Date: Mon, 22 Apr 1996 05:50:01 -0700 (PDT) Message-Id: <199604221250.FAA02558@freefall.freebsd.org> To: freebsd-bugs Cc: From: "matthew c. mead" Subject: Re: bin/1153: fmt segfaults Reply-To: "matthew c. mead" Sender: owner-bugs@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk The following reply was made to PR bin/1153; it has been noted by GNATS. From: "matthew c. mead" 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/