From 6113bc214412cd0d48451ac8759f6d8bd8ebd859 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 29 Oct 2015 16:46:43 +0100 Subject: [PATCH] CID 26254: Incorrect expression (DIVIDE_BY_ZERO) magic should never be zero, but coverity doesn't know that. --- src/magic.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/magic.c b/src/magic.c index 4d801e7ff..52d85f435 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1281,19 +1281,20 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade) * 20% Warscheinlichkeit nicht * */ - int rnd = 0; - double x = (double)cast_grade / (double)effskill(u, SK_MAGIC, r); - int fumble_chance = (int)(((double)x * 40.0) - 20.0); + int fumble_chance, rnd = 0; + int effsk = effskill(u, SK_MAGIC, r); struct building *b = inside_building(u); const struct building_type *btype = b ? b->type : NULL; int fumble_enabled = get_param_int(global.parameters, "magic.fumble.enable", 1); sc_mage * mage; - if (!fumble_enabled) { + if (effsk<=0 || !fumble_enabled) { return false; } - if (btype) + fumble_chance = (int)((cast_grade * 40.0 / (double)effsk) - 20.0); + if (btype) { fumble_chance -= btype->fumblebonus; + } /* CHAOSPATZERCHANCE 10 : +10% Chance zu Patzern */ mage = get_mage(u);