From 2419641cd094fabcfbddd2c976b7aa99a7cb01ba Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Tue, 10 Jan 2023 22:21:38 -0800 Subject: [PATCH] :bug: fixed unsigned underflow when negative --- src/bank.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bank.cpp b/src/bank.cpp index ff5e770..7f32913 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -179,7 +179,6 @@ bool Bank::VerifyPassword(const std::string &name, const std::string_view &attem Bank::users.if_contains(name, [&res, &attempt](const User &u) { res = (u.password == xxHashStringGen{}(attempt)); }); return res; } - void Bank::ChangePassword(const std::string &name, const std::string &new_pass) noexcept { SET_CHANGES_ON; @@ -211,7 +210,7 @@ BankResponse Bank::ImpactBal(const std::string &name, int64_t amount) noexcept } uint32_t bal; if (ValidUsername(name) && Bank::users.modify_if(name, [&bal, &amount](User &u) { - if (u.balance < (amount * -1)) { amount = -u.balance; }; + if (u.balance < (amount * -1)) { amount = -int64_t(u.balance); }; bal = u.balance += amount; #if MAX_LOG_SIZE > 0 u.log.AddTrans("Ω", (amount > 0), std::abs(amount), time(NULL));