Theo mentioned on icb yesterday that when compiling ksh for instbin, a
warning similar to this one is emitted:

/usr/src/bin/ksh/edit.c: In function 'x_print_expansions':
/usr/src/bin/ksh/edit.c:303: warning: 'l.beg' may be used uninitialized in this 
function

This warning is only seen when using -Os.

The code is a bit difficult to follow due to the XP* macros in expand.h.
The reason of the complaint is that XPptrv(l) expands to l.beg.  Note
that this is only used if use_copy == 1, which in turn is only true if l
was initialized, so I think the warning is bogus.

The following avoids the warning by being a bit less clever.

The various completions, where x_print_expansions() is used,  still seem
to work fine, both with vi and emacs editing mode.

Index: edit.c
===================================================================
RCS file: /var/cvs/src/bin/ksh/edit.c,v
retrieving revision 1.53
diff -u -p -r1.53 edit.c
--- edit.c      17 Mar 2016 23:33:23 -0000      1.53
+++ edit.c      16 Aug 2016 13:30:54 -0000
@@ -298,7 +298,6 @@ static void glob_path(int flags, const c
 void
 x_print_expansions(int nwords, char *const *words, int is_command)
 {
-       int use_copy = 0;
        int prefix_len;
        XPtrV l;
 
@@ -321,23 +320,25 @@ x_print_expansions(int nwords, char *con
                if (i == nwords) {
                        while (prefix_len > 0 && words[0][prefix_len - 1] != 
'/')
                                prefix_len--;
-                       use_copy = 1;
                        XPinit(l, nwords + 1);
                        for (i = 0; i < nwords; i++)
                                XPput(l, words[i] + prefix_len);
                        XPput(l, NULL);
+
+                       /* Enumerate expansions */
+                       x_putc('\r');
+                       x_putc('\n');
+                       pr_list((char **) XPptrv(l));
+
+                       XPfree(l); /* not x_free_words() */
+                       return;
                }
        }
 
-       /*
-        * Enumerate expansions
-        */
+       /* Enumerate expansions */
        x_putc('\r');
        x_putc('\n');
-       pr_list(use_copy ? (char **) XPptrv(l) : words);
-
-       if (use_copy)
-               XPfree(l); /* not x_free_words() */
+       pr_list(words);
 }
 
 /*

Reply via email to