From 362be87e05b6d4f61cf7c24eab797458715f9057 Mon Sep 17 00:00:00 2001 From: AMS21 Date: Thu, 26 Oct 2023 21:07:19 +0200 Subject: [PATCH] xrGame: Fix logic error in `TransferMoney` Since both values are unsigned subtracting them from another will never produce a negative value. This bug was also present before the previous commit since the `money` variable was implicitly converted to an `u32` resulting in the same bug. --- src/xrGame/script_game_object_inventory_owner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xrGame/script_game_object_inventory_owner.cpp b/src/xrGame/script_game_object_inventory_owner.cpp index 52f14a171b0..db2b8852ce6 100644 --- a/src/xrGame/script_game_object_inventory_owner.cpp +++ b/src/xrGame/script_game_object_inventory_owner.cpp @@ -486,7 +486,7 @@ void CScriptGameObject::TransferMoney(u32 money, CScriptGameObject* pForWho) CInventoryOwner* pOtherOwner = smart_cast(&pForWho->object()); VERIFY(pOtherOwner); - if (pOurOwner->get_money() - money < 0) + if (pOurOwner->get_money() < money) { GEnv.ScriptEngine->script_log(LuaMessageType::Error, "Character does not have enought money"); return;