]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
Silence unused-but-set-variable warnings
authorJozsef Kadlecsik <kadlec@netfilter.org>
Wed, 17 Feb 2021 09:07:27 +0000 (10:07 +0100)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Fri, 19 Feb 2021 20:20:58 +0000 (21:20 +0100)
When ipset is compiled in non-debug mode, in some environments warnings
treated as errors emitted:

  session.c: In function 'build_msg':
  session.c:1985:28: warning: variable 'type' set but not used
[-Wunused-but-set-variable]
     const struct ipset_type *type;
                            ^
  session.c:2030:28: warning: variable 'type' set but not used
[-Wunused-but-set-variable]
     const struct ipset_type *type;
                            ^
Fix it by hiding the unused variable definitions/settings in non-debug mode.

Reported by Serhey Popovych.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
include/libipset/debug.h
lib/session.c

index 9743d595787b0cec160497efc968d2ecb11d9c80..92d5f89d83f3b6df591c9ac5426c7fd6b555417d 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <sys/socket.h>
 #include <linux/netlink.h>
+#define DD(cmd)                cmd
 #define D(fmt, args...) \
        fprintf(stderr, "%s: %s: " fmt "\n", __FILE__, __func__ , ## args)
 #define IF_D(test, fmt, args...) \
@@ -25,6 +26,7 @@ dump_nla(struct  nlattr *nla[], int maxlen)
                D("nla[%u] does%s exist", i, nla[i] ? "" : " NOT");
 }
 #else
+#define DD(cmd)
 #define D(fmt, args...)
 #define IF_D(test, fmt, args...)
 #define dump_nla(nla, maxlen)
index b088bc82888ac94d5285dacaa9ad4be0bbec5ddc..1ca26ffda8c1b4134f78d619d4891693927a5a1e 100644 (file)
@@ -1982,7 +1982,7 @@ build_msg(struct ipset_session *session, bool aggregate)
                break;
        case IPSET_CMD_ADD:
        case IPSET_CMD_DEL: {
-               const struct ipset_type *type;
+               DD(const struct ipset_type *type);
 
                if (!aggregate) {
                        /* Setname, type not checked/added yet */
@@ -2007,7 +2007,7 @@ build_msg(struct ipset_session *session, bool aggregate)
                                open_nested(session, nlh, IPSET_ATTR_ADT);
                        }
                }
-               type = ipset_data_get(data, IPSET_OPT_TYPE);
+               DD(type = ipset_data_get(data, IPSET_OPT_TYPE));
                D("family: %u, type family %u",
                  ipset_data_family(data), type->family);
                if (open_nested(session, nlh, IPSET_ATTR_DATA)) {
@@ -2027,7 +2027,7 @@ build_msg(struct ipset_session *session, bool aggregate)
                break;
        }
        case IPSET_CMD_TEST: {
-               const struct ipset_type *type;
+               DD(const struct ipset_type *type);
                /* Return codes are not aggregated, so tests cannot be either */
 
                /* Setname, type not checked/added yet */
@@ -2040,7 +2040,7 @@ build_msg(struct ipset_session *session, bool aggregate)
                        return ipset_err(session,
                                "Invalid test command: missing settype");
 
-               type = ipset_data_get(data, IPSET_OPT_TYPE);
+               DD(type = ipset_data_get(data, IPSET_OPT_TYPE));
                D("family: %u, type family %u",
                  ipset_data_family(data), type->family);
                ADDATTR_SETNAME(session, nlh, data);