Date: Mon, 22 Apr 1996 08:44:51 -0400 (EDT) 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 Message-ID: <199604221244.IAA04738@neon.Glock.COM> In-Reply-To: <199604220503.BAA01235@neon.Glock.COM> from "mmead@Glock.COM" at Apr 22, 96 01:03:08 am
next in thread | previous in thread | raw e-mail | index | archive | help
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?199604221244.IAA04738>
