From 51b1e2dc27441812d7a3006b5d98834c95618e48 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 14 Apr 2015 06:39:21 +0200 Subject: Fix undefined behavior when asking about item to fireproof --- src/q_fireprof.cc | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/q_fireprof.cc') diff --git a/src/q_fireprof.cc b/src/q_fireprof.cc index 4a88965a..dbf26c0b 100644 --- a/src/q_fireprof.cc +++ b/src/q_fireprof.cc @@ -169,30 +169,28 @@ static bool_ fireproof_enough_points(object_type *o_ptr, int *stack) static bool_ fireproof() { - int ret, item, stack = 0; - object_type *obj2 = NULL; - bool_ ret2; + int item; item_tester_hook = item_tester_hook_proofable; - ret = get_item(&item, - "Which item shall I fireproof?", - "You have no more items I can fireproof, come back when you have some.", - USE_INVEN); + if (!get_item(&item, + "Which item shall I fireproof?", + "You have no more items I can fireproof, come back when you have some.", + USE_INVEN)) + { + return FALSE; + } /* get the object type from the number */ - obj2 = get_object(item); + object_type *obj2 = get_object(item); /* check we have enough points (if we 'got' an item) */ - if (ret == TRUE) { - ret2 = fireproof_enough_points(obj2, &stack); - } - - /* did either routine fail? */ - if ((ret == FALSE) || (ret2 == FALSE)) + int stack = 0; + if (!fireproof_enough_points(obj2, &stack)) { return FALSE; } - else + + /* Do the actual fireproofing */ { bool_ carry_it; object_type *obj3; -- cgit v1.2.3