]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Move NULL pointer check into save_iface()
authorPhil Sutter <phil@nwl.cc>
Fri, 26 Jul 2024 18:53:12 +0000 (20:53 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 31 Jul 2024 21:13:55 +0000 (23:13 +0200)
Simplify callers a bit, the function tests other conditions
disqualifying any output already.

While being at it, invert the conditional - it is more readable this
way.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/xshared.c

index 1070fea42c8cf93f4629349d315c1172049daa98..2a5eef09c75deaf9a888f6fc8eb4bd5c3b9b3ab5 100644 (file)
@@ -759,10 +759,8 @@ void print_ifaces(const char *iniface, const char *outiface, uint8_t invflags,
 
 static void save_iface(char letter, const char *iface, int invert)
 {
-       if (!strlen(iface) || (!strcmp(iface, "+") && !invert))
-               return;
-
-       printf("%s -%c %s", invert ? " !" : "", letter, iface);
+       if (iface && strlen(iface) && (strcmp(iface, "+") || invert))
+               printf("%s -%c %s", invert ? " !" : "", letter, iface);
 }
 
 static void command_match(struct iptables_command_state *cs, bool invert)
@@ -1095,12 +1093,8 @@ void print_rule_details(unsigned int linenum, const struct xt_counters *ctrs,
 void save_rule_details(const char *iniface, const char *outiface,
                       uint16_t proto, int frag, uint8_t invflags)
 {
-       if (iniface != NULL) {
-               save_iface('i', iniface, invflags & IPT_INV_VIA_IN);
-       }
-       if (outiface != NULL) {
-               save_iface('o', outiface, invflags & IPT_INV_VIA_OUT);
-       }
+       save_iface('i', iniface, invflags & IPT_INV_VIA_IN);
+       save_iface('o', outiface, invflags & IPT_INV_VIA_OUT);
 
        if (proto > 0) {
                const char *pname = proto_to_name(proto, true);