[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [patch 2/5] Instantiate comments in ip(6)tables rules



On 09/24/2010 01:38 PM, Stefan Berger wrote:

To prevent consecutive spaces in comments from becoming a single space
(by bash), the IFS variable is now set to an empty string. Also, commands
are now executed using bash's 'eval' command.

-#define CMD_EXEC   "res=`${cmd}`" CMD_SEPARATOR
+#define CMD_EXEC   "res=`eval ${cmd}`" CMD_SEPARATOR

Underquoted.  To be robust, this needs to be:

"res=`eval \"$cmd\"" CMD_SEPARATOR

which will then avoid your need for the empty IFS hack and double escaping (you'll still need single escaping, but that's a bit more manageable).

+/* avoiding a compiler warning trough own implementation */
+static const char *
+_strchr(const char *s, int c)
+{
+    while (*s && *s != (char)c)
+        s++;
+    if (*s)
+        return s;
+    return NULL;
+}


Ouch. That's probably 4x slower than the glibc version. I'd much rather see:

#undef strchr

or

(strchr)(a, b)

which then guarantees that you get the function call, rather than the macro expansion; after all, the macro expansion just defers to the function call if both arguments are non-constants, not to mention the fact that the -Wlogical-op warning is only triggered by the macro and not by the function.

--
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]