Landry Breuil <lan...@rhaalovely.net> writes:

> Hi,
>
> as i found out while wandering through mozilla's build system revamp for
> thunderbird - it turns out our pdksh has a "difference" with zsh, bash &
> bash in the following case :
>
> [05:38] dawn:/src/comm-central/ $set foo bar baz ; for out in ; do echo $out 
> ; done
> foo
> bar
> baz
> [05:40] dawn:/src/comm-central/ $zsh 
> dawn% set foo bar baz ; for out in ; do echo $out ; done
> dawn% 
> [05:41] dawn:/src/comm-central/ $bash
> bash-4.2$ set foo bar baz ; for out in ; do echo $out ; done
> bash-4.2$ exit
> [05:43] dawn:/src/comm-central/ $dash
> $set foo bar baz ; for out in ; do echo $out ; done

[...]

> As you can see, ksh outputs set values. boom in the thunderbird trunk
> configure script, cf https://bugzilla.mozilla.org/show_bug.cgi?id=878661
> for the complete analysis.
>
> So, a real bug to fix, or just a "difference" ?

I'd say it's a bug, simo^Wposix says[1]:

--8<--
The format for the for loop is as follows:

  for name [ in [word ... ]]
  do
      compound-list
  done

First, the list of words following in shall be expanded to generate
a list of items. Then, the variable name shall be set to each item, in
turn, and the compound-list executed each time. If no items result from
the expansion, the compound-list shall not be executed. Omitting:

  in word...

shall be equivalent to:

  in "$@"
-->8--

The list of items can be empty but nothing says that in this case the
interpretation should be done like when <in "$@"> is omitted.

Here's a patch, roughly tested.  The idea is to return an empty (but not
NULL) list of tokens to exec.c:l.263 and exec.c:l.281

The behavior seems consistent and tests are ok but ENOTIME to check
whether all is actually well today.

> Landry
>

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

Index: syn.c
===================================================================
RCS file: /cvs/src/bin/ksh/syn.c,v
retrieving revision 1.28
diff -u -p -r1.28 syn.c
--- syn.c       23 Jul 2008 16:34:38 -0000      1.28
+++ syn.c       3 Jun 2013 11:05:29 -0000
@@ -598,13 +598,8 @@ wordlist(void)
                XPput(args, yylval.cp);
        if (c != '\n' && c != ';')
                syntaxerr((char *) 0);
-       if (XPsize(args) == 0) {
-               XPfree(args);
-               return NULL;
-       } else {
-               XPput(args, NULL);
-               return (char **) XPclose(args);
-       }
+       XPput(args, NULL);
+       return (char **) XPclose(args);
 }
 
 /*

Reply via email to