From 5661f1c49a9de3caad60d9824170e8fa2f62b6fe Mon Sep 17 00:00:00 2001 From: inogenous <123803852+inogenous@users.noreply.github.com> Date: Wed, 22 May 2024 21:50:35 +0200 Subject: [PATCH] Bugfix: Prevent segfault when butcher target disappears (#73990) Stops butchering when the butcher target corpse has been either raised or moved. Prevents segfault caused by dereferencing an invalid `item_location`. --- src/activity_handlers.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index 05db524e634cc..fb00061fc7e31 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -477,7 +477,12 @@ void activity_handlers::butcher_do_turn( player_activity *act, Character * ) const butcher_type action = get_butcher_type( act ); const double progress = static_cast( act->moves_total - act->moves_left ) / act->moves_total; - item &corpse_item = *act->targets.back(); + item_location target = act->targets.back(); + if( !target || !target->is_corpse() ) { + act->set_to_null(); + return; + } + item &corpse_item = *target; corpse_item.set_var( butcher_progress_var( action ), progress ); }