Fixed signed/unsigned comparision warnings

This commit is contained in:
Pauli Nieminen 2008-09-11 12:34:33 +00:00
parent 56d8134847
commit 715b7d031b
28 changed files with 66 additions and 57 deletions

View file

@ -269,9 +269,11 @@ env.Replace(CPPDEFINES = ["HAVE_CONFIG_H"])
if env['static']:
env.AppendUnique(LINKFLAGS = "-all-static")
env.AppendUnique(CXXFLAGS = Split("-W -Wall -Wno-unused -Wno-sign-compare -ansi"))
env.AppendUnique(CXXFLAGS = Split("-W -Wall -ansi"))
if env['strict']:
env.AppendUnique(CXXFLAGS = "-Werror")
else:
env.AppendUnique(CXXFLAGS = Split("-Wno-unused -Wno-sign-compare"))
if env['gui'] == 'tiny':
env.Append(CPPDEFINES = "USE_TINY_GUI")
@ -333,6 +335,7 @@ env.MergeFlags(env["extra_flags_" + build])
test_env = env.Clone()
if not env['static_test']:
test_env.Append(CPPDEFINES = "BOOST_TEST_DYN_LINK")
test_env.AppendUnique(CXXFLAGS = "-Wno-unused")
Export("test_env")
if build == "base":

View file

