From 1ecad0cc537d560b7444741b71ca3e5a87295f05 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 20 Oct 2019 22:39:41 +0200 Subject: [PATCH] db: Maybe a bit too pedantic? Checking on whether we access a null field is ok, but should we crash right away? Probably not. This reduces the access to a warning on sqlite3 and let's it continue. We can look for occurences and fix them as they come up and then re-arm the asserts once we addressed all cases. --- wallet/db.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index 91745b604..a1264066b 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -562,7 +562,10 @@ bool db_step(struct db_stmt *stmt) u64 db_column_u64(struct db_stmt *stmt, int col) { - assert(!db_column_is_null(stmt, col)); + if (db_column_is_null(stmt, col)) { + log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query); + return 0; + } return stmt->db->config->column_u64_fn(stmt, col); } @@ -576,13 +579,19 @@ int db_column_int_or_default(struct db_stmt *stmt, int col, int def) int db_column_int(struct db_stmt *stmt, int col) { - assert(!db_column_is_null(stmt, col)); + if (db_column_is_null(stmt, col)) { + log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query); + return 0; + } return stmt->db->config->column_int_fn(stmt, col); } size_t db_column_bytes(struct db_stmt *stmt, int col) { - assert(!db_column_is_null(stmt, col)); + if (db_column_is_null(stmt, col)) { + log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query); + return 0; + } return stmt->db->config->column_bytes_fn(stmt, col); } @@ -593,13 +602,19 @@ int db_column_is_null(struct db_stmt *stmt, int col) const void *db_column_blob(struct db_stmt *stmt, int col) { - assert(!db_column_is_null(stmt, col)); + if (db_column_is_null(stmt, col)) { + log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query); + return NULL; + } return stmt->db->config->column_blob_fn(stmt, col); } const unsigned char *db_column_text(struct db_stmt *stmt, int col) { - assert(!db_column_is_null(stmt, col)); + if (db_column_is_null(stmt, col)) { + log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query); + return NULL; + } return stmt->db->config->column_text_fn(stmt, col); }