Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset item pointer after wielding item currently being invoked. #33405

Merged
merged 3 commits into from
Aug 20, 2019

Conversation

BevapDin
Copy link
Contributor

SUMMARY: None

See commit messages. In short the iuse function did wield the item, but that invalidates the it pointer (which may be an item in the main inventory, which is not there anymore after wielded it).

Fixes #32009 and fixes #33398.

If the item has been wielded, the pointer `ìt` (the item previously, e.g. in the inventory or on the ground) is now invalid.
The check at the top of the function makes sure `it` is actually a pointer to the wielded weapon, so using either is the same.

This change just makes the code more consistent: it uses `it` like in all the other iuse functions. And `it` is already used at one place to get the recipe anyway.
At least one iuse function (`iuse::craft` when the item was not wielded) removes the item. Accessing it afterwards is UB.

(Search for `p->i_rem( it )` in "iuse.cpp" to find those places.)
@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Items / Item Actions / Item Qualities Items and how they work and interact <Bugfix> This is a fix for a bug (or closes open issue) labels Aug 20, 2019
@ZhilkinSerg ZhilkinSerg merged commit 46fbee2 into CleverRaven:master Aug 20, 2019
@BevapDin BevapDin deleted the jbn branch August 20, 2019 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Items / Item Actions / Item Qualities Items and how they work and interact
Projects
None yet
2 participants