summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:56 +0100
committerBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:56 +0100
commit61e8cfc1d553b2bc0cce6b0dd56b03f51f187423 (patch)
tree4988afbe6ad84804444d0dc3151d300e22d1a80e /src
parentb1f5178bdabafde20eb65df6256b53dc5968b2e2 (diff)
Clean up warnings about signed/unsigned comparisons
Diffstat (limited to 'src')
-rw-r--r--src/cave.cc6
-rw-r--r--src/cmd3.cc9
-rw-r--r--src/cmd6.cc5
-rw-r--r--src/loadsave.cc2
-rw-r--r--src/main-sdl.c4
-rw-r--r--src/modules.cc8
-rw-r--r--src/object2.cc23
-rw-r--r--src/randart.cc15
-rw-r--r--src/skills.cc57
-rw-r--r--src/spells1.cc4
-rw-r--r--src/spells2.cc40
-rw-r--r--src/squelch/automatizer.cc6
-rw-r--r--src/squelch/condition_metadata.cc2
-rw-r--r--src/types.h2
-rw-r--r--src/util.cc7
-rw-r--r--src/wizard1.cc8
16 files changed, 118 insertions, 80 deletions
diff --git a/src/cave.cc b/src/cave.cc
index c962829a..19bbe2e7 100644
--- a/src/cave.cc
+++ b/src/cave.cc
@@ -2148,9 +2148,9 @@ void display_map(int *cy, int *cx)
// No priority.
mp.push_back(std::vector<byte>(wid + 2, 0));
}
- assert(ma.size() == hgt + 2);
- assert(mc.size() == hgt + 2);
- assert(mp.size() == hgt + 2);
+ assert(static_cast<int>(ma.size()) == hgt + 2);
+ assert(static_cast<int>(mc.size()) == hgt + 2);
+ assert(static_cast<int>(mp.size()) == hgt + 2);
/* Calculate scaling factors */
yfactor = ((cur_hgt / hgt < 4) && (cur_hgt > hgt)) ? 10 : 1;
diff --git a/src/cmd3.cc b/src/cmd3.cc
index f4a0a511..ba96a44b 100644
--- a/src/cmd3.cc
+++ b/src/cmd3.cc
@@ -15,6 +15,7 @@
#include "quark.h"
#include "hooks.h"
+#include <cassert>
#include <algorithm>
#include <memory>
#include <utility>
@@ -1606,7 +1607,9 @@ void do_cmd_query_symbol(void)
/* Move to "prev" monster */
if (query == '-')
{
- if (++i == who.size())
+ i++;
+ assert(i >= 0);
+ if (static_cast<size_t>(i) == who.size())
{
i = 0;
if (!expand_list) break;
@@ -1800,7 +1803,9 @@ bool_ research_mon()
/* Move to "prev" monster */
if (query == '-')
{
- if (++i == who.size())
+ i++;
+ assert(i >= 0);
+ if (static_cast<size_t>(i) == who.size())
{
i = 0;
if (!expand_list) break;
diff --git a/src/cmd6.cc b/src/cmd6.cc
index 903d5a4d..423843b0 100644
--- a/src/cmd6.cc
+++ b/src/cmd6.cc
@@ -3890,7 +3890,7 @@ void do_cmd_aim_wand(void)
{
bool_ obvious, use_charge;
- int item, ident;
+ int item;
object_type *o_ptr;
@@ -3932,9 +3932,6 @@ void do_cmd_aim_wand(void)
/* Take a turn */
energy_use = 100;
- /* Not identified yet */
- ident = FALSE;
-
/* Enter device mode */
set_stick_mode(o_ptr);
diff --git a/src/loadsave.cc b/src/loadsave.cc
index cf1365c7..8cdbfe5e 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -1548,7 +1548,7 @@ static void do_monster(monster_type *m_ptr, int flag)
do_byte(&m_ptr->speed, flag);
do_byte(&m_ptr->level, flag);
do_s16b(&m_ptr->ac, flag);
- do_u32b(&m_ptr->exp, flag);
+ do_s32b(&m_ptr->exp, flag);
do_s16b(&m_ptr->target, flag);
do_s16b(&m_ptr->bleeding, flag);
diff --git a/src/main-sdl.c b/src/main-sdl.c
index 6a75fb87..c9e70b73 100644
--- a/src/main-sdl.c
+++ b/src/main-sdl.c
@@ -30,6 +30,7 @@
#include <SDL_image.h>
#include <SDL_ttf.h>
+#include <assert.h>
#include <math.h>
/*************************************************
@@ -1099,7 +1100,8 @@ static errr Term_text_sdl(int x, int y, int n, byte a, const char *cp)
SDL_BlitSurface(worksurf,NULL,td->surf,&base);
} else {
/* copy the desired character onto working surface */
- SDL_BlitSurface(text[*cp],NULL,worksurf,NULL);
+ assert(*cp >= 0); // Make sure cast is valid
+ SDL_BlitSurface(text[(size_t)(*cp)],NULL,worksurf,NULL);
/* color our crayon surface with the desired color */
SDL_FillRect(crayon,NULL,color_data[a&0x0f]);
/* apply the color to the character on the working surface */
diff --git a/src/modules.cc b/src/modules.cc
index a2e26fe8..842d6c41 100644
--- a/src/modules.cc
+++ b/src/modules.cc
@@ -377,9 +377,9 @@ static bool_ dleft(byte c, cptr str, int y, int o)
static bool_ dright(byte c, cptr str, int y, int o)
{
- int x = 39 - (strlen(str) / 2) + o;
- int i = 1;
- while (i <= strlen(str))
+ int n = strlen(str); // Conversion to int to avoid warnings
+ int x = 39 - (n / 2) + o;
+ for (int i = 1; i <= n; i++)
{
int a = 79;
int time = 0;
@@ -402,8 +402,6 @@ static bool_ dright(byte c, cptr str, int y, int o)
}
}
}
-
- i = i + 1;
}
return FALSE;
}
diff --git a/src/object2.cc b/src/object2.cc
index 564248bf..06451c53 100644
--- a/src/object2.cc
+++ b/src/object2.cc
@@ -2379,16 +2379,15 @@ static bool_ make_artifact(object_type *o_ptr)
*/
static bool_ make_ego_item(object_type *o_ptr, bool_ good)
{
- int i = 0, j;
bool_ ret = FALSE;
object_kind *k_ptr = &k_info[o_ptr->k_idx];
if (artifact_p(o_ptr) || o_ptr->name2) return (FALSE);
- std::vector<int> ok_ego;
+ std::vector<size_t> ok_ego;
/* Grab the ok ego */
- for (i = 0; i < max_e_idx; i++)
+ for (size_t i = 0; i < max_e_idx; i++)
{
ego_item_type *e_ptr = &e_info[i];
bool_ ok = FALSE;
@@ -2397,7 +2396,7 @@ static bool_ make_ego_item(object_type *o_ptr, bool_ good)
if (!e_ptr->name) continue;
/* Must have the correct fields */
- for (j = 0; j < 6; j++)
+ for (size_t j = 0; j < 6; j++)
{
if (e_ptr->tval[j] == o_ptr->tval)
{
@@ -2437,12 +2436,10 @@ static bool_ make_ego_item(object_type *o_ptr, bool_ good)
}
/* Now test them a few times */
- for (i = 0; i < ok_ego.size() * 10; i++)
+ for (size_t i = 0; i < ok_ego.size() * 10; i++)
{
- ego_item_type *e_ptr;
-
- int j = ok_ego[rand_int(ok_ego.size())];
- e_ptr = &e_info[j];
+ size_t j = ok_ego[rand_int(ok_ego.size())];
+ ego_item_type *e_ptr = &e_info[j];
/* XXX XXX Enforce minimum "depth" (loosely) */
if (e_ptr->level > dun_level)
@@ -2478,12 +2475,10 @@ static bool_ make_ego_item(object_type *o_ptr, bool_ good)
if (magik(7 + luck( -7, 7)) && (!o_ptr->name2b))
{
/* Now test them a few times */
- for (i = 0; i < ok_ego.size() * 10; i++)
+ for (size_t i = 0; i < ok_ego.size() * 10; i++)
{
- ego_item_type *e_ptr;
-
- int j = ok_ego[rand_int(ok_ego.size())];
- e_ptr = &e_info[j];
+ int j = ok_ego[rand_int(ok_ego.size())]; // Explicit int conversion to avoid warning
+ ego_item_type *e_ptr = &e_info[j];
/* Cannot be a double ego of the same ego type */
if (j == o_ptr->name2) continue;
diff --git a/src/randart.cc b/src/randart.cc
index 43f7d256..2acba543 100644
--- a/src/randart.cc
+++ b/src/randart.cc
@@ -28,20 +28,19 @@
*/
static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *max_times)
{
- int i = 0, j;
bool_ ret = FALSE;
u32b f1, f2, f3, f4, f5, esp;
- std::vector<int> ok_ra;
+ std::vector<size_t> ok_ra;
/* Grab the ok randart */
- for (i = 0; i < max_ra_idx; i++)
+ for (size_t i = 0; i < max_ra_idx; i++)
{
randart_part_type *ra_ptr = &ra_info[i];
bool_ ok = FALSE;
/* Must have the correct fields */
- for (j = 0; j < 20; j++)
+ for (size_t j = 0; j < 20; j++)
{
if (ra_ptr->tval[j] == o_ptr->tval)
{
@@ -77,12 +76,10 @@ static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *m
}
/* Now test them a few times */
- for (i = 0; i < ok_ra.size() * 10; i++)
+ for (size_t count = 0; count < ok_ra.size() * 10; count++)
{
- randart_part_type *ra_ptr;
-
- i = ok_ra[rand_int(ok_ra.size())];
- ra_ptr = &ra_info[i];
+ size_t i = ok_ra[rand_int(ok_ra.size())];
+ randart_part_type *ra_ptr = &ra_info[i];
/* XXX XXX Enforce minimum player level (loosely) */
if (ra_ptr->level > p_ptr->lev)
diff --git a/src/skills.cc b/src/skills.cc
index 37e84c57..e8291ce4 100644
--- a/src/skills.cc
+++ b/src/skills.cc
@@ -752,13 +752,13 @@ void select_default_melee()
static void print_skill_batch(const std::vector<std::tuple<cptr, int>> &p, int start)
{
char buff[80];
- int i = start, j = 0;
+ int j = 0;
prt(format(" %-31s", "Name"), 1, 20);
- for (i = start; i < (start + 20); i++)
+ for (int i = start; i < (start + 20); i++)
{
- if (i >= p.size())
+ if (static_cast<size_t>(i) >= p.size())
{
break;
}
@@ -777,7 +777,7 @@ static void print_skill_batch(const std::vector<std::tuple<cptr, int>> &p, int s
static int do_cmd_activate_skill_aux()
{
char which;
- int i, start = 0;
+ int start = 0;
int ret;
std::vector<std::tuple<cptr,int>> p;
@@ -788,7 +788,7 @@ static int do_cmd_activate_skill_aux()
p.push_back(std::make_tuple("Change melee mode", 0));
}
- for (i = 1; i < max_s_idx; i++)
+ for (size_t i = 1; i < max_s_idx; i++)
{
if (s_info[i].action_mkey && s_info[i].value && ((!s_info[i].hidden) || (i == SKILL_LEARN)))
{
@@ -810,7 +810,7 @@ static int do_cmd_activate_skill_aux()
}
}
- for (i = 0; i < max_ab_idx; i++)
+ for (size_t i = 0; i < max_ab_idx; i++)
{
if (ab_info[i].action_mkey && ab_info[i].acquired)
{
@@ -854,14 +854,20 @@ static int do_cmd_activate_skill_aux()
else if (which == '+')
{
start += 20;
- if (start >= p.size()) start -= 20;
+ if (static_cast<size_t>(start) >= p.size())
+ {
+ start -= 20;
+ }
Term_load();
character_icky = FALSE;
}
else if (which == '-')
{
start -= 20;
- if (start < 0) start += 20;
+ if (start < 0)
+ {
+ start += 20;
+ }
Term_load();
character_icky = FALSE;
}
@@ -874,22 +880,23 @@ static int do_cmd_activate_skill_aux()
return FALSE;
/* Find the skill it is related to */
- for (i = 0; i < p.size(); i++)
+ size_t i = 0;
+ for (; i < p.size(); i++)
{
if (!strcmp(buf, std::get<0>(p[i])))
break;
}
- if ((i < p.size()))
+
+ if (i < p.size())
{
ret = std::get<1>(p[i]);
break;
}
-
}
else
{
which = tolower(which);
- if (start + A2I(which) >= p.size())
+ if (start + A2I(which) >= static_cast<int>(p.size()))
{
bell();
continue;
@@ -1593,7 +1600,8 @@ static void print_abilities(const std::vector<int> &table, int sel, int start)
byte color = TERM_WHITE;
char deb = ' ', end = ' ';
- if (j >= table.size())
+ assert(j >= 0);
+ if (static_cast<size_t>(j) >= table.size())
{
break;
}
@@ -1679,7 +1687,8 @@ void do_cmd_ability()
else if (c == 'n')
{
sel += (hgt - 7);
- if (sel >= table.size())
+ assert(sel >= 0);
+ if (static_cast<size_t>(sel) >= table.size())
{
sel = table.size() - 1;
}
@@ -1721,10 +1730,22 @@ void do_cmd_ability()
}
/* Handle boundaries and scrolling */
- if (sel < 0) sel = table.size() - 1;
- if (sel >= table.size()) sel = 0;
- if (sel < start) start = sel;
- if (sel >= start + (hgt - 7)) start = sel - (hgt - 7) + 1;
+ if (sel < 0)
+ {
+ sel = table.size() - 1;
+ }
+ if (static_cast<size_t>(sel) >= table.size())
+ {
+ sel = 0;
+ }
+ if (sel < start)
+ {
+ start = sel;
+ }
+ if (sel >= start + (hgt - 7))
+ {
+ start = sel - (hgt - 7) + 1;
+ }
}
}
diff --git a/src/spells1.cc b/src/spells1.cc
index 9207974c..0eda200c 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -8956,6 +8956,10 @@ bool_ potion_smash_effect(int who, int y, int x, int o_sval)
(void) project(who, radius, y, x, dam, dt,
(PROJECT_JUMP | PROJECT_ITEM | PROJECT_KILL));
+ // Silence warning. We may want to introuce an actual implementation
+ // and I want to preserve the original "ident" values if we do so.
+ (void) ident;
+
/* XXX those potions that explode need to become "known" */
return angry;
}
diff --git a/src/spells2.cc b/src/spells2.cc
index 679b7b14..3f12b613 100644
--- a/src/spells2.cc
+++ b/src/spells2.cc
@@ -16,6 +16,7 @@
#include <cassert>
#include <chrono>
+#include <sstream>
#include <thread>
#include <vector>
@@ -5331,7 +5332,12 @@ void do_probe(int m_idx)
sprintf(t_name, "nothing");
msg_format("%^s target is %s.", m_name, t_name);
- msg_format("%^s has %ld exp and needs %d.", m_name, m_ptr->exp, (int) monster_exp(m_ptr->level + 1));
+ {
+ std::ostringstream buf;
+ buf << " has " << m_ptr->exp
+ << " exp and needs " << monster_exp(m_ptr->level + 1) << ".";
+ msg_format("%^s%s", m_name, buf.str().c_str());
+ }
}
/* Learn all of the non-spell, non-treasure flags */
@@ -7840,10 +7846,9 @@ static void print_dungeon_batch(std::vector<int> const &dungeon_idxs,
int i, j;
byte attr;
-
if (mode) prt(format(" %-31s", "Name"), 1, 20);
- for (i = 0, j = start; i < 20 && j < dungeon_idxs.size(); i++, j++)
+ for (i = 0, j = start; i < 20 && j < static_cast<int>(dungeon_idxs.size()); i++, j++)
{
dungeon_info_type *d_ptr = &d_info[dungeon_idxs[j]];
@@ -7869,13 +7874,13 @@ static void print_dungeon_batch(std::vector<int> const &dungeon_idxs,
int reset_recall_aux()
{
char which;
- int i, start = 0;
+ int start = 0;
int ret;
bool_ mode = FALSE;
// Dungeons available for recall
std::vector<int> dungeons;
- for (i = 1; i < max_d_idx; i++)
+ for (size_t i = 1; i < max_d_idx; i++)
{
/* skip "blocked" dungeons */
if (d_info[i].flags1 & DF1_NO_RECALL) continue;
@@ -7910,7 +7915,11 @@ int reset_recall_aux()
else if (which == '+')
{
start += 20;
- if (start >= dungeons.size()) start -= 20;
+ assert(start > 0);
+ if (static_cast<size_t>(start) >= dungeons.size())
+ {
+ start -= 20;
+ }
Term_load();
character_icky = FALSE;
}
@@ -7918,7 +7927,10 @@ int reset_recall_aux()
else if (which == '-')
{
start -= 20;
- if (start < 0) start += 20;
+ if (start < 0)
+ {
+ start += 20;
+ }
Term_load();
character_icky = FALSE;
}
@@ -7931,6 +7943,7 @@ int reset_recall_aux()
if (!get_string("Which dungeon? ", buf, 79)) continue;
/* Find the index corresponding to the name */
+ int i;
for (i = 1; i < max_d_idx; i++)
{
sprintf(buf2, "%s", d_info[i].name + d_name);
@@ -7970,18 +7983,23 @@ int reset_recall_aux()
else
{
which = tolower(which);
- if (start + A2I(which) >= dungeons.size())
+ int i = start + A2I(which);
+
+ if (i < 0)
{
bell();
continue;
}
- if (start + A2I(which) < 0)
+ else if (static_cast<size_t>(i) >= dungeons.size()) // Cast to avoid compilation warning
{
bell();
continue;
}
- ret = dungeons[start + A2I(which)];
- break;
+ else
+ {
+ ret = dungeons[i];
+ break;
+ }
}
}
diff --git a/src/squelch/automatizer.cc b/src/squelch/automatizer.cc
index 0c0f571a..b05a253f 100644
--- a/src/squelch/automatizer.cc
+++ b/src/squelch/automatizer.cc
@@ -231,9 +231,11 @@ void Automatizer::select_rule(int selected_rule)
// Adjust selection to conform to bounds.
{
+ int rules_size = m_rules.size(); // Convert to int to avoid warnings
+
if (m_selected_rule < 0)
{
- m_selected_rule = m_rules.size() - 1;
+ m_selected_rule = rules_size - 1;
m_begin = m_selected_rule - hgt + 3;
if (m_begin < 0)
{
@@ -246,7 +248,7 @@ void Automatizer::select_rule(int selected_rule)
m_begin = m_selected_rule;
}
- if (m_selected_rule >= m_rules.size())
+ if (m_selected_rule >= rules_size)
{
m_selected_rule = 0;
m_begin = 0;
diff --git a/src/squelch/condition_metadata.cc b/src/squelch/condition_metadata.cc
index 766d44aa..273d3092 100644
--- a/src/squelch/condition_metadata.cc
+++ b/src/squelch/condition_metadata.cc
@@ -431,7 +431,7 @@ std::shared_ptr<Condition> new_condition_interactive()
else if (c == '2')
{
sel++;
- if (sel >= condition_types.size())
+ if (sel >= static_cast<int>(condition_types.size()))
{
sel = 0;
begin = 0;
diff --git a/src/types.h b/src/types.h
index 30bbdfd8..cbd9196b 100644
--- a/src/types.h
+++ b/src/types.h
@@ -840,7 +840,7 @@ struct monster_type
byte speed; /* Speed (normally 110) */
byte level; /* Level of creature */
s16b ac; /* Armour Class */
- u32b exp; /* Experience */
+ s32b exp; /* Experience */
s16b csleep; /* Inactive counter */
diff --git a/src/util.cc b/src/util.cc
index a4c00a26..550fc9e4 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -3516,6 +3516,7 @@ int ask_menu(cptr ask, const std::vector<std::string> &items)
{
int ret = -1, i, start = 0;
char c;
+ int size = items.size(); // Convert to int to avoid warnings
/* Enter "icky" mode */
character_icky = TRUE;
@@ -3529,7 +3530,7 @@ int ask_menu(cptr ask, const std::vector<std::string> &items)
Term_load();
Term_save();
prt(ask, 0, 0);
- for (i = start; (i < items.size()) && (i < start + 20); i++)
+ for (i = start; (i < size) && (i < start + 20); i++)
{
prt(format("%c) %s", I2A(i - start), items[i].c_str()), i - start + 1, 0);
}
@@ -3543,7 +3544,7 @@ int ask_menu(cptr ask, const std::vector<std::string> &items)
/* Scroll */
else if (c == '+')
{
- if (start + 20 < items.size())
+ if (start + 20 < size)
start += 20;
continue;
}
@@ -3560,7 +3561,7 @@ int ask_menu(cptr ask, const std::vector<std::string> &items)
else
{
c = tolower(c);
- if (A2I(c) + start >= items.size())
+ if (A2I(c) + start >= size)
{
bell();
continue;
diff --git a/src/wizard1.cc b/src/wizard1.cc
index 90ee5d27..883ed5a6 100644
--- a/src/wizard1.cc
+++ b/src/wizard1.cc
@@ -1312,8 +1312,6 @@ static void spoil_artifact(cptr fname)
*/
static void spoil_mon_desc(cptr fname)
{
- int i = 0;
-
char buf[1024];
char nam[80];
@@ -1356,7 +1354,7 @@ static void spoil_mon_desc(cptr fname)
/* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
+ for (size_t i = 1; i < max_r_idx; i++)
{
monster_race *r_ptr = &r_info[i];
@@ -1368,9 +1366,9 @@ static void spoil_mon_desc(cptr fname)
/* Scan again */
- for (i = 0; i < who.size(); i++)
+ for (auto const who_i : who)
{
- monster_race *r_ptr = &r_info[who[i]];
+ monster_race *r_ptr = &r_info[who_i];
cptr name = (r_name + r_ptr->name);