Merge branch 'cppcheck'

Fixes several issues found by cppcheck, or issues found while reviewing
the issues found by cppcheck.
This commit is contained in:
Mark de Wever 2014-04-12 21:16:09 +02:00
commit 734f1be224
8 changed files with 17 additions and 24 deletions

View File

@ -308,7 +308,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
const std::map<std::string, t_string>& colors = game_config::team_rgb_name;
std::map<std::string, t_string>::const_iterator colors_it;
for (colors_it = colors.begin(); colors_it != colors.end(); colors_it++) {
for (colors_it = colors.begin(); colors_it != colors.end(); ++colors_it) {
const std::string& color_id = colors_it->first;
const t_string& color_name = colors_it->second;

View File

@ -26,7 +26,7 @@ class tcampaign_selection : public tdialog
{
public:
explicit tcampaign_selection(const std::vector<config>& campaigns)
: campaigns_(campaigns), choice_(-1)
: campaigns_(campaigns), choice_(-1), deterministic_(false)
{
}
@ -62,7 +62,7 @@ private:
/** The chosen campaign. */
int choice_;
/** whether zhe player checked teh "Deterministic" checkbox. */
/** whether the player checked the "Deterministic" checkbox. */
bool deterministic_;
};

View File

@ -1693,7 +1693,7 @@ public:
if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
std::vector<item> row;
const std::string& name = info.name();
const std::string id = info.id();
const std::string& id = info.id();
const int moves = movement_type.movement_cost(terrain);
const int views = movement_type.vision_cost(terrain);
const int jams = movement_type.jamming_cost(terrain);

View File

@ -60,11 +60,8 @@ map_labels::~map_labels()
map_labels& map_labels::operator=(const map_labels& other)
{
if(this != &other) {
team_ = other.team_;
config cfg;
other.write(cfg);
read(cfg);
this->~map_labels();
new (this) map_labels(other);
}
return *this;
}

View File

@ -14,7 +14,7 @@ static lg::log_domain log_network("network");
void playturn_network_adapter::read_from_network()
{
assert(data_.size() > 0);
assert(!data_.empty());
this->data_.push_back(config());
config& back = data_.back();
@ -48,7 +48,7 @@ void playturn_network_adapter::read_from_network()
bool playturn_network_adapter::is_at_end()
{
assert(data_.size() > 0);
assert(!data_.empty());
return this->next_ == data_.back().ordered_end();
}
@ -80,24 +80,24 @@ bool playturn_network_adapter::read(config& dst)
assert(next_->cfg.all_children_count() > next_command_num_);
config::all_children_iterator itor = child_old.ordered_begin();
//TODO: implement operator + (all_children_iterator, int ) properly
for(unsigned int i = 0; i < next_command_num_; i++) {itor++;}
std::advance(itor, next_command_num_);
//TODO: implement a non const version of ordered children
config& childchild_old = const_cast<config&>(itor->cfg);
config& childchild = child.add_child(itor->key);
childchild.swap(childchild_old);
next_command_num_++;
++next_command_num_;
if(next_->cfg.all_children_count() == next_command_num_)
{
next_command_num_ = 0;
next_++;
++next_;
}
return true;
}
else
{
child.swap(child_old);
next_++;
++next_;
return true;
}
}

View File

@ -119,9 +119,8 @@ static ucs4::string markov_generate_name(const markov_prefix_map& prefixes,
// markov prefix map. If no valid ending is found, use the
// originally generated name.
ucs4::string originalRes = res;
int prefixLen;
while(!res.empty()) {
prefixLen = chain_size < res.size() ? chain_size : res.size();
const int prefixLen = chain_size < res.size() ? chain_size : res.size();
prefix = ucs4::string(res.end() - prefixLen, res.end());
const markov_prefix_map::const_iterator i = prefixes.find(prefix);

View File

@ -435,7 +435,6 @@ void replay_controller::play_side(const unsigned int /*team_index*/, bool){
try{
// If a side is empty skip over it.
bool has_end_turn = true;
if (!current_team().is_empty()) {
statistics::reset_turn_stats(current_team().save_id());
@ -444,10 +443,8 @@ void replay_controller::play_side(const unsigned int /*team_index*/, bool){
DBG_REPLAY << "doing replay " << player_number_ << "\n";
// if have reached the end we don't want to execute finish_side_turn and finish_turn
// becasue we might not have enough data to execute them (like advancements during turn_end for example)
// !has_end_turn == we reached the end of teh replay without finding and end turn tag.
has_end_turn = do_replay(player_number_) == REPLAY_FOUND_END_TURN;
if(!has_end_turn)
{
if(do_replay(player_number_) != REPLAY_FOUND_END_TURN) {
// We reached the end of teh replay without finding and end turn tag.
return;
}
finish_side_turn();

View File

@ -276,9 +276,9 @@ size_t index(const utf8::string& str, const size_t index)
{
// chr counts characters, i is the codepoint index
// remark: several functions rely on the fallback to str.length()
unsigned int chr, i = 0, len = str.size();
unsigned int i = 0, len = str.size();
try {
for (chr=0; chr<index && i<len; ++chr) {
for (unsigned int chr=0; chr<index && i<len; ++chr) {
i += byte_size_from_utf8_first(str[i]);
}
} catch(invalid_utf8_exception&) {