summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2024-04-22 09:13:24 +0200
committerThomas Haller <thaller@redhat.com>2024-04-22 10:30:03 +0200
commitdbe21b8d64cdfd38476cddee0bb766fa7d4a7c3c (patch)
tree957fafa052367e50a3c8a1bb625dc637e0452980
parente592dd89f1d6a6613b2ca37434ad568da0998b19 (diff)
downloadlibnl-dbe21b8d64cdfd38476cddee0bb766fa7d4a7c3c.tar.gz
core: always define statements for NL_DBG()
Conditionally defining to nothing, means that the compiler doesn't see the print statement without NL_DEBUG. In turn, we lack checking of the statement by the compiler. Instead, add an "if (NL_DEBUG)" around it. Since NL_DEBUG is a constant, the compiler will optimize out all the code of the statement, while still checking it.
-rw-r--r--include/nl-aux-core/nl-core.h11
-rw-r--r--lib/route/neigh.c2
-rw-r--r--lib/route/route_obj.c4
3 files changed, 3 insertions, 14 deletions
diff --git a/include/nl-aux-core/nl-core.h b/include/nl-aux-core/nl-core.h
index c6bdbebb..5198296f 100644
--- a/include/nl-aux-core/nl-core.h
+++ b/include/nl-aux-core/nl-core.h
@@ -5,21 +5,16 @@
#include "base/nl-base-utils.h"
-#if NL_DEBUG
#define NL_DBG(LVL, FMT, ARG...) \
do { \
- if (LVL <= nl_debug) { \
- int _errsv = errno; \
+ if ((NL_DEBUG) && (LVL) <= nl_debug) { \
+ const int _errsv = errno; \
+ \
fprintf(stderr, "DBG<" #LVL ">%20s:%-4u %s: " FMT, \
__FILE__, __LINE__, __func__, ##ARG); \
errno = _errsv; \
} \
} while (0)
-#else /* NL_DEBUG */
-#define NL_DBG(LVL, FMT, ARG...) \
- do { \
- } while (0)
-#endif /* NL_DEBUG */
struct nl_addr;
void nl_addr_put(struct nl_addr *);
diff --git a/lib/route/neigh.c b/lib/route/neigh.c
index 1f19fed0..7e698b49 100644
--- a/lib/route/neigh.c
+++ b/lib/route/neigh.c
@@ -242,9 +242,7 @@ static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey,
uint16_t n_vlan;
char n_addr[0];
} _nl_packed *nkey;
-#if NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
-#endif
if (neigh->n_family == AF_BRIDGE) {
if (neigh->n_lladdr)
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
index 488cff5b..50775937 100644
--- a/lib/route/route_obj.c
+++ b/lib/route/route_obj.c
@@ -345,9 +345,7 @@ static void route_keygen(struct nl_object *obj, uint32_t *hashkey,
uint32_t rt_prio;
char rt_addr[0];
} _nl_packed *rkey = NULL;
-#if NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
-#endif
if (route->rt_dst)
addr = route->rt_dst;
@@ -502,9 +500,7 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
struct rtnl_route *old_route = (struct rtnl_route *) old_obj;
struct rtnl_nexthop *new_nh;
int action = new_obj->ce_msgtype;
-#if NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
-#endif
/*
* ipv6 ECMP route notifications from the kernel come as