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,15 +1362,17 @@ int _obj_use_item_on(Object* a1, Object* a2, Object* a3)
int flags = a3->flags & OBJECT_IN_ANY_HAND; int flags = a3->flags & OBJECT_IN_ANY_HAND;
itemRemove(a1, a3, 1); itemRemove(a1, a3, 1);
Object* v7 = itemReplace(a1, a3, flags); Object* replacedItem = itemReplace(a1, a3, flags);
// 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 leftItemAction;
int rightItemAction; int rightItemAction;
if (a1 == gDude) {
interfaceGetItemActions(&leftItemAction, &rightItemAction); interfaceGetItemActions(&leftItemAction, &rightItemAction);
}
if (v7 == NULL) { if (replacedItem == NULL) {
if ((flags & OBJECT_IN_LEFT_HAND) != 0) { if ((flags & OBJECT_IN_LEFT_HAND) != 0) {
leftItemAction = INTERFACE_ITEM_ACTION_DEFAULT; leftItemAction = INTERFACE_ITEM_ACTION_DEFAULT;
} else if ((flags & OBJECT_IN_RIGHT_HAND) != 0) { } else if ((flags & OBJECT_IN_RIGHT_HAND) != 0) {
@ -1383,6 +1385,7 @@ int _obj_use_item_on(Object* a1, Object* a2, Object* a3)
interfaceUpdateItems(false, leftItemAction, rightItemAction); interfaceUpdateItems(false, leftItemAction, rightItemAction);
} }
}
_obj_destroy(a3); _obj_destroy(a3);