Skip to content

Commit 1ecad0c

Browse files
cdeckerniftynei
authored andcommitted
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.
1 parent 712595f commit 1ecad0c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

wallet/db.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,10 @@ bool db_step(struct db_stmt *stmt)
562562

563563
u64 db_column_u64(struct db_stmt *stmt, int col)
564564
{
565-
assert(!db_column_is_null(stmt, col));
565+
if (db_column_is_null(stmt, col)) {
566+
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
567+
return 0;
568+
}
566569
return stmt->db->config->column_u64_fn(stmt, col);
567570
}
568571

@@ -576,13 +579,19 @@ int db_column_int_or_default(struct db_stmt *stmt, int col, int def)
576579

577580
int db_column_int(struct db_stmt *stmt, int col)
578581
{
579-
assert(!db_column_is_null(stmt, col));
582+
if (db_column_is_null(stmt, col)) {
583+
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
584+
return 0;
585+
}
580586
return stmt->db->config->column_int_fn(stmt, col);
581587
}
582588

583589
size_t db_column_bytes(struct db_stmt *stmt, int col)
584590
{
585-
assert(!db_column_is_null(stmt, col));
591+
if (db_column_is_null(stmt, col)) {
592+
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
593+
return 0;
594+
}
586595
return stmt->db->config->column_bytes_fn(stmt, col);
587596
}
588597

@@ -593,13 +602,19 @@ int db_column_is_null(struct db_stmt *stmt, int col)
593602

594603
const void *db_column_blob(struct db_stmt *stmt, int col)
595604
{
596-
assert(!db_column_is_null(stmt, col));
605+
if (db_column_is_null(stmt, col)) {
606+
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
607+
return NULL;
608+
}
597609
return stmt->db->config->column_blob_fn(stmt, col);
598610
}
599611

600612
const unsigned char *db_column_text(struct db_stmt *stmt, int col)
601613
{
602-
assert(!db_column_is_null(stmt, col));
614+
if (db_column_is_null(stmt, col)) {
615+
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
616+
return NULL;
617+
}
603618
return stmt->db->config->column_text_fn(stmt, col);
604619
}
605620

0 commit comments

Comments
 (0)