From a4ed07f731f2f83657f75695cc9e589123718a07 Mon Sep 17 00:00:00 2001 From: RenechCDDA <84619419+RenechCDDA@users.noreply.github.com> Date: Sun, 3 Nov 2024 07:16:40 -0500 Subject: [PATCH] Check for nullptr before calling --- src/item.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 8a22634264113..b957b59dd4dc4 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -8673,8 +8673,9 @@ bool item::made_of_any_food_components( bool deep_search ) const for( const std::pair> pair : components ) { for( const item &it : pair.second ) { - nutrients &maybe_food = it.get_comestible()->default_nutrition; - bool must_be_food = maybe_food.kcal() > 0 || maybe_food.vitamins().empty(); + const auto &maybe_food = it.get_comestible(); + bool must_be_food = maybe_food && ( maybe_food->default_nutrition.kcal() > 0 || + !maybe_food->default_nutrition.vitamins().empty() ); bool has_food_component = false; if( deep_search && !it.components.empty() ) { // make true if any component has food values, even if some don't