OSDN Git Service

[Fix] #37856 不正なモンスターのステータスを参照した際に発生し得るゼロ除算を回避。 / Avoid div 0 error on viewing status...
authorDeskull <deskull@users.sourceforge.jp>
Sun, 23 Dec 2018 00:26:55 +0000 (09:26 +0900)
committerDeskull <deskull@users.sourceforge.jp>
Sun, 23 Dec 2018 00:26:55 +0000 (09:26 +0900)
src/monster-process.c
src/monster2.c
src/xtra1.c
src/xtra2.c

index 5117265..6f22a8a 100644 (file)
@@ -2101,10 +2101,8 @@ void process_monster(MONSTER_IDX m_idx)
        bool            aware = TRUE;
 
        bool fear, dead;
-
-       bool            is_riding_mon = (m_idx == p_ptr->riding);
-
-       bool            see_m = is_seen(m_ptr);
+       bool is_riding_mon = (m_idx == p_ptr->riding);
+       bool see_m = is_seen(m_ptr);
 
        if (is_riding_mon && !(r_ptr->flags7 & RF7_RIDING))
        {
@@ -2132,7 +2130,7 @@ void process_monster(MONSTER_IDX m_idx)
                int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
                if (p_ptr->monlite) tmp /= 3;
                if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
-               if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
+               if (r_ptr->level > (p_ptr->lev * p_ptr->lev / 20 + 10)) tmp /= 3;
                /* Low-level monsters will find it difficult to locate the player. */
                if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
        }
@@ -2152,12 +2150,10 @@ void process_monster(MONSTER_IDX m_idx)
                if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
                {
                        char m_name[80];
-
                        monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
                        do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
                }
 
-
                delete_monster_idx(m_idx);
 
                return;
@@ -2187,7 +2183,6 @@ void process_monster(MONSTER_IDX m_idx)
                        /* Generate treasure, etc */
                        monster_death(m_idx, FALSE);
 
-
                        delete_monster_idx(m_idx);
                        if (sad)
                        {
@@ -2267,8 +2262,6 @@ void process_monster(MONSTER_IDX m_idx)
                /* Handle non-aggravation - Still sleeping */
                if (!(p_ptr->cursed & TRC_AGGRAVATE)) return;
 
-               /* Handle aggravation */
-
                /* Reset sleep counter */
                (void)set_monster_csleep(m_idx, 0);
 
@@ -2304,8 +2297,7 @@ void process_monster(MONSTER_IDX m_idx)
                gets_angry = TRUE;
 
        /* Paranoia... no pet uniques outside wizard mode -- TY */
-       if (is_pet(m_ptr) &&
-           ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
+       if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
              monster_has_hostile_align(NULL, 10, -10, r_ptr))
             || (r_ptr->flagsr & RFR_RES_ALL)))
        {
@@ -2330,11 +2322,11 @@ void process_monster(MONSTER_IDX m_idx)
        oy = m_ptr->fy;
        ox = m_ptr->fx;
 
-
        /* Attempt to "multiply" if able and allowed */
        if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
        {
-               int k, y, x;
+               int k;
+               POSITION y, x;
 
                /* Count the adjacent monsters */
                for (k = 0, y = oy - 1; y <= oy + 1; y++)
@@ -2369,7 +2361,6 @@ void process_monster(MONSTER_IDX m_idx)
                }
        }
 
-
        if (r_ptr->a_ability_flags2 & RF6_SPECIAL)
        {
                /* Hack -- Ohmu scatters molds! */
@@ -2397,7 +2388,6 @@ void process_monster(MONSTER_IDX m_idx)
                }
        }
 
-
        if (!p_ptr->inside_battle)
        {
                /* Hack! "Cyber" monster makes noise... */
@@ -2542,8 +2532,7 @@ void process_monster(MONSTER_IDX m_idx)
        else if (is_pet(m_ptr))
        {
                /* Are we trying to avoid the player? */
-               bool avoid = ((p_ptr->pet_follow_distance < 0) &&
-                                                 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
+               bool avoid = ((p_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
 
                /* Do we want to find the player? */
                bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
@@ -2609,7 +2598,6 @@ void process_monster(MONSTER_IDX m_idx)
        did_pass_wall = FALSE;
        did_kill_wall = FALSE;
 
-
        /* Take a zero-terminated array of "directions" */
        for (i = 0; mm[i]; i++)
        {
index 453a72e..b0fab2a 100644 (file)
@@ -251,7 +251,6 @@ void delete_monster_idx(MONSTER_IDX i)
        if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(i, 0);
        if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(i, 0, FALSE);
 
-
        /* Hack -- remove target monster */
        if (i == target_who) target_who = 0;
 
index fca9512..5797b2d 100644 (file)
@@ -1539,8 +1539,8 @@ static void health_redraw(bool riding)
                else
                {
                        /* Extract the "percent" of health */
-                       int pct = 100L * m_ptr->hp / m_ptr->maxhp;
-                       int pct2 = 100L * m_ptr->hp / m_ptr->max_maxhp;
+                       int pct = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
+                       int pct2 = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->max_maxhp: 0;
 
                        /* Convert percent into "health" */
                        int len = (pct2 < 10) ? 1 : (pct2 < 90) ? (pct2 / 10 + 1) : 10;
index a44e1ba..c445daf 100644 (file)
@@ -2060,7 +2060,7 @@ cptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
        living = monster_living(m_ptr->ap_r_idx);
 
        /* Calculate a health "percentage" */
-       perc = 100L * m_ptr->hp / m_ptr->maxhp;
+       perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
 
        /* Healthy monsters */
        if (m_ptr->hp >= m_ptr->maxhp)