From aeb147cc4a8bad6352441b8cd63e57a73be5ab91 Mon Sep 17 00:00:00 2001
From: "Alfred M. Szmidt" <ams@gnu.org>
Date: Thu, 22 Jun 2017 10:12:10 +0200
Subject: [PATCH 23/60] ftp/main.c (main): Don't assume that uninitialized
 argv[argv] is NULL.

---
 ChangeLog  | 5 +++++
 ftp/main.c | 7 +++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2f11d205..8ca7099a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-06-22  Omer Anson <oaanson@gmail.com>  (tiny change)
+
+	* ftp/main.c (main): Don't assume that uninitialized argv[argv] is
+	NULL.
+
 2017-03-03  Mats Erik Andersson  <gnu@gisladisker.se>
 
 	Test utility displays some termcaps.
diff --git a/ftp/main.c b/ftp/main.c
index 4ccb079d..0ff6e044 100644
--- a/ftp/main.c
+++ b/ftp/main.c
@@ -286,16 +286,15 @@ main (int argc, char *argv[])
   if (argc > 0)
     {
       char *xargv[5];
+      int i;
 
       if (setjmp (toplevel))
 	exit (EXIT_SUCCESS);
       signal (SIGINT, intr);
       signal (SIGPIPE, lostpeer);
       xargv[0] = program_invocation_name;
-      xargv[1] = argv[0];
-      xargv[2] = argv[1];
-      xargv[3] = argv[2];
-      xargv[4] = NULL;
+      for (i = 0; i < argc && i < 3; i++)
+	xargv[i + 1] = argv[i];
       setpeer (argc + 1, xargv);
     }
   top = setjmp (toplevel) == 0;
-- 
2.26.0.292.g33ef6b2f38