@ -815,13 +815,13 @@ namespace {
weap_index = -1;
return;
}
if(weap_index >= 0 && weap_index < attacks.size() && attacks[weap_index].id() == weap_id) {
if(weap_index >= 0 && weap_index < static_cast<int>(attacks.size()) && attacks[weap_index].id() == weap_id) {
//the currently selected attack fits
return;
}
if(!weap_id.empty()) {
//lookup the weapon by id
for(int i=0; i<attacks.size(); ++i) {
for(int i=0; i<static_cast<int>(attacks.size()); ++i) {
if(attacks[i].id() == weap_id) {
weap_index = i;
return;

View file

@ -869,7 +869,7 @@ int filter_textbox::get_index(int selection) const {
void filter_textbox::delete_item(int selection) {
// use the real selection
int adjusted_selection = selection + header_row_;
size_t adjusted_selection = selection + header_row_;
if (adjusted_selection >= index_map_.size())
return;

View file

@ -49,11 +49,11 @@ editor_map::~editor_map()
void editor_map::sanity_check()
{
int errors = 0;
if (total_width() != tiles_.size()) {
if (total_width() != static_cast<int>(tiles_.size())) {
ERR_ED << "total_width is " << total_width() << " but tiles_.size() is " << tiles_.size() << "\n";
++errors;
}
if (total_height() != tiles_[0].size()) {
if (total_height() != static_cast<int>(tiles_[0].size())) {
ERR_ED << "total_height is " << total_height() << " but tiles_[0].size() is " << tiles_.size() << "\n";
++errors;
}
@ -155,7 +155,7 @@ void editor_map::select_all()
bool editor_map::everything_selected() const
{
LOG_ED << selection_.size() << " " << total_width() * total_height() << "\n";
return selection_.size() == total_width() * total_height();
return static_cast<int>(selection_.size()) == total_width() * total_height();
}
void editor_map::resize(int width, int height, int x_offset, int y_offset,
@ -301,7 +301,7 @@ void editor_map::expand_left(int count, t_translation::t_terrain filler)
void editor_map::expand_top(int count, t_translation::t_terrain filler)
{
for (int y = 0; y < count; ++y) {
for (int x = 0; x < tiles_.size(); ++x) {
for (int x = 0; x < static_cast<int>(tiles_.size()); ++x) {
t_translation::t_terrain terrain =
filler != t_translation::NONE_TERRAIN ?
filler :
@ -319,7 +319,7 @@ void editor_map::expand_bottom(int count, t_translation::t_terrain filler)
{
int h = tiles_[1].size();
for (int y = 0; y < count; ++y) {
for (int x = 0; x < tiles_.size(); ++x) {
for (int x = 0; x < static_cast<int>(tiles_.size()); ++x) {
t_translation::t_terrain terrain =
filler != t_translation::NONE_TERRAIN ?
filler :
@ -334,7 +334,7 @@ void editor_map::expand_bottom(int count, t_translation::t_terrain filler)
void editor_map::shrink_right(int count)
{
if(count < 0 || count > tiles_.size()) {
if(count < 0 || count > static_cast<int>(tiles_.size())) {
throw editor_map_operation_exception();
}
tiles_.resize(tiles_.size() - count);
@ -344,7 +344,7 @@ void editor_map::shrink_right(int count)
void editor_map::shrink_left(int count)
{
if(count < 0 || count > tiles_.size()) {
if(count < 0 || count > static_cast<int>(tiles_.size())) {
throw editor_map_operation_exception();
}
tiles_.erase(tiles_.begin(), tiles_.begin() + count);
@ -354,7 +354,7 @@ void editor_map::shrink_left(int count)
void editor_map::shrink_top(int count)
{
if(count < 0 || count > tiles_[0].size()) {
if(count < 0 || count > static_cast<int>(tiles_[0].size())) {
throw editor_map_operation_exception();
}
for (size_t x = 0; x < tiles_.size(); ++x) {
@ -366,7 +366,7 @@ void editor_map::shrink_top(int count)
void editor_map::shrink_bottom(int count)
{
if(count < 0 || count > tiles_[0].size()) {
if(count < 0 || count > static_cast<int>(tiles_[0].size())) {
throw editor_map_operation_exception();
}
for (size_t x = 0; x < tiles_.size(); ++x) {

View file

@ -541,14 +541,14 @@ unsigned int brush_bar::selected_brush_size() {
}
void brush_bar::select_brush(int index) {
assert(index > 0 && index < brushes_.size());
assert(static_cast<size_t>(index) < brushes_.size());
selected_ = index;
}
void brush_bar::left_mouse_click(const int mousex, const int mousey) {
int index = selected_index(mousex, mousey);
if(index >= 0) {
if (index != selected_) {
if (static_cast<size_t>(index) != selected_) {
set_dirty();
selected_ = index;
*the_brush_ = &brushes_[index];
@ -624,16 +624,16 @@ int brush_bar::selected_index(int x, int y) const {
const int bar_x = size_specs_.brush_x;
const int bar_y = size_specs_.brush_y;
if ((x < bar_x || x > bar_x + size_ * brushes_.size() +
if ((x < bar_x || static_cast<size_t>(x) > bar_x + size_ * brushes_.size() +
brushes_.size() * size_specs_.brush_padding) ||
(y < bar_y || y > bar_y + size_)) {
(y < bar_y || static_cast<size_t>(y) > bar_y + size_)) {
return -1;
}
for(int i = 0; i < brushes_.size(); i++) {
for(size_t i = 0; i < brushes_.size(); i++) {
int px = bar_x + size_ * i + i * size_specs_.brush_padding;
if (x >= px && x <= px + size_ && y >= bar_y && y <= bar_y + size_) {
if (x >= px && x <= px + static_cast<int>(size_) && y >= bar_y && y <= bar_y + static_cast<int>(size_)) {
return i;
}
}

View file

@ -265,7 +265,7 @@ void map_context::clear_undo_redo()
void map_context::trim_stack(action_stack& stack)
{
if (stack.size() > max_action_stack_size_) {
if (stack.size() > static_cast<size_t>(max_action_stack_size_)) {
delete stack.front();
stack.pop_front();
}

View file

@ -411,7 +411,7 @@ std::string get_exe_dir()
#ifndef _WIN32
char buf[1024];
size_t path_size = readlink("/proc/self/exe", buf, 1024);
if(path_size == -1)
if(path_size == static_cast<size_t>(-1))
return std::string();
buf[path_size] = 0;
return std::string(dirname(buf));

View file

@ -1908,7 +1908,7 @@ bool formula_ai::can_attack(const gamemap::location unit_loc,
void candidate_move::evaluate_move(const formula_ai* ai, unit_map& units,
int team_num) {
size_t team_num) {
score_ = -1000;
if(type_ == "attack") {
for(unit_map::unit_iterator me = units.begin() ; me != units.end() ; ++me)

View file

@ -40,7 +40,7 @@ public:
enemy_unit_()
{};
void evaluate_move(const formula_ai* ai, unit_map& units, int team_num);
void evaluate_move(const formula_ai* ai, unit_map& units, size_t team_num);
int get_score() const {return score_;}
std::string get_type() const {return type_;}

View file

@ -309,6 +309,9 @@ game_controller::game_controller(int argc, char** argv) :
preferences::disable_preferences_save();
} else if(val == "--smallgui") {
game_config::small_gui = true;
} else if(val == "--config-dir") {
if (argc_ <= ++arg_)
break;
} else if(val == "--windowed" || val == "-w") {
preferences::set_fullscreen(false);
} else if(val == "--fullscreen" || val == "-f") {

View file

@ -1027,7 +1027,7 @@ void game_display::parse_team_overlays()
if (overlay->second.team_name != "" &&
bool(overlay->second.team_name.find(teams_[playing_team()].team_name())+1) !=
bool(overlay->second.team_name.find(teams_[playing_team()-1 > -1 ? playing_team()-1 : teams_.size()-1].team_name())+1))
bool(overlay->second.team_name.find(teams_[playing_team()-1 < teams_.size() ? playing_team()-1 : teams_.size()-1].team_name())+1))
{
invalidate(overlay->first);
}

View file

@ -810,7 +810,7 @@ namespace {
const unsigned int current_turn_number = status_ptr->turn();
const int new_turn_number = lexical_cast_default<int>(current, current_turn_number);
const unsigned int new_turn_number_u = static_cast<unsigned int>(new_turn_number);
if(new_turn_number < current_turn_number || new_turn_number > status_ptr->number_of_turns()) {
if(new_turn_number_u < current_turn_number || new_turn_number > status_ptr->number_of_turns()) {
ERR_NG << "attempted to change current turn number to one out of range (" << new_turn_number << ") or less than current turn\n";
} else if(new_turn_number_u != current_turn_number) {
status_ptr->set_turn(new_turn_number_u);

View file

@ -403,7 +403,7 @@ void gamestatus::set_turn(unsigned int num)
if (currentTime_ < 0) {
currentTime_ += times_.size();
}
if(num > numTurns_ && numTurns_ != -1) {
if(static_cast<int>(num) > numTurns_ && numTurns_ != -1) {
this->add_turns(numTurns_ - num);
}
turn_ = num;

View file

@ -57,7 +57,7 @@ void teditor_generate_map::do_next_generator(twindow& window)
map_generator* teditor_generate_map::get_selected_map_generator()
{
assert(current_map_generator_ >= 0 && current_map_generator_ < map_generators_.size());
assert(static_cast<size_t>(current_map_generator_) < map_generators_.size());
return map_generators_[current_map_generator_];
}

View file

@ -833,7 +833,7 @@ unsigned tgrid::get_best_row_height(const unsigned row, const unsigned maximum_h
const tchild& cell = child(row, x);
const tpoint size = cell.get_best_size(tpoint(0, maximum_height));
if(required_height == 0 || size.y > required_height) {
if(required_height == 0 || static_cast<size_t>(size.y) > required_height) {
required_height = size.y;
}
}

View file

@ -287,7 +287,7 @@ twidget* tlistbox::find_widget(const tpoint& coordinate, const bool must_be_acti
int offset = 0;
const size_t row = row_at_offset(coordinate.y - list_rect_.y, offset);
if(row == -1) {
if(row == static_cast<size_t>(-1)) {
return NULL;
}
@ -311,7 +311,7 @@ const twidget* tlistbox::find_widget(
int offset = 0;
const size_t row = row_at_offset(coordinate.y - list_rect_.y, offset);
if(row == -1) {
if(row == static_cast<size_t>(-1)) {
return NULL;
}

View file

@ -191,15 +191,15 @@ bool tslider::on_positioner(const tpoint& coordinate) const
int tslider::on_bar(const tpoint& coordinate) const
{
// Not on the widget, leave.
if(coordinate.x < 0 || coordinate.x > get_width()
|| coordinate.y < 0 || coordinate.y > get_height()) {
if(static_cast<size_t>(coordinate.x) > get_width()
|| static_cast<size_t>(coordinate.y) > get_height()) {
return 0;
}
// we also assume the bar is over the entire height of the widget.
if(coordinate.x < get_positioner_offset()) {
if(static_cast<size_t>(coordinate.x) < get_positioner_offset()) {
return -1;
} else if(coordinate.x >get_positioner_offset() + get_positioner_length()) {
} else if(static_cast<size_t>(coordinate.x) >get_positioner_offset() + get_positioner_length()) {
return 1;
} else {
return 0;

View file

@ -319,7 +319,7 @@ void ttext_::set_selection_start(const size_t selection_start)
}
}
void ttext_::set_selection_length(const unsigned selection_length)
void ttext_::set_selection_length(const int selection_length)
{
if(selection_length != selection_length_) {
selection_length_ = selection_length;
@ -353,7 +353,7 @@ void ttext_::handle_key_right_arrow(SDLMod modifier, bool& handled)
DBG_G_E << "Text: key press: right arrow.\n";
handled = true;
const int offset = selection_start_ + 1 + selection_length_;
const size_t offset = selection_start_ + 1 + selection_length_;
if(offset <= text_.get_length()) {
set_cursor(offset, modifier & KMOD_SHIFT);
}

View file

@ -184,7 +184,7 @@ protected:
void set_selection_start(const size_t selection_start);
size_t get_selection_length() const { return selection_length_; }
void set_selection_length(const unsigned selection_length);
void set_selection_length(const int selection_length);
private:

View file

@ -86,15 +86,15 @@ bool tvertical_scrollbar::on_positioner(const tpoint& coordinate) const
int tvertical_scrollbar::on_bar(const tpoint& coordinate) const
{
// Not on the widget, leave.
if(coordinate.x < 0 || coordinate.x > get_width()
|| coordinate.y < 0 || coordinate.y > get_height()) {
if(static_cast<size_t>(coordinate.x) > get_width()
|| static_cast<size_t>(coordinate.y) > get_height()) {
return 0;
}
// we also assume the bar is over the entire width of the widget.
if(coordinate.y < get_positioner_offset()) {
if(static_cast<size_t>(coordinate.y) < get_positioner_offset()) {
return -1;
} else if(coordinate.y >get_positioner_offset() + get_positioner_length()) {
} else if(static_cast<size_t>(coordinate.y) >get_positioner_offset() + get_positioner_length()) {
return 1;
} else {
return 0;

View file

@ -111,7 +111,7 @@ void tvertical_scrollbar_container_::key_press(tevent_handler& /*event*/,
select_row(row);
handled = true;
if(row < sb->get_item_position()) {
if(static_cast<size_t>(row) < sb->get_item_position()) {
sb->set_item_position(row);
set_scrollbar_button_status();
}
@ -121,7 +121,7 @@ void tvertical_scrollbar_container_::key_press(tevent_handler& /*event*/,
case SDLK_PAGEDOWN :
row += sb->get_visible_items() - 1;
if(row + 1 >= sb->get_item_count()) {
if(static_cast<size_t>(row + 1) >= sb->get_item_count()) {
row = sb->get_item_count() - 2;
}
// FALL DOWN
@ -129,13 +129,13 @@ void tvertical_scrollbar_container_::key_press(tevent_handler& /*event*/,
case SDLK_DOWN :
++row;
while(row < sb->get_item_count() && !get_item_active(row)) {
while(static_cast<size_t>(row) < sb->get_item_count() && !get_item_active(row)) {
++row;
}
if(row < sb->get_item_count()) {
if(static_cast<size_t>(row) < sb->get_item_count()) {
select_row(row);
handled = true;
if(row >= sb->get_item_position() + sb->get_visible_items()) {
if(static_cast<size_t>(row) >= sb->get_item_position() + sb->get_visible_items()) {
sb->set_item_position(row + 1 - sb->get_visible_items());
set_scrollbar_button_status();

View file

@ -390,8 +390,8 @@ void twindow::layout()
<< settings::screen_width << ',' << settings::screen_height << ".\n";
// If too big try it gracefully.
if(size.x > settings::screen_width
|| size.y > settings::screen_height) {
if(static_cast<size_t>(size.x) > settings::screen_width
|| static_cast<size_t>(size.y) > settings::screen_height) {
size = get_best_size(
tpoint(settings::screen_width, settings::screen_height));

View file

@ -848,7 +848,7 @@ void precache_file_existence(const std::string& subdir)
template<typename T>
cache_item<T>& cache_type<T>::get_element(int index){
assert (index != -1);
while(index >= content_.size()) {
while(static_cast<size_t>(index) >= content_.size()) {
content_.push_back(cache_item<T>());
}
cache_item<T>& elt = content_[index];

View file

@ -265,7 +265,7 @@ static void wesnoth_setlocale(int category, std::string slocale,
orig_locale.assign(locale);
typedef boost::scoped_array<char> char_array;
int length = orig_locale.length()+1;
size_t length = orig_locale.length()+1;
char_array try_loc(new char[length]);
orig_locale.copy(try_loc.get(), orig_locale.length());
try_loc[orig_locale.length()] = 0;
@ -287,7 +287,10 @@ static void wesnoth_setlocale(int category, std::string slocale,
if (i == alternates->end()) break;
orig_locale = *i + extra;
if (length < orig_locale.length()+1)
try_loc.reset(new char[orig_locale.length()+1]);
{
length = orig_locale.length()+1;
try_loc.reset(new char[length]);
}
orig_locale.copy(try_loc.get(), orig_locale.length());
try_loc[orig_locale.length()] = 0;
i++;

View file

@ -254,7 +254,7 @@ void wait::join_game(bool observe)
}
}
}
if (side_choice < 0 || side_choice >= sides_list.size()) {
if (static_cast<size_t>(side_choice) >= sides_list.size()) {
join_game(true);
return;
}

View file

@ -646,7 +646,7 @@ void server::run() {
}
// Send network stats every hour
static size_t prev_hour = localtime(&now)->tm_hour;
static int prev_hour = localtime(&now)->tm_hour;
if (prev_hour != localtime(&now)->tm_hour)
{
prev_hour = localtime(&now)->tm_hour;

View file

@ -245,12 +245,12 @@ WESNOTH_PARAMETERIZED_TEST_CASE( test_multi_sendfile, sendfile_param, sendfile_s
std::vector<char> data;
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
BOOST_CHECK_EQUAL(data.size(), file_size(file));
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(file_size(file)));
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
BOOST_CHECK_EQUAL(data.size(), file_size(file));
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(file_size(file)));
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
BOOST_CHECK_EQUAL(data.size(), file_size(file));
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(file_size(file)));
network::disconnect(cl_client1);
network::disconnect(cl_client2);

View file

@ -179,7 +179,7 @@ gui2::tpoint ttext::get_cursor_position(
// Go the the wanted line.
if(line != 0) {
if(pango_layout_get_line_count(layout_) >= line) {
if(pango_layout_get_line_count(layout_) >= static_cast<int>(line)) {
return gui2::tpoint(0, 0);
}