Browse Source

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.
ppa-0.6.1
ZmnSCPxj 7 years ago
committed by Christian Decker
parent
commit
7b6a16a3a6
  1. 4
      wallet/invoices.c

4
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. */

Loading…
Cancel
Save