From 7eb522efe25003a1faed8451cd21f3965d90a868 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Apr 2024 09:13:24 +0200 Subject: [PATCH] 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. --- include/nl-aux-core/nl-core.h | 11 +++-------- lib/route/neigh.c | 2 -- lib/route/route_obj.c | 4 ---- 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