<br><tt><font size=2>Eric Blake <eblake@redhat.com> wrote on 09/24/2010
04:01:55 PM:<br>
<br>
<br>
> libvir-list</font></tt>
<br><tt><font size=2>> <br>
> On 09/24/2010 01:38 PM, Stefan Berger wrote:<br>
> <br>
> > To prevent consecutive spaces in comments from becoming a single
space<br>
> > (by bash), the IFS variable is now set to an empty string. Also,
commands<br>
> > are now executed using bash's 'eval' command.<br>
> <br>
> -#define CMD_EXEC   "res=`${cmd}`" CMD_SEPARATOR<br>
> +#define CMD_EXEC   "res=`eval ${cmd}`" CMD_SEPARATOR</font></tt>
<br><tt><font size=2>> <br>
> Underquoted.  To be robust, this needs to be:<br>
> <br>
> "res=`eval \"$cmd\"" CMD_SEPARATOR<br>
> <br>
</font></tt>
<br><tt><font size=2>Ok, I made this change.</font></tt>
<br><tt><font size=2><br>
> which will then avoid your need for the empty IFS hack and double
<br>
> escaping (you'll still need single escaping, but that's a bit more
<br>
> manageable).</font></tt>
<br>
<br><tt><font size=2>I just tried the TCK test without and with double-escaping
in libvirtd</font></tt>
<br><tt><font size=2>and double-escaping does seem to be necessary otherwise
`ls` and $(ls)</font></tt>
<br><tt><font size=2>do get executed and their results end up in the comment.
The spaces</font></tt>
<br><tt><font size=2>are preserved, though, so I can revert the change
to IFS.</font></tt>
<br><tt><font size=2><br>
> <br>
> > +/* avoiding a compiler warning trough own implementation */<br>
> > +static const char *<br>
> > +_strchr(const char *s, int c)<br>
> > +{<br>
> > +    while (*s && *s != (char)c)<br>
> > +        s++;<br>
> > +    if (*s)<br>
> > +        return s;<br>
> > +    return NULL;<br>
> > +}<br>
> ><br>
> <br>
> Ouch.  That's probably 4x slower than the glibc version.  I'd
much <br>
> rather see:<br>
> <br>
> #undef strchr<br>
> </font></tt>
<br>
<br><tt><font size=2>Yes, that does the trick. Thanks.</font></tt>
<br><tt><font size=2><br>
> or<br>
> <br>
> (strchr)(a, b)<br>
> <br>
> which then guarantees that you get the function call, rather than
the <br>
> macro expansion; after all, the macro expansion just defers to the
<br>
> function call if both arguments are non-constants, not to mention
the <br>
> fact that the -Wlogical-op warning is only triggered by the macro
and <br>
> not by the function.</font></tt>
<br>
<br><tt><font size=2>  Stefan</font></tt>
<br>
<br>