From 88d07b52fb6027ac6abecca863d06080a4c7b90f Mon Sep 17 00:00:00 2001 From: Thomas Gschwantner Date: Sat, 25 May 2019 22:53:56 +0200 Subject: Add BUG() and BUG_ON() --- common.c | 2 +- dbg.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common.c b/common.c index a86641f..a3ce7ae 100644 --- a/common.c +++ b/common.c @@ -89,7 +89,7 @@ static struct wg_dynamic_attr *parse_value(enum wg_dynamic_key key, char *value) break; default: debug("Invalid key %d, aborting\n", key); - abort(); + BUG(); } attr = malloc(sizeof(struct wg_dynamic_attr) + len); diff --git a/dbg.h b/dbg.h index fa55ee9..2d32033 100644 --- a/dbg.h +++ b/dbg.h @@ -45,6 +45,9 @@ extern int DBG_LVL; #endif #define debug(...) do { if (DEBUG) log_err(__VA_ARGS__); } while (0) +#define BUG() do { __BUG(_FILENAME, __LINE__); abort(); } while (0) +#define __BUG(f,l) fprintf(stderr, "BUG: " f ":" STRINGIFY(l) "\n") +#define BUG_ON(cond) do { if (cond) BUG(); } while (0) #define assert_str_equal(a,b) ({ \ if (strcmp(a, b)) { \ -- cgit v1.2.3-59-g8ed1b