Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.Test A: Triggered
resetTransferItem
to confirm correct handling of the item reference without settingtransferItem
tonullptr
prematurely.Test B: Stress-tested the scenario where multiple items are transferred in quick succession to validate stability.
Checklist