[PATCH 1/2] vi: avoid spurious error if no filename is provided

Ron Yorston rmy at tigress.co.uk
Mon Aug 18 12:59:59 UTC 2014


Since commit 32afd3a (vi: some simplifications) starting vi without a
filename on the command line has resulted in an error message in the
status line:  '(null)' Bad address.

The commit removed a call to the file_size function which checked for a
null filename.  This prevented file_insert (and hence open) from being
called with a null filename.

Signed-off-by: Ron Yorston <rmy at tigress.co.uk>
---
 editors/vi.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index 24a9f60..9f55af1 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -722,7 +722,7 @@ int vi_main(int argc, char **argv)
 /* will also update current_filename */
 static int init_text_buffer(char *fn)
 {
-	int rc;
+	int rc = -1;
 
 	flush_undo_data();
 	modified_count = 0;
@@ -741,7 +741,8 @@ static int init_text_buffer(char *fn)
 		free(current_filename);
 		current_filename = xstrdup(fn);
 	}
-	rc = file_insert(fn, text, 1);
+	if (fn != NULL)
+		rc = file_insert(fn, text, 1);
 	if (rc < 0) {
 		// file doesnt exist. Start empty buf with dummy line
 		char_insert(text, '\n', NO_UNDO);
-- 
1.7.1



More information about the busybox mailing list