← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~hjd/widelands/cppcheck-fixes-again into lp:widelands

 

Hans Joachim Desserud has proposed merging lp:~hjd/widelands/cppcheck-fixes-again into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~hjd/widelands/cppcheck-fixes-again/+merge/240336

Ran a new cppcheck release and fixed a couple of low hanging fruits.
-- 
https://code.launchpad.net/~hjd/widelands/cppcheck-fixes-again/+merge/240336
Your team Widelands Developers is requested to review the proposed merge of lp:~hjd/widelands/cppcheck-fixes-again into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2014-10-31 19:09:53 +0000
+++ src/ai/defaultai.cc	2014-10-31 20:52:17 +0000
@@ -2203,7 +2203,6 @@
 	if (enhancement != INVALID_INDEX && (site.bo->cnt_built_ - site.bo->unoccupied_) > 1) {
 
 		BuildingIndex enbld = INVALID_INDEX;  // to get rid of this
-		BuildingObserver* bestbld = nullptr;
 
 		// Only enhance buildings that are allowed (scenario mode)
 		// do not do decisions to fast
@@ -2211,6 +2210,7 @@
 
 			const BuildingDescr& bld = *tribe_->get_building_descr(enhancement);
 			BuildingObserver& en_bo = get_building_observer(bld.name().c_str());
+			BuildingObserver* bestbld = nullptr;
 
 			if (gametime - en_bo.construction_decision_time_ >= kBuildingMinInterval &&
 			    (en_bo.cnt_under_construction_ + en_bo.unoccupied_) == 0) {
@@ -3116,9 +3116,8 @@
 	const uint16_t attempts = militarysites.size() / 6 + 1;
 	Map& map = game().map();
 
-	uint16_t position = 0;
 	for (uint32_t i = 0; i < attempts && !any_attacked; ++i) {
-		position = (game().get_gametime() + (3 * i)) % militarysites.size();
+		const uint16_t position = (game().get_gametime() + (3 * i)) % militarysites.size();
 
 		// picking random military sites
 		// using gametime as a random value, but it is constant so each next is on position +3