From 8493ee5e1a40f1ef65ced91be50c9f4976af8c69 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 10 Apr 2023 09:43:56 +0930 Subject: [PATCH] db: print nice message and not just backtrace on bad column name. Happens more than I expected! Signed-off-by: Rusty Russell --- db/utils.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/db/utils.c b/db/utils.c index 52e209fa4..9449e0160 100644 --- a/db/utils.c +++ b/db/utils.c @@ -21,9 +21,13 @@ size_t db_query_colnum(const struct db_stmt *stmt, assert(stmt->query->colnames != NULL); col = hash_djb2(colname) % stmt->query->num_colnames; - /* Will crash on NULL, which is the Right Thing */ - while (!streq(stmt->query->colnames[col].sqlname, - colname)) { + for (;;) { + const char *n = stmt->query->colnames[col].sqlname; + if (!n) + db_fatal("Unknown column name %s in query %s", + colname, stmt->query->query); + if (streq(n, colname)) + break; col = (col + 1) % stmt->query->num_colnames; }