Skip to content

Commit

Permalink
core: always define statements for NL_DBG()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thom311 committed Apr 22, 2024
1 parent 713546f commit 7eb522e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
11 changes: 3 additions & 8 deletions include/nl-aux-core/nl-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
2 changes: 0 additions & 2 deletions lib/route/neigh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions lib/route/route_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7eb522e

Please sign in to comment.