summaryrefslogtreecommitdiffstats
path: root/usr.bin/fmt
diff options
context:
space:
mode:
authorsmpatel <smpatel@FreeBSD.org>1996-04-22 18:37:22 +0000
committersmpatel <smpatel@FreeBSD.org>1996-04-22 18:37:22 +0000
commit791bb4af0afd9a27ef286b6bed0bf5f610e849b4 (patch)
tree305213cdcdd602048e836ae848baa5129250f65c /usr.bin/fmt
parent7b5dbe22eca16e99a433ce4d5a9b2194c763e1ce (diff)
downloadFreeBSD-src-791bb4af0afd9a27ef286b6bed0bf5f610e849b4.zip
FreeBSD-src-791bb4af0afd9a27ef286b6bed0bf5f610e849b4.tar.gz
Fix a segfault which occurs when it gets an empty input line.
Closes PR bin/1153 Reviewed by: smpatel Submitted by: Matthew C. Mead (mmead@Glock.COM)
Diffstat (limited to 'usr.bin/fmt')
-rw-r--r--usr.bin/fmt/fmt.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/usr.bin/fmt/fmt.c b/usr.bin/fmt/fmt.c
index cba6456..4bd1a7f 100644
--- a/usr.bin/fmt/fmt.c
+++ b/usr.bin/fmt/fmt.c
@@ -172,7 +172,6 @@ fmt(fi)
*cp++ = c;
c = getc(fi);
}
- *cp = '\0';
/*
* Toss anything remaining on the input line.
@@ -180,6 +179,14 @@ fmt(fi)
while (c != '\n' && c != EOF)
c = getc(fi);
+ if (cp != NULL) {
+ *cp = '\0';
+ } else {
+ putchar('\n');
+ c = getc(fi);
+ continue;
+ }
+
/*
* Expand tabs on the way to canonb.
*/
OpenPOWER on IntegriCloud