From 003aaef883db5f18fd43cfb6cc019383d681221b Mon Sep 17 00:00:00 2001 From: Sujal Patel Date: Mon, 22 Apr 1996 18:37:22 +0000 Subject: [PATCH] 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) --- usr.bin/fmt/fmt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/usr.bin/fmt/fmt.c b/usr.bin/fmt/fmt.c index cba6456131bd..4bd1a7f76b27 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. */