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,