From 7b6a16a3a644f7d5579ba470ee7c519926563161 Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Thu, 18 Jan 2018 12:41:30 +0000 Subject: [PATCH] invoices: Do not load `pay_index` if not PAID. `pay_index` has no valid value if not PAID anyway, so we should correctly leave it uninitialized. Analysis via valgrind will catch incorrect use of uninitialized fields. If we load it with a dummy 0 value, then an incorrect use of `pay_index` whan invoice is not PAID will not get caught by valgrind. --- wallet/invoices.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/wallet/invoices.c b/wallet/invoices.c index 86e2088a0..cef555102 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -58,10 +58,9 @@ static bool wallet_stmt2invoice(sqlite3_stmt *stmt, struct invoice *inv) } inv->expiry_time = sqlite3_column_int64(stmt, 6); - /* Correctly 0 if pay_index is NULL. */ - inv->pay_index = sqlite3_column_int64(stmt, 7); if (inv->state == PAID) { + inv->pay_index = sqlite3_column_int64(stmt, 7); inv->msatoshi_received = sqlite3_column_int64(stmt, 8); inv->paid_timestamp = sqlite3_column_int64(stmt, 9); } @@ -181,7 +180,6 @@ const struct invoice *invoices_create(struct invoices *invoices, memcpy(&invoice->r, &r, sizeof(invoice->r)); memcpy(&invoice->rhash, &rhash, sizeof(invoice->rhash)); invoice->expiry_time = expiry_time; - invoice->pay_index = 0; list_head_init(&invoice->waitone_waiters); /* Add to invoices object. */