[PATCH 6/8] iptablesPrivateChainCreate: Switch to STRSKIP()

Michal Privoznik via Devel posted 8 patches 2 weeks ago
[PATCH 6/8] iptablesPrivateChainCreate: Switch to STRSKIP()
Posted by Michal Privoznik via Devel 2 weeks ago
From: Michal Privoznik <mprivozn@redhat.com>

The body of iptablesPrivateChainCreate() uses STRPREFIX() to
match strings starting with certain prefix. Then it uses pointer
arithmetic to skip the prefix. Well, that's exactly what
STRSKIP() is meant to do. Switch the body to use the latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/network/network_iptables.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/network/network_iptables.c b/src/network/network_iptables.c
index be91b273ed..19dcfc7c8b 100644
--- a/src/network/network_iptables.c
+++ b/src/network/network_iptables.c
@@ -90,17 +90,21 @@ iptablesPrivateChainCreate(virFirewall *fw,
 
     line = lines;
     while (line && *line) {
-        if (STRPREFIX(*line, "-N ")) { /* eg "-N LIBVIRT_INP" */
-            if (virHashUpdateEntry(chains, *line + 3, (void *)0x1) < 0)
+        const char *tmp;
+
+        if ((tmp = STRSKIP(*line, "-N "))) { /* eg "-N LIBVIRT_INP" */
+            if (virHashUpdateEntry(chains, tmp, (void *)0x1) < 0)
                 return -1;
-        } else if (STRPREFIX(*line, "-A ")) { /* eg "-A INPUT -j LIBVIRT_INP" */
-            char *sep = strchr(*line + 3, ' ');
+        } else if ((tmp = STRSKIP(*line, "-A "))) { /* eg "-A INPUT -j LIBVIRT_INP" */
+            char *sep = strchr(tmp, ' ');
 
             if (sep) {
+                char *target;
+
                 *sep = '\0';
-                if (STRPREFIX(sep + 1, "-j ")) {
-                    if (virHashUpdateEntry(links, sep + 4,
-                                           (char *)*line + 3) < 0)
+                if ((target = STRSKIP(sep + 1, "-j "))) {
+                    if (virHashUpdateEntry(links, target,
+                                           (char *)tmp) < 0)
                         return -1;
                 }
             }
-- 
2.51.2