This addresses an issue in the House::resetTransferItem function where the transferItem pointer was being set to nullptr before being used later in the function, leading to potential undefined behavior or crashes. The solution involves reordering the operations to ensure that transferItem is only set to nullptr after all required operations are completed. This change ensures that the object remains accessible until all necessary manipulations are performed.
When transferItem is set to nullptr before the removal of the item, attempting to use the tmpItem reference leads to undefined behavior or a crash because the reference is pointing to a nullptr.
Expected
transferItem should only be set to nullptr after tmpItem is fully utilized to remove the item from transfer_container. This avoids dereferencing a nullptr and ensures that operations on the item are safe.
Type of change
[x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested
The change was tested by:
Validating that the resetTransferItem function works without setting transferItem to nullptr before necessary operations are performed.
Running the server under conditions that would trigger the resetTransferItem function to ensure there are no crashes or unexpected behavior.
Adding logs to verify that tmpItem retains its value correctly until all actions are completed.
[x] Test A: Triggered resetTransferItem to confirm correct handling of the item reference without setting transferItem to nullptr prematurely.
[x] Test B: Stress-tested the scenario where multiple items are transferred in quick succession to validate stability.
Checklist
[x] My code follows the style guidelines of this project
[x] I have performed a self-review of my own code
[x] I checked the PR checks reports
[x] I have commented my code, particularly in hard-to-understand areas
[x] I have made corresponding changes to the documentation
[x] My changes generate no new warnings
[x] I have added tests that prove my fix is effective or that my feature works
Description
This addresses an issue in the
House::resetTransferItem
function where thetransferItem
pointer was being set tonullptr
before being used later in the function, leading to potential undefined behavior or crashes. The solution involves reordering the operations to ensure thattransferItem
is only set tonullptr
after all required operations are completed. This change ensures that the object remains accessible until all necessary manipulations are performed.Fixes this crash: crash house.txt
Behaviour
Actual
When
transferItem
is set tonullptr
before the removal of the item, attempting to use thetmpItem
reference leads to undefined behavior or a crash because the reference is pointing to anullptr
.Expected
transferItem
should only be set tonullptr
aftertmpItem
is fully utilized to remove the item fromtransfer_container
. This avoids dereferencing anullptr
and ensures that operations on the item are safe.Type of change
How Has This Been Tested
The change was tested by:
Validating that the
resetTransferItem
function works without settingtransferItem
tonullptr
before necessary operations are performed.Running the server under conditions that would trigger the
resetTransferItem
function to ensure there are no crashes or unexpected behavior.Adding logs to verify that
tmpItem
retains its value correctly until all actions are completed.[x] Test A: Triggered
resetTransferItem
to confirm correct handling of the item reference without settingtransferItem
tonullptr
prematurely.[x] Test B: Stress-tested the scenario where multiple items are transferred in quick succession to validate stability.
Checklist