Fix crash in obj_use_item_on

This commit is contained in:
Alexander Batalov 2022-10-05 17:55:54 +03:00
parent 08691ce319
commit a4e9123bcc
1 changed files with 17 additions and 14 deletions

View File

@ -1362,26 +1362,29 @@ int _obj_use_item_on(Object* a1, Object* a2, Object* a3)
int flags = a3->flags & OBJECT_IN_ANY_HAND;
itemRemove(a1, a3, 1);
Object* v7 = itemReplace(a1, a3, flags);
Object* replacedItem = itemReplace(a1, a3, flags);
int leftItemAction;
int rightItemAction;
// CE: Fix rare crash when using uninitialized action variables. The
// following code is on par with |_obj_use_item| which does not
// crash.
if (a1 == gDude) {
int leftItemAction;
int rightItemAction;
interfaceGetItemActions(&leftItemAction, &rightItemAction);
}
if (v7 == NULL) {
if ((flags & OBJECT_IN_LEFT_HAND) != 0) {
leftItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
} else if ((flags & OBJECT_IN_RIGHT_HAND) != 0) {
rightItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
} else {
leftItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
rightItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
if (replacedItem == NULL) {
if ((flags & OBJECT_IN_LEFT_HAND) != 0) {
leftItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
} else if ((flags & OBJECT_IN_RIGHT_HAND) != 0) {
rightItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
} else {
leftItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
rightItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
}
}
}
interfaceUpdateItems(false, leftItemAction, rightItemAction);
interfaceUpdateItems(false, leftItemAction, rightItemAction);
}
}
_obj_destroy(a3);