From b1cbd5acf90d558153582cce64c39d88d2749362 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 22 Jul 2026 09:18:54 +0300 Subject: [PATCH] topo_node_sqlite: dynamic idx_sql allocation instead of fixed 128-byte buffer --- src/routing_layer/topo_node_sqlite.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/routing_layer/topo_node_sqlite.c b/src/routing_layer/topo_node_sqlite.c index d5096730..30531f8e 100644 --- a/src/routing_layer/topo_node_sqlite.c +++ b/src/routing_layer/topo_node_sqlite.c @@ -278,10 +278,15 @@ int topo_node_sqlite_channel_put(sqlite3* db, const char* channel_id, u_free(ddl); } - char idx_sql[128]; - snprintf(idx_sql, sizeof(idx_sql), + int idx_sz = snprintf(NULL, 0, "CREATE INDEX IF NOT EXISTS \"idx_%s_type_rtt\" ON \"%s\" (node_type, node_RTT)", peers_tbl, peers_tbl); - sqlite3_exec(db, idx_sql, NULL, NULL, NULL); + char* idx_sql = u_malloc(idx_sz + 1); + if (idx_sql) { + snprintf(idx_sql, idx_sz + 1, + "CREATE INDEX IF NOT EXISTS \"idx_%s_type_rtt\" ON \"%s\" (node_type, node_RTT)", peers_tbl, peers_tbl); + sqlite3_exec(db, idx_sql, NULL, NULL, NULL); + u_free(idx_sql); + } sqlite3_stmt* stmt = NULL; if (sqlite3_prepare_v2(db,