← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1782377-compiler-error into lp:widelands

 

Klaus Halfmann has proposed merging lp:~widelands-dev/widelands/bug-1782377-compiler-error into lp:widelands.

Commit message:
Fix for Bug#1782377 

Requested reviews:
  GunChleoc (gunchleoc)
Related bugs:
  Bug #1782377 in widelands: "Compile error in bzr8754[trunk] save_handler.cc on OSX"
  https://bugs.launchpad.net/widelands/+bug/1782377

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1782377-compiler-error/+merge/349831

Fix compiler error in src/logic/player.cc.

As of to many auto variables the compiler (an I) got confused
how to use a iterator for a two dimensional array.

I simmplified the code to make the compiler and the codecheck happy.

I had not time to check this, yet.

Gun: in this case the codecheck did not point to a real improvement, do we really need that one?
-- 
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1782377-compiler-error.
=== modified file 'src/logic/player.cc'
--- src/logic/player.cc	2018-07-18 15:01:33 +0000
+++ src/logic/player.cc	2018-07-18 19:49:00 +0000
@@ -1482,11 +1482,12 @@
 	const auto write_stats = [&fw](
 	   const std::vector<std::vector<uint32_t>>& stats, const DescriptionIndex ware_index) {
 		std::ostringstream oss("");
-		if (!stats[ware_index].empty()) {
-			for (uint32_t i = 0; i < stats[ware_index].size() - 1; ++i) {
+		const int sizem = stats[ware_index].size() - 1;
+		if (sizem >= 0) {
+			for (int i = 0; i < sizem; ++i) {
 				oss << stats[ware_index][i] << "|";
 			}
-			oss << stats[ware_index][stats[ware_index].rbegin()];
+			oss << stats[ware_index][sizem];
 		}
 		fw.c_string(oss.str());
 	};


Follow ups