Skip to content

Commit

Permalink
Further warning resolutions. Specifically focused on signed/unsigned …
Browse files Browse the repository at this point in the history
…mismatches.

Change to warning flags in Makefile.

Small error fix.
  • Loading branch information
AkrionXxarr committed Feb 28, 2013
1 parent e19854d commit 9ba34d3
Show file tree
Hide file tree
Showing 34 changed files with 486 additions and 484 deletions.
5 changes: 3 additions & 2 deletions Makefile.Windows
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# WARNINGS will spam hundreds of warnings, mostly safe, if turned on
# DEBUG is best turned on if you plan to debug in gdb -- please do!
# PROFILE is for use with gprof or a similar program -- don't bother generally
#WARNINGS = -Wall -Wextra -Wno-switch -Wno-sign-compare -Wno-missing-braces -Wno-unused-parameter -Wno-char-subscripts

WARNINGS = -Wall -Wextra
DEBUG = -g
#PROFILE = -pg
OTHERS = -O3
Expand Down Expand Up @@ -49,4 +50,4 @@ $(ODIR)/%.o: %.cpp
clean:
rm -f $(TARGET) $(ODIR)/*.o

-include $(SOURCES:%.cpp=$(DEPDIR)/%.P)
-include $(SOURCES:%.cpp=$(DEPDIR)/%.P)
2 changes: 1 addition & 1 deletion bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void bionics_install_failure(game *g, player *u, int success)
fail_text += " and ";
fail_text += (u->my_bionics.size() <= failure_level ? "all" : "some");
fail_text += " of your existing bionics are lost.";
for (unsigned int i = 0; i < failure_level && u->my_bionics.size() > 0; i++) {
for (int i = 0; i < failure_level && u->my_bionics.size() > 0; i++) {
int rem = rng(0, u->my_bionics.size() - 1);
u->my_bionics.erase(u->my_bionics.begin() + rem);
}
Expand Down
2 changes: 1 addition & 1 deletion construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ bool game::player_can_build(player &p, inventory inv, constructable* con,
start = level;

bool can_build_any = false;
for (unsigned int i = start; i < con->stages.size() && i <= last_level; i++) {
for (int i = start; i < con->stages.size() && i <= last_level; i++) {
construction_stage stage = con->stages[i];
bool has_tool = false;
bool has_component = false;
Expand Down
2 changes: 1 addition & 1 deletion faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ std::string faction::save_info()
good << " " << omx << " " << omy << " " << mapx << " " << mapy <<
" " << size << " " << power << " ";
dump << opinion_of.size() << " ";
for (int i = 0; i < opinion_of.size(); i++)
for (unsigned int i = 0; i < opinion_of.size(); i++)
dump << opinion_of[i] << " ";
dump << name;
return dump.str();
Expand Down
2 changes: 1 addition & 1 deletion help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ from frostbite and to keep your distance from large fires.");
if (keys.empty())
printz(c_red, "Unbound!");
else {
for (int j = 0; j < keys.size(); j++) {
for (unsigned int j = 0; j < keys.size(); j++) {
printz(c_yellow, "%c", keys[j]);
if (j < keys.size() - 1)
printz(c_white, " or ");
Expand Down
52 changes: 26 additions & 26 deletions inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std::vector<item> inventory::as_vector()
{
std::vector<item> ret;
for (int i = 0; i < size(); i++) {
for (int j = 0; j < stack_at(i).size(); j++)
for (unsigned int j = 0; j < stack_at(i).size(); j++)
ret.push_back(items[i][j]);
}
return ret;
Expand All @@ -53,7 +53,7 @@ int inventory::size() const
int inventory::num_items() const
{
int ret = 0;
for (int i = 0; i < items.size(); i++)
for (unsigned int i = 0; i < items.size(); i++)
ret += items[i].size();

return ret;
Expand Down Expand Up @@ -90,7 +90,7 @@ inventory& inventory::operator+= (const inventory &rhs)

inventory& inventory::operator+= (const std::vector<item> &rhs)
{
for (int i = 0; i < rhs.size(); i++)
for (unsigned int i = 0; i < rhs.size(); i++)
add_item(rhs[i]);
return *this;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ void inventory::clear()

void inventory::add_stack(const std::vector<item> newits)
{
for (int i = 0; i < newits.size(); i++)
for (unsigned int i = 0; i < newits.size(); i++)
add_item(newits[i], true);
}

Expand All @@ -139,7 +139,7 @@ void inventory::add_item(item newit, bool keep_invlet)

if (newit.is_style())
return; // Styles never belong in our inventory.
for (int i = 0; i < items.size(); i++) {
for (unsigned int i = 0; i < items.size(); i++) {
if (items[i][0].stacks_with(newit)) {
newit.invlet = items[i][0].invlet;
items[i].push_back(newit);
Expand Down Expand Up @@ -169,7 +169,7 @@ void inventory::restack(player *p)
{
inventory tmp;
for (int i = 0; i < size(); i++) {
for (int j = 0; j < items[i].size(); j++)
for (unsigned int j = 0; j < items[i].size(); j++)
tmp.add_item(items[i][j]);
}
clear();
Expand All @@ -178,7 +178,7 @@ void inventory::restack(player *p)
if (!tmp[i].invlet_is_okay() || p->has_weapon_or_armor(tmp[i].invlet)) {
//debugmsg("Restacking item %d (invlet %c)", i, tmp[i].invlet);
tmp.assign_empty_invlet(tmp[i], p);
for (int j = 1; j < tmp.stack_at(i).size(); j++)
for (unsigned int j = 1; j < tmp.stack_at(i).size(); j++)
tmp.stack_at(i)[j].invlet = tmp[i].invlet;
}
}
Expand All @@ -192,7 +192,7 @@ void inventory::form_from_map(game *g, point origin, int range)
items.clear();
for (int x = origin.x - range; x <= origin.x + range; x++) {
for (int y = origin.y - range; y <= origin.y + range; y++) {
for (int i = 0; i < g->m.i_at(x, y).size(); i++)
for (unsigned int i = 0; i < g->m.i_at(x, y).size(); i++)
if (!g->m.i_at(x, y)[i].made_of(LIQUID))
add_item(g->m.i_at(x, y)[i]);
// Kludges for now!
Expand Down Expand Up @@ -260,7 +260,7 @@ item inventory::remove_item(int stack, int index)

item inventory::remove_item_by_letter(char ch)
{
for (int i = 0; i < items.size(); i++) {
for (unsigned int i = 0; i < items.size(); i++) {
if (items[i][0].invlet == ch) {
if (items[i].size() > 1)
items[i][1].invlet = ch;
Expand Down Expand Up @@ -290,7 +290,7 @@ item inventory::remove_item_by_quantity(int index, int quantity)

item& inventory::item_by_letter(char ch)
{
for (int i = 0; i < items.size(); i++) {
for (unsigned int i = 0; i < items.size(); i++) {
if (items[i][0].invlet == ch)
return items[i][0];
}
Expand All @@ -301,7 +301,7 @@ int inventory::index_by_letter(char ch)
{
if (ch == KEY_ESCAPE)
return -1;
for (int i = 0; i < items.size(); i++) {
for (unsigned int i = 0; i < items.size(); i++) {
if (items[i][0].invlet == ch)
return i;
}
Expand All @@ -311,8 +311,8 @@ int inventory::index_by_letter(char ch)
int inventory::amount_of(itype_id it)
{
int count = 0;
for (int i = 0; i < items.size(); i++) {
for (int j = 0; j < items[i].size(); j++) {
for (unsigned int i = 0; i < items.size(); i++) {
for (unsigned int j = 0; j < items[i].size(); j++) {
if (items[i][j].type->id == it)
{
// check if it's a container, if so, it should be empty
Expand All @@ -322,7 +322,7 @@ int inventory::amount_of(itype_id it)
count++;
} else count++;
}
for (int k = 0; k < items[i][j].contents.size(); k++) {
for (unsigned int k = 0; k < items[i][j].contents.size(); k++) {
if (items[i][j].contents[k].type->id == it)
count++;
}
Expand All @@ -334,15 +334,15 @@ int inventory::amount_of(itype_id it)
int inventory::charges_of(itype_id it)
{
int count = 0;
for (int i = 0; i < items.size(); i++) {
for (int j = 0; j < items[i].size(); j++) {
for (unsigned int i = 0; i < items.size(); i++) {
for (unsigned int j = 0; j < items[i].size(); j++) {
if (items[i][j].type->id == it) {
if (items[i][j].charges < 0)
count++;
else
count += items[i][j].charges;
}
for (int k = 0; k < items[i][j].contents.size(); k++) {
for (unsigned int k = 0; k < items[i][j].contents.size(); k++) {
if (items[i][j].contents[k].type->id == it) {
if (items[i][j].contents[k].charges < 0)
count++;
Expand All @@ -357,11 +357,11 @@ int inventory::charges_of(itype_id it)

void inventory::use_amount(itype_id it, int quantity, bool use_container)
{
for (int i = 0; i < items.size() && quantity > 0; i++) {
for (int j = 0; j < items[i].size() && quantity > 0; j++) {
for (unsigned int i = 0; i < items.size() && quantity > 0; i++) {
for (unsigned int j = 0; j < items[i].size() && quantity > 0; j++) {
// First, check contents
bool used_item_contents = false;
for (int k = 0; k < items[i][j].contents.size() && quantity > 0; k++) {
for (unsigned int k = 0; k < items[i][j].contents.size() && quantity > 0; k++) {
if (items[i][j].contents[k].type->id == it) {
quantity--;
items[i][j].contents.erase(items[i][j].contents.begin() + k);
Expand Down Expand Up @@ -394,10 +394,10 @@ void inventory::use_amount(itype_id it, int quantity, bool use_container)

void inventory::use_charges(itype_id it, int quantity)
{
for (int i = 0; i < items.size() && quantity > 0; i++) {
for (int j = 0; j < items[i].size() && quantity > 0; j++) {
for (unsigned int i = 0; i < items.size() && quantity > 0; i++) {
for (unsigned int j = 0; j < items[i].size() && quantity > 0; j++) {
// First, check contents
for (int k = 0; k < items[i][j].contents.size() && quantity > 0; k++) {
for (unsigned int k = 0; k < items[i][j].contents.size() && quantity > 0; k++) {
if (items[i][j].contents[k].type->id == it) {
if (items[i][j].contents[k].charges <= quantity) {
quantity -= items[i][j].contents[k].charges;
Expand Down Expand Up @@ -447,11 +447,11 @@ bool inventory::has_charges(itype_id it, int quantity)

bool inventory::has_item(item *it)
{
for (int i = 0; i < items.size(); i++) {
for (int j = 0; j < items[i].size(); j++) {
for (unsigned int i = 0; i < items.size(); i++) {
for (unsigned int j = 0; j < items[i].size(); j++) {
if (it == &(items[i][j]))
return true;
for (int k = 0; k < items[i][j].contents.size(); k++) {
for (unsigned int k = 0; k < items[i][j].contents.size(); k++) {
if (it == &(items[i][j].contents[k]))
return true;
}
Expand Down
16 changes: 8 additions & 8 deletions inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void print_inv_statics(game *g, WINDOW* w_inv, std::string title,
// Print our weapon
mvwprintz(w_inv, 2, 45, c_magenta, "WEAPON:");
int dropping_weapon = false;
for (int i = 0; i < dropped_items.size() && !dropping_weapon; i++) {
for (unsigned int i = 0; i < dropped_items.size() && !dropping_weapon; i++) {
if (dropped_items[i] == g->u.weapon.invlet)
dropping_weapon = true;
}
Expand All @@ -62,9 +62,9 @@ void print_inv_statics(game *g, WINDOW* w_inv, std::string title,
// Print worn items
if (g->u.worn.size() > 0)
mvwprintz(w_inv, 5, 45, c_magenta, "ITEMS WORN:");
for (int i = 0; i < g->u.worn.size(); i++) {
for (unsigned int i = 0; i < g->u.worn.size(); i++) {
bool dropping_armor = false;
for (int j = 0; j < dropped_items.size() && !dropping_armor; j++) {
for (unsigned int j = 0; j < dropped_items.size() && !dropping_armor; j++) {
if (dropped_items[j] == g->u.worn[i].invlet)
dropping_armor = true;
}
Expand Down Expand Up @@ -375,7 +375,7 @@ std::vector<item> game::multidrop()
int index = u.inv.index_by_letter(ch);
if (index == -1) { // Not from inventory
int found = false;
for (int i = 0; i < weapon_and_armor.size() && !found; i++) {
for (unsigned int i = 0; i < weapon_and_armor.size() && !found; i++) {
if (weapon_and_armor[i] == ch) {
weapon_and_armor.erase(weapon_and_armor.begin() + i);
found = true;
Expand Down Expand Up @@ -472,7 +472,7 @@ std::vector<item> game::multidrop()
current_stack++;
}

for (int i = 0; i < weapon_and_armor.size(); i++)
for (unsigned int i = 0; i < weapon_and_armor.size(); i++)
ret.push_back(u.i_rem(weapon_and_armor[i]));

return ret;
Expand Down Expand Up @@ -508,7 +508,7 @@ void game::compare(int iCompareX, int iCompareY)
std::vector <item> grounditems;
//Filter out items with the same name (keep only one of them)
std::map <std::string, bool> dups;
for (int i = 0; i < here.size(); i++) {
for (unsigned int i = 0; i < here.size(); i++) {
if (!dups[here[i].tname(this).c_str()]) {
grounditems.push_back(here[i]);
dups[here[i].tname(this).c_str()] = true;
Expand All @@ -534,7 +534,7 @@ void game::compare(int iCompareX, int iCompareY)
if (groundsize > 0) {
firsts.push_back(0);
}
for (int i = 0; i < first.size(); i++) {
for (unsigned int i = 0; i < first.size(); i++) {
firsts.push_back((first[i] >= 0) ? first[i]+groundsize : -1);
}
ch = '.';
Expand Down Expand Up @@ -602,7 +602,7 @@ void game::compare(int iCompareX, int iCompareY)
int index = u.inv.index_by_letter(ch);
if (index == -1) { // Not from inventory
bool found = false;
for (int i = 0; i < weapon_and_armor.size() && !found; i++) {
for (unsigned int i = 0; i < weapon_and_armor.size() && !found; i++) {
if (weapon_and_armor[i] == ch) {
weapon_and_armor.erase(weapon_and_armor.begin() + i);
found = true;
Expand Down
Loading

0 comments on commit 9ba34d3

Please sign in to comment.