OSDN Git Service

[cleanup] GCCの警告に対応
authorHabu <habu@users.sourceforge.jp>
Thu, 3 Dec 2020 14:06:36 +0000 (23:06 +0900)
committerHabu <habu@users.sourceforge.jp>
Thu, 3 Dec 2020 14:07:28 +0000 (23:07 +0900)
GCCによる警告に対応した修正を行う。
GCCのバージョン:GCC 10.2.0
警告関連オプション:-Wall -Wno-switch -Wno-format-overflow

 - 未使用変数の削除
 - 代入のみで使用していない変数の削除
 - 条件式における&&と||の組み合わせに対し()を付けて優先順位を明確にする
 - .cファイルでの #pragma once を削除
 - if文の連続は{}を付けてifに対応するelseを明確にする
 - 変数の使いまわしによる型の不一致を避ける
 - 未使用の引数は(void)にキャストする文でVisual Studioでの警告を避ける
 - term_exchange()はstaticではなく外部に公開する

15 files changed:
src/artifact/fixed-art-generator.c
src/cmd-item/cmd-smith.c
src/inventory/item-getter.c
src/knowledge/knowledge-uniques.c
src/main-gcu.c
src/main-x11.c
src/market/bounty-prize-table.c
src/melee/melee-spell-util.c
src/monster-attack/monster-attack-player.c
src/mspell/mspell-attack.c
src/player/patron.c
src/player/player-status-resist.c
src/player/player-status.c
src/term/z-term.c
src/term/z-term.h

index 3364ded..797b69e 100644 (file)
@@ -123,11 +123,12 @@ static void random_artifact_resistance(player_type *player_ptr, object_type *o_p
     if (a_ptr->gen_flags & TRG_XTRA_H_RES)
         give_resistance = TRUE;
 
-    if (a_ptr->gen_flags & TRG_XTRA_RES_OR_POWER)
+    if (a_ptr->gen_flags & TRG_XTRA_RES_OR_POWER) {
         if (one_in_(2))
             give_resistance = TRUE;
         else
             give_power = TRUE;
+    }
 
     if (give_power)
         one_ability(o_ptr);
index 5e6b0a1..3b7b3c2 100644 (file)
@@ -239,7 +239,6 @@ static void drain_essence(player_type *creature_ptr)
     byte marked;
     ITEM_NUMBER number;
     OBJECT_IDX next_o_idx;
-    WEIGHT weight;
 
     for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
         drain_value[i] = 0;
@@ -334,7 +333,6 @@ static void drain_essence(player_type *creature_ptr)
     ix = o_ptr->ix;
     next_o_idx = o_ptr->next_o_idx;
     marked = o_ptr->marked;
-    weight = o_ptr->weight;
     number = o_ptr->number;
 
     object_prep(creature_ptr, o_ptr, o_ptr->k_idx);
index c7b3580..9d75809 100644 (file)
@@ -467,7 +467,8 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
                         continue;
 
                     item_selection_ptr->k = 0 - item_selection_ptr->this_o_idx;
-                    if (other_query_flag && !verify(owner_ptr, _("本当に", "Try"), item_selection_ptr->k) || !get_item_allow(owner_ptr, item_selection_ptr->k))
+                    if ((other_query_flag && !verify(owner_ptr, _("本当に", "Try"), item_selection_ptr->k))
+                        || !get_item_allow(owner_ptr, item_selection_ptr->k))
                         continue;
 
                     *item_selection_ptr->cp = item_selection_ptr->k;
index 0a932f5..4bbbd20 100644 (file)
@@ -122,10 +122,6 @@ static void display_uniques(unique_list_type *unique_list_ptr, FILE *fff)
  */
 void do_cmd_knowledge_uniques(player_type *creature_ptr, bool is_alive)
 {
-    int n_alive[10];
-    for (IDX i = 0; i < 10; i++)
-        n_alive[i] = 0;
-
     unique_list_type tmp_list;
     unique_list_type *unique_list_ptr = initialize_unique_lsit_type(&tmp_list, is_alive);
     FILE *fff = NULL;
index b965fd0..20ba0bf 100644 (file)
@@ -1036,7 +1036,6 @@ static errr Term_text_gcu(int x, int y, int n, byte a, concptr s)
 {
    term_data *td = (term_data *)(Term->data);
 
-   int i;
    char intext[n];
    char text[80 * 3 + 1];
    size_t inlen = n;
index f677f78..7dabb41 100644 (file)
@@ -1080,7 +1080,7 @@ static void term_string_push(char *buf)
  */
 static void react_keypress(XKeyEvent *xev)
 {
-       int i, n, mc, ms, mo, mx;
+       int n, mc, ms, mo, mx;
        uint ks1;
        XKeyEvent *ev = (XKeyEvent*)(xev);
        KeySym ks;
index 573f006..3d122b9 100644 (file)
@@ -1,6 +1,4 @@
-#pragma once
-
-#include "market/bounty-prize-table.h"
+#include "market/bounty-prize-table.h"
 #include "sv-definition/sv-potion-types.h"
 #include "sv-definition/sv-scroll-types.h"
 
index 10d9709..70dc732 100644 (file)
@@ -14,7 +14,7 @@ melee_spell_type *initialize_melee_spell_type(player_type *target_ptr, melee_spe
     ms_ptr->y = 0;
     ms_ptr->x = 0;
     ms_ptr->target_idx = 0;
-    ms_ptr->thrown_spell;
+    ms_ptr->thrown_spell = 0;
     ms_ptr->dam = 0;
     ms_ptr->num = 0;
     floor_type *floor_ptr = target_ptr->current_floor_ptr;
index f462f5e..94ee4a7 100644 (file)
@@ -391,11 +391,12 @@ static bool process_monster_blows(player_type *target_ptr, monap_type *monap_ptr
         power = mbe_info[monap_ptr->effect].power;
         monap_ptr->ac = target_ptr->ac + target_ptr->to_a;
         if ((monap_ptr->effect == RBE_NONE)
-            || check_hit_from_monster_to_player(target_ptr, power, monap_ptr->rlev, monster_stunned_remaining(monap_ptr->m_ptr)))
+            || check_hit_from_monster_to_player(target_ptr, power, monap_ptr->rlev, monster_stunned_remaining(monap_ptr->m_ptr))) {
             if (!process_monster_attack_hit(target_ptr, monap_ptr))
                 continue;
             else
                 process_monster_attack_evasion(target_ptr, monap_ptr);
+        }
 
         increase_blow_type_seen(target_ptr, monap_ptr);
         check_fall_off_horse(target_ptr, monap_ptr);
index 33faf8a..3d00cfa 100644 (file)
@@ -181,7 +181,7 @@ static bool check_mspell_continuation(player_type *target_ptr, msa_type *msa_ptr
 
     remove_bad_spells(msa_ptr->m_idx, target_ptr, &msa_ptr->f4, &msa_ptr->f5, &msa_ptr->f6);
     check_mspell_arena(target_ptr, msa_ptr);
-    if ((msa_ptr->f4 == 0) && (msa_ptr->f5 == 0) && (msa_ptr->f6 == 0) || !check_mspell_non_stupid(target_ptr, msa_ptr))
+    if (((msa_ptr->f4 == 0) && (msa_ptr->f5 == 0) && (msa_ptr->f6 == 0)) || !check_mspell_non_stupid(target_ptr, msa_ptr))
         return FALSE;
 
     set_mspell_list(msa_ptr);
index 5329862..cafe9fe 100644 (file)
@@ -153,7 +153,6 @@ void gain_level_reward(player_type *creature_ptr, int chosen_reward)
 {
     char wrath_reason[32] = "";
     int nasty_chance = 6;
-    tval_type dummy = 0;
     int type, effect;
     concptr reward = NULL;
     GAME_TEXT o_name[MAX_NLEN];
@@ -343,8 +342,8 @@ void gain_level_reward(player_type *creature_ptr, int chosen_reward)
             msg_print(_("「汝、謙虚たることを学ぶべし!」", "'Thou needst a lesson in humility, mortal!'"));
             msg_print(_("あなたは以前より弱くなった!", "You feel less powerful!"));
 
-            for (dummy = 0; dummy < A_MAX; dummy++) {
-                (void)dec_stat(creature_ptr, dummy, 10 + randint1(15), TRUE);
+            for (base_status_type stat = 0; stat < A_MAX; stat++) {
+                (void)dec_stat(creature_ptr, stat, 10 + randint1(15), TRUE);
             }
             reward = _("全能力値が下がった。", "decreasing all stats");
             break;
@@ -362,8 +361,8 @@ void gain_level_reward(player_type *creature_ptr, int chosen_reward)
 
             msg_print(_("「我がささやかなる賜物を受けとるがよい!」", "'Receive this modest gift from me!'"));
 
-            for (dummy = 0; dummy < A_MAX; dummy++) {
-                (void)do_inc_stat(creature_ptr, dummy);
+            for (base_status_type stat = 0; stat < A_MAX; stat++) {
+                (void)do_inc_stat(creature_ptr, stat);
             }
             reward = _("全能力値が上がった。", "increasing all stats");
             break;
@@ -387,23 +386,25 @@ void gain_level_reward(player_type *creature_ptr, int chosen_reward)
             reward = _("体力が回復した。", "healing");
             break;
 
-        case REW_CURSE_WP:
+        case REW_CURSE_WP: {
+            inventory_slot_type slot;
 
             if (!has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
                 break;
             msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[creature_ptr->chaos_patron]);
             msg_print(_("「汝、武器に頼ることなかれ。」", "'Thou reliest too much on thy weapon.'"));
 
-            dummy = INVEN_RARM;
+            slot = INVEN_RARM;
             if (has_melee_weapon(creature_ptr, INVEN_LARM)) {
-                dummy = INVEN_LARM;
+                slot = INVEN_LARM;
                 if (has_melee_weapon(creature_ptr, INVEN_RARM) && one_in_(2))
-                    dummy = INVEN_RARM;
+                    slot = INVEN_RARM;
             }
-            describe_flavor(creature_ptr, o_name, &creature_ptr->inventory_list[dummy], OD_NAME_ONLY);
-            (void)curse_weapon_object(creature_ptr, FALSE, &creature_ptr->inventory_list[dummy]);
+            describe_flavor(creature_ptr, o_name, &creature_ptr->inventory_list[slot], OD_NAME_ONLY);
+            (void)curse_weapon_object(creature_ptr, FALSE, &creature_ptr->inventory_list[slot]);
             reward = format(_("%sが破壊された。", "destroying %s"), o_name);
             break;
+        }
 
         case REW_CURSE_AR:
 
@@ -433,16 +434,17 @@ void gain_level_reward(player_type *creature_ptr, int chosen_reward)
                 break;
             case 3:
                 if (one_in_(2)) {
+                    inventory_slot_type slot;
                     if (!has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
                         break;
-                    dummy = INVEN_RARM;
+                    slot = INVEN_RARM;
                     if (has_melee_weapon(creature_ptr, INVEN_LARM)) {
-                        dummy = INVEN_LARM;
+                        slot = INVEN_LARM;
                         if (has_melee_weapon(creature_ptr, INVEN_RARM) && one_in_(2))
-                            dummy = INVEN_RARM;
+                            slot = INVEN_RARM;
                     }
-                    describe_flavor(creature_ptr, o_name, &creature_ptr->inventory_list[dummy], OD_NAME_ONLY);
-                    (void)curse_weapon_object(creature_ptr, FALSE, &creature_ptr->inventory_list[dummy]);
+                    describe_flavor(creature_ptr, o_name, &creature_ptr->inventory_list[slot], OD_NAME_ONLY);
+                    (void)curse_weapon_object(creature_ptr, FALSE, &creature_ptr->inventory_list[slot]);
                     reward = format(_("%sが破壊された。", "destroying %s"), o_name);
                 } else {
                     if (!creature_ptr->inventory_list[INVEN_BODY].k_idx)
@@ -453,8 +455,8 @@ void gain_level_reward(player_type *creature_ptr, int chosen_reward)
                 }
                 break;
             default:
-                for (dummy = 0; dummy < A_MAX; dummy++) {
-                    (void)dec_stat(creature_ptr, dummy, 10 + randint1(15), TRUE);
+                for (base_status_type stat = 0; stat < A_MAX; stat++) {
+                    (void)dec_stat(creature_ptr, stat, 10 + randint1(15), TRUE);
                 }
                 reward = _("全能力値が下がった。", "decreasing all stats");
                 break;
@@ -467,23 +469,23 @@ void gain_level_reward(player_type *creature_ptr, int chosen_reward)
             msg_print(_("「死ぬがよい、下僕よ!」", "'Die, mortal!'"));
 
             take_hit(creature_ptr, DAMAGE_LOSELIFE, creature_ptr->lev * 4, wrath_reason, -1);
-            for (dummy = 0; dummy < A_MAX; dummy++) {
-                (void)dec_stat(creature_ptr, dummy, 10 + randint1(15), FALSE);
+            for (base_status_type stat = 0; stat < A_MAX; stat++) {
+                (void)dec_stat(creature_ptr, stat, 10 + randint1(15), FALSE);
             }
             activate_hi_summon(creature_ptr, creature_ptr->y, creature_ptr->x, FALSE);
             (void)activate_ty_curse(creature_ptr, FALSE, &count);
             if (one_in_(2)) {
-                dummy = 0;
+                inventory_slot_type slot = 0;
 
                 if (has_melee_weapon(creature_ptr, INVEN_RARM)) {
-                    dummy = INVEN_RARM;
+                    slot = INVEN_RARM;
                     if (has_melee_weapon(creature_ptr, INVEN_LARM) && one_in_(2))
-                        dummy = INVEN_LARM;
+                        slot = INVEN_LARM;
                 } else if (has_melee_weapon(creature_ptr, INVEN_LARM))
-                    dummy = INVEN_LARM;
+                    slot = INVEN_LARM;
 
-                if (dummy)
-                    (void)curse_weapon_object(creature_ptr, FALSE, &creature_ptr->inventory_list[dummy]);
+                if (slot)
+                    (void)curse_weapon_object(creature_ptr, FALSE, &creature_ptr->inventory_list[slot]);
             }
             if (one_in_(2))
                 (void)curse_armor(creature_ptr);
index c9628a8..ff5f3d8 100644 (file)
@@ -202,7 +202,7 @@ PERCENTAGE calc_nuke_damage_rate(player_type *creature_ptr)
  */
 PERCENTAGE calc_deathray_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
 {
-    (mode); // unused
+    (void)mode; // unused
     if (creature_ptr->mimic_form) {
         if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
             return 0;
@@ -360,7 +360,7 @@ PERCENTAGE calc_nexus_damage_rate(player_type *creature_ptr, rate_calc_type_mode
  */
 PERCENTAGE calc_rocket_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
 {
-    (mode); // unused
+    (void)mode; // unused
     PERCENTAGE per = 100;
 
     if (creature_ptr->resist_shard) {
@@ -393,7 +393,7 @@ PERCENTAGE calc_nether_damage_rate(player_type *creature_ptr, rate_calc_type_mod
  */
 PERCENTAGE calc_time_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
 {
-    (mode); // unused
+    (void)mode; // unused
     PERCENTAGE per = 100;
 
     if (creature_ptr->resist_time) {
@@ -409,7 +409,7 @@ PERCENTAGE calc_time_damage_rate(player_type *creature_ptr, rate_calc_type_mode
  */
 PERCENTAGE calc_holy_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
 {
-    (mode); // unused
+    (void)mode; // unused
     PERCENTAGE per = 100;
     if (creature_ptr->align > 10)
         per /= 2;
@@ -423,7 +423,7 @@ PERCENTAGE calc_holy_fire_damage_rate(player_type *creature_ptr, rate_calc_type_
  */
 PERCENTAGE calc_hell_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
 {
-    (mode); // unused
+    (void)mode; // unused
     PERCENTAGE per = 100;
     if (creature_ptr->align > 10)
         per *= 2;
@@ -435,7 +435,7 @@ PERCENTAGE calc_hell_fire_damage_rate(player_type *creature_ptr, rate_calc_type_
  */
 PERCENTAGE calc_gravity_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
 {
-    (mode); // unused
+    (void)mode; // unused
     PERCENTAGE per = 100;
     if (creature_ptr->levitation) {
         per = (per * 2) / 3;
index 8f98293..cbbc98d 100644 (file)
@@ -419,12 +419,6 @@ void calc_bonuses(player_type *creature_ptr)
 
     creature_ptr->lite = has_lite(creature_ptr);
 
-    const player_race *tmp_rp_ptr;
-    if (creature_ptr->mimic_form)
-        tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
-    else
-        tmp_rp_ptr = &race_info[creature_ptr->prace];
-
     if (creature_ptr->special_defense & KAMAE_MASK) {
         if (!(empty_hands_status & EMPTY_HAND_RARM)) {
             set_action(creature_ptr, ACTION_NONE);
@@ -2548,12 +2542,6 @@ static s16b calc_speed(player_type *creature_ptr)
     int count;
 
     if (!creature_ptr->riding) {
-        const player_race *tmp_rp_ptr;
-        if (creature_ptr->mimic_form)
-            tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
-        else
-            tmp_rp_ptr = &race_info[creature_ptr->prace];
-
         if (is_specific_player_race(creature_ptr, RACE_KLACKON) || is_specific_player_race(creature_ptr, RACE_SPRITE))
             pow += (creature_ptr->lev) / 10;
 
@@ -3409,8 +3397,8 @@ static DICE_NUMBER calc_to_weapon_dice_num(player_type *creature_ptr, INVENTORY_
 
 static DICE_NUMBER calc_to_weapon_dice_side(player_type *creature_ptr, INVENTORY_IDX slot)
 {
-    (creature_ptr); // unused
-    (slot); // unused
+    (void)creature_ptr; // unused
+    (void)slot; // unused
     return 0;
 }
 
index 57e60ec..f925d5f 100644 (file)
@@ -1943,7 +1943,7 @@ errr term_load(void)
 /*
  * Exchange the "requested" screen with the "tmp" screen
  */
-static errr term_exchange(void)
+errr term_exchange(void)
 {
     TERM_LEN w = Term->wid;
     TERM_LEN h = Term->hgt;
index d7a22da..989727e 100644 (file)
@@ -171,6 +171,8 @@ errr term_inkey(char *ch, bool wait, bool take);
 errr term_save(void);
 errr term_load(void);
 
+errr term_exchange(void);
+
 errr term_resize(TERM_LEN w, TERM_LEN h);
 
 errr term_activate(term_type *t);