From b4f0929280984fdfe3ff32e5a4abc780cd19b69b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 22 Jul 2023 16:42:57 +0930 Subject: [PATCH] db/bindings: allow db_col_short_channel_id_arr and db_col_node_id_arr on null columns The other _arr helpers allow this, and we want it for the next patch. Signed-off-by: Rusty Russell --- db/bindings.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/db/bindings.c b/db/bindings.c index 4274d07a9..aa9795161 100644 --- a/db/bindings.c +++ b/db/bindings.c @@ -357,17 +357,22 @@ void db_col_node_id(struct db_stmt *stmt, const char *colname, struct node_id *d memcpy(dest->k, db_column_blob(stmt, col), sizeof(dest->k)); } +/* We don't assume sizeof(struct node_id) == sizeof(struct node_id.k), + * otherwise this would simply be a call to db_col_arr! + * Thanks ARM! */ struct node_id *db_col_node_id_arr(const tal_t *ctx, struct db_stmt *stmt, - const char *colname) + const char *colname) { size_t col = db_query_colnum(stmt, colname); struct node_id *ret; size_t n = db_column_bytes(stmt, col) / sizeof(ret->k); const u8 *arr = db_column_blob(stmt, col); assert(n * sizeof(ret->k) == (size_t)db_column_bytes(stmt, col)); - ret = tal_arr(ctx, struct node_id, n); - db_column_null_warn(stmt, colname, col); + if (db_column_is_null(stmt, col)) + return NULL; + + ret = tal_arr(ctx, struct node_id, n); for (size_t i = 0; i < n; i++) memcpy(ret[i].k, arr + i * sizeof(ret[i].k), sizeof(ret[i].k)); @@ -410,7 +415,9 @@ db_col_short_channel_id_arr(const tal_t *ctx, struct db_stmt *stmt, const char * size_t len; struct short_channel_id *ret; - db_column_null_warn(stmt, colname, col); + if (db_column_is_null(stmt, col)) + return NULL; + ser = db_column_blob(stmt, col); len = db_column_bytes(stmt, col); ret = tal_arr(ctx, struct short_channel_id, 0);