mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
db: Make column access way more pedantic
We should never access a nulled field, so add an assert to that effect.
This commit is contained in:
parent
12f40f2227
commit
ec8d774b29
2 changed files with 9 additions and 2 deletions
|
@ -562,6 +562,7 @@ bool db_step(struct db_stmt *stmt)
|
||||||
|
|
||||||
u64 db_column_u64(struct db_stmt *stmt, int col)
|
u64 db_column_u64(struct db_stmt *stmt, int col)
|
||||||
{
|
{
|
||||||
|
assert(!db_column_is_null(stmt, col));
|
||||||
return stmt->db->config->column_u64_fn(stmt, col);
|
return stmt->db->config->column_u64_fn(stmt, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,11 +576,13 @@ int db_column_int_or_default(struct db_stmt *stmt, int col, int def)
|
||||||
|
|
||||||
int db_column_int(struct db_stmt *stmt, int col)
|
int db_column_int(struct db_stmt *stmt, int col)
|
||||||
{
|
{
|
||||||
|
assert(!db_column_is_null(stmt, col));
|
||||||
return stmt->db->config->column_int_fn(stmt, col);
|
return stmt->db->config->column_int_fn(stmt, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t db_column_bytes(struct db_stmt *stmt, int col)
|
size_t db_column_bytes(struct db_stmt *stmt, int col)
|
||||||
{
|
{
|
||||||
|
assert(!db_column_is_null(stmt, col));
|
||||||
return stmt->db->config->column_bytes_fn(stmt, col);
|
return stmt->db->config->column_bytes_fn(stmt, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,11 +593,13 @@ int db_column_is_null(struct db_stmt *stmt, int col)
|
||||||
|
|
||||||
const void *db_column_blob(struct db_stmt *stmt, int col)
|
const void *db_column_blob(struct db_stmt *stmt, int col)
|
||||||
{
|
{
|
||||||
|
assert(!db_column_is_null(stmt, col));
|
||||||
return stmt->db->config->column_blob_fn(stmt, col);
|
return stmt->db->config->column_blob_fn(stmt, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char *db_column_text(struct db_stmt *stmt, int col)
|
const unsigned char *db_column_text(struct db_stmt *stmt, int col)
|
||||||
{
|
{
|
||||||
|
assert(!db_column_is_null(stmt, col));
|
||||||
return stmt->db->config->column_text_fn(stmt, col);
|
return stmt->db->config->column_text_fn(stmt, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1136,12 +1141,14 @@ struct bitcoin_tx *db_column_tx(const tal_t *ctx, struct db_stmt *stmt, int col)
|
||||||
void *db_column_arr_(const tal_t *ctx, struct db_stmt *stmt, int col,
|
void *db_column_arr_(const tal_t *ctx, struct db_stmt *stmt, int col,
|
||||||
size_t bytes, const char *label, const char *caller)
|
size_t bytes, const char *label, const char *caller)
|
||||||
{
|
{
|
||||||
size_t sourcelen = db_column_bytes(stmt, col);
|
size_t sourcelen;
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (db_column_is_null(stmt, col))
|
if (db_column_is_null(stmt, col))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
sourcelen = db_column_bytes(stmt, col);
|
||||||
|
|
||||||
if (sourcelen % bytes != 0)
|
if (sourcelen % bytes != 0)
|
||||||
db_fatal("%s: column size %zu not a multiple of %s (%zu)",
|
db_fatal("%s: column size %zu not a multiple of %s (%zu)",
|
||||||
caller, sourcelen, label, bytes);
|
caller, sourcelen, label, bytes);
|
||||||
|
|
|
@ -1790,7 +1790,7 @@ static bool wallet_stmt2htlc_out(struct channel *channel,
|
||||||
sizeof(out->onion_routing_packet));
|
sizeof(out->onion_routing_packet));
|
||||||
|
|
||||||
out->failuremsg = db_column_arr(out, stmt, 8, u8);
|
out->failuremsg = db_column_arr(out, stmt, 8, u8);
|
||||||
out->failcode = db_column_int(stmt, 9);
|
out->failcode = db_column_int_or_default(stmt, 9, 0);
|
||||||
|
|
||||||
if (!db_column_is_null(stmt, 10)) {
|
if (!db_column_is_null(stmt, 10)) {
|
||||||
out->origin_htlc_id = db_column_u64(stmt, 10);
|
out->origin_htlc_id = db_column_u64(stmt, 10);
|
||||||
|
|
Loading…
Add table
Reference in a new issue