Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,14 @@ static bool get_room_above_reserve(const struct channel *channel,
struct amount_msat owed = view->owed[side];

/* `lowest_splice_amnt` will always be negative or 0 */
if (amount_msat_less_eq_sat(owed, amount_sat(-view->lowest_splice_amnt[side]))) {
if (amount_msat_less_eq_sat(owed, amount_sat(-(u64)view->lowest_splice_amnt[side]))) {
status_debug("Relative splice balance invalid");
return false;
}

/* `lowest_splice_amnt` is a relative amount */
if (!amount_msat_sub_sat(&owed, owed,
amount_sat(-view->lowest_splice_amnt[side]))) {
amount_sat(-(u64)view->lowest_splice_amnt[side]))) {
status_debug("Owed amount should not wrap around from splice");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions common/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ WARN_UNUSED_RESULT bool amount_msat_add_sat_s64(struct amount_msat *val,
s64 b)
{
if (b < 0)
return amount_msat_sub_sat(val, a, amount_sat(-b));
return amount_msat_sub_sat(val, a, amount_sat(-(u64)b));
else
return amount_msat_add_sat(val, a, amount_sat(b));
}
Expand All @@ -413,7 +413,7 @@ WARN_UNUSED_RESULT bool amount_sat_add_sat_s64(struct amount_sat *val,
s64 b)
{
if (b < 0)
return amount_sat_sub(val, a, amount_sat(-b));
return amount_sat_sub(val, a, amount_sat(-(u64)b));
else
return amount_sat_add(val, a, amount_sat(b));
}
Expand Down
11 changes: 11 additions & 0 deletions common/test/run-amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,17 @@ int main(int argc, char *argv[])
assert(sat.satoshis == i);
}

/* Negating INT64_MIN as a signed value overflows. */
sat.satoshis = UINT64_MAX;
assert(amount_sat_add_sat_s64(&sat, sat, INT64_MIN));
assert(sat.satoshis == UINT64_MAX - (1ULL << 63));
assert(!amount_sat_add_sat_s64(&sat, AMOUNT_SAT(5), INT64_MIN));
assert(amount_sat_add_sat_s64(&sat, AMOUNT_SAT(5), -5));
assert(amount_sat_is_zero(sat));
assert(!amount_msat_add_sat_s64(&msat, AMOUNT_MSAT(UINT64_MAX), INT64_MIN));
assert(amount_msat_add_sat_s64(&msat, AMOUNT_MSAT(5000), -5));
assert(amount_msat_is_zero(msat));

test_amount_with_fee();
test_amount_div();
common_shutdown();
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -7258,7 +7258,7 @@ static void db_col_credit_or_debit(struct db_stmt *stmt,
s64 amount = db_col_s64(stmt, colname);
if (amount < 0) {
*credit = AMOUNT_MSAT(0);
*debit = amount_msat(-amount);
*debit = amount_msat(-(u64)amount);
} else {
*credit = amount_msat(amount);
*debit = AMOUNT_MSAT(0);
Expand Down
Loading