From 05f604f5b6dda046edc38d583c2561475eb416bd Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Tue, 7 May 2019 18:19:00 +0300
Subject: [PATCH] Code tidy to remove warnings

---
 CMakeLists.txt                   |  2 +-
 net/cpp/src/dispatcher.cpp       |  4 ++--
 net/cpp/test/net_integration.cpp |  1 +
 net/cpp/test/peer_unit.cpp       |  6 ++---
 net/cpp/test/uri_unit.cpp        |  6 ++---
 vision/include/ftl/calibrate.hpp |  7 +++++-
 vision/include/ftl/local.hpp     |  2 +-
 vision/lib/elas/triangle.cpp     | 38 ++++++++++++++++----------------
 vision/src/algorithms/elas.cpp   |  2 +-
 vision/src/calibrate.cpp         |  8 ++-----
 10 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f0e730d44..08daad6b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -99,7 +99,7 @@ check_include_file_cxx("opencv2/cudastereo.hpp" HAVE_OPENCVCUDA)
 find_program(CPPCHECK_FOUND cppcheck)
 if (CPPCHECK_FOUND)
 	message(STATUS "Found cppcheck: will perform source checks")
-	set(CMAKE_CXX_CPPCHECK "cppcheck" "--enable=style" "--suppress=*:*catch.hpp" "--suppress=*:*json.hpp")
+	set(CMAKE_CXX_CPPCHECK "cppcheck" "--enable=style" "--suppress=*:*catch.hpp" "--suppress=*:*elas*" "--suppress=*:*json.hpp")
 endif()
 
 include_directories(${PROJECT_SOURCE_DIR}/common/cpp/include)
diff --git a/net/cpp/src/dispatcher.cpp b/net/cpp/src/dispatcher.cpp
index 269db7a6d..a2dfd5ad6 100644
--- a/net/cpp/src/dispatcher.cpp
+++ b/net/cpp/src/dispatcher.cpp
@@ -136,8 +136,8 @@ void ftl::net::Dispatcher::dispatch_notification(Peer &s, msgpack::object const
     if (binding) {
         try {
             auto result = (*binding)(args);
-        } catch (int e) {
-			throw e;
+        } catch (const int &e) {
+			throw &e;
 		}
     } else {
     	LOG(ERROR) << "Missing handler for incoming message";
diff --git a/net/cpp/test/net_integration.cpp b/net/cpp/test/net_integration.cpp
index 9197bab23..87a23ee27 100644
--- a/net/cpp/test/net_integration.cpp
+++ b/net/cpp/test/net_integration.cpp
@@ -91,6 +91,7 @@ TEST_CASE("Universe::broadcast()", "[net]") {
 		b.broadcast("done");
 		
 		sleep_for(milliseconds(100));
+		REQUIRE( !done );
 	}
 	
 	SECTION("no arguments to one peer") {
diff --git a/net/cpp/test/peer_unit.cpp b/net/cpp/test/peer_unit.cpp
index b7bebbcb1..583f615d4 100644
--- a/net/cpp/test/peer_unit.cpp
+++ b/net/cpp/test/peer_unit.cpp
@@ -185,7 +185,7 @@ TEST_CASE("Peer(int)", "[]") {
 		
 		sleep_for(milliseconds(50));
 		
-		REQUIRE( s.getFTLVersion() ==  (8 << 16) + (5 << 8) + 2 );
+		REQUIRE( (s.getFTLVersion() ==  (8 << 16) + (5 << 8) + 2) );
 	}
 	
 	SECTION("has correct peer id on full handshake") {
@@ -342,7 +342,7 @@ TEST_CASE("Peer::bind()", "[rpc]") {
 		sleep_for(milliseconds(50));
 		
 		REQUIRE( (done == 55) );
-		REQUIRE( readRPCReturn<int>(0) == 55 );
+		REQUIRE( (readRPCReturn<int>(0) == 55) );
 	}
 
 	SECTION("vector return value") {		
@@ -361,7 +361,7 @@ TEST_CASE("Peer::bind()", "[rpc]") {
 		REQUIRE( (done == 55) );
 
 		auto res = readRPCReturn<vector<int>>(0);
-		REQUIRE( res[1] == 45 );
+		REQUIRE( (res[1] == 45) );
 	}
 }
 
diff --git a/net/cpp/test/uri_unit.cpp b/net/cpp/test/uri_unit.cpp
index e11b320f4..a9fde4e80 100644
--- a/net/cpp/test/uri_unit.cpp
+++ b/net/cpp/test/uri_unit.cpp
@@ -21,8 +21,8 @@ SCENARIO( "URI() can parse valid URIs", "[utility]" ) {
 		REQUIRE( uri.isValid() );
 		REQUIRE( uri.getScheme() == URI::SCHEME_HTTP );
 		REQUIRE( uri.getHost() == "localhost" );
-		REQUIRE( uri.getPort() == 8080 );
-		REQUIRE (uri.getPath() == "/test/case.html" );
+		REQUIRE( (uri.getPort() == 8080) );
+		REQUIRE( uri.getPath() == "/test/case.html" );
 	}
 
 	GIVEN( "a valid scheme with path and query" ) {
@@ -85,7 +85,7 @@ SCENARIO( "URI::getAttribute() from query" ) {
 
 	GIVEN( "an integer value" ) {
 		URI uri("http://localhost:1000/hello?x=56");
-		REQUIRE( uri.getAttribute<int>("x") == 56 );
+		REQUIRE( (uri.getAttribute<int>("x") == 56) );
 	}
 }
 
diff --git a/vision/include/ftl/calibrate.hpp b/vision/include/ftl/calibrate.hpp
index 79fb310b3..83a2bd9c1 100644
--- a/vision/include/ftl/calibrate.hpp
+++ b/vision/include/ftl/calibrate.hpp
@@ -29,7 +29,12 @@ class Calibrate {
 	// TODO(nick) replace or remove this class.
 	class Settings {
 		public:
-		Settings() : goodInput(false) {}
+		Settings() : calibrationPattern(CHESSBOARD), squareSize(50.0f),
+			nrFrames(30), aspectRatio(1.0f), delay(100), writePoints(false), writeExtrinsics(true),
+			writeGrid(false), calibZeroTangentDist(false), calibFixPrincipalPoint(true),
+			flipVertical(false), showUndistorsed(true), useFisheye(false), fixK1(false),
+			fixK2(false), fixK3(false), fixK4(false), fixK5(false), cameraID(0), atImageList(0),
+			inputType(INVALID), goodInput(false), flag(0) {}
 		enum Pattern { NOT_EXISTING, CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };
 		enum InputType { INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST };
 
diff --git a/vision/include/ftl/local.hpp b/vision/include/ftl/local.hpp
index 80b527cc7..9a4204e65 100644
--- a/vision/include/ftl/local.hpp
+++ b/vision/include/ftl/local.hpp
@@ -12,7 +12,7 @@ namespace cv {
 namespace ftl {
 class LocalSource {
 	public:
-	LocalSource(nlohmann::json &config);
+	explicit LocalSource(nlohmann::json &config);
 	LocalSource(const std::string &vid, nlohmann::json &config);
 	
 	bool left(cv::Mat &m);
diff --git a/vision/lib/elas/triangle.cpp b/vision/lib/elas/triangle.cpp
index 8de1557bc..14d4a2d03 100644
--- a/vision/lib/elas/triangle.cpp
+++ b/vision/lib/elas/triangle.cpp
@@ -1419,27 +1419,27 @@ void printtriangle(struct mesh *m, struct behavior *b, struct otri *t)
   struct osub printsh;
   vertex printvertex;
 
-  printf("triangle x%lx with orientation %d:\n", (unsigned long long) t->tri,
+  printf("triangle x%lx with orientation %d:\n", (unsigned long) t->tri,
          t->orient);
   decode(t->tri[0], printtri);
   if (printtri.tri == m->dummytri) {
     printf("    [0] = Outer space\n");
   } else {
-    printf("    [0] = x%lx  %d\n", (unsigned long long) printtri.tri,
+    printf("    [0] = x%lx  %d\n", (unsigned long) printtri.tri,
            printtri.orient);
   }
   decode(t->tri[1], printtri);
   if (printtri.tri == m->dummytri) {
     printf("    [1] = Outer space\n");
   } else {
-    printf("    [1] = x%lx  %d\n", (unsigned long long) printtri.tri,
+    printf("    [1] = x%lx  %d\n", (unsigned long) printtri.tri,
            printtri.orient);
   }
   decode(t->tri[2], printtri);
   if (printtri.tri == m->dummytri) {
     printf("    [2] = Outer space\n");
   } else {
-    printf("    [2] = x%lx  %d\n", (unsigned long long) printtri.tri,
+    printf("    [2] = x%lx  %d\n", (unsigned long) printtri.tri,
            printtri.orient);
   }
 
@@ -1448,37 +1448,37 @@ void printtriangle(struct mesh *m, struct behavior *b, struct otri *t)
     printf("    Origin[%d] = NULL\n", (t->orient + 1) % 3 + 3);
   else
     printf("    Origin[%d] = x%lx  (%.12g, %.12g)\n",
-           (t->orient + 1) % 3 + 3, (unsigned long long) printvertex,
+           (t->orient + 1) % 3 + 3, (unsigned long) printvertex,
            printvertex[0], printvertex[1]);
   dest(*t, printvertex);
   if (printvertex == (vertex) NULL)
     printf("    Dest  [%d] = NULL\n", (t->orient + 2) % 3 + 3);
   else
     printf("    Dest  [%d] = x%lx  (%.12g, %.12g)\n",
-           (t->orient + 2) % 3 + 3, (unsigned long long) printvertex,
+           (t->orient + 2) % 3 + 3, (unsigned long) printvertex,
            printvertex[0], printvertex[1]);
   apex(*t, printvertex);
   if (printvertex == (vertex) NULL)
     printf("    Apex  [%d] = NULL\n", t->orient + 3);
   else
     printf("    Apex  [%d] = x%lx  (%.12g, %.12g)\n",
-           t->orient + 3, (unsigned long long) printvertex,
+           t->orient + 3, (unsigned long) printvertex,
            printvertex[0], printvertex[1]);
 
   if (b->usesegments) {
     sdecode(t->tri[6], printsh);
     if (printsh.ss != m->dummysub) {
-      printf("    [6] = x%lx  %d\n", (unsigned long long) printsh.ss,
+      printf("    [6] = x%lx  %d\n", (unsigned long) printsh.ss,
              printsh.ssorient);
     }
     sdecode(t->tri[7], printsh);
     if (printsh.ss != m->dummysub) {
-      printf("    [7] = x%lx  %d\n", (unsigned long long) printsh.ss,
+      printf("    [7] = x%lx  %d\n", (unsigned long) printsh.ss,
              printsh.ssorient);
     }
     sdecode(t->tri[8], printsh);
     if (printsh.ss != m->dummysub) {
-      printf("    [8] = x%lx  %d\n", (unsigned long long) printsh.ss,
+      printf("    [8] = x%lx  %d\n", (unsigned long) printsh.ss,
              printsh.ssorient);
     }
   }
@@ -1506,19 +1506,19 @@ void printsubseg(struct mesh *m, struct behavior *b, struct osub *s)
   vertex printvertex;
 
   printf("subsegment x%lx with orientation %d and mark %d:\n",
-         (unsigned long long) s->ss, s->ssorient, mark(*s));
+         (unsigned long) s->ss, s->ssorient, mark(*s));
   sdecode(s->ss[0], printsh);
   if (printsh.ss == m->dummysub) {
     printf("    [0] = No subsegment\n");
   } else {
-    printf("    [0] = x%lx  %d\n", (unsigned long long) printsh.ss,
+    printf("    [0] = x%lx  %d\n", (unsigned long) printsh.ss,
            printsh.ssorient);
   }
   sdecode(s->ss[1], printsh);
   if (printsh.ss == m->dummysub) {
     printf("    [1] = No subsegment\n");
   } else {
-    printf("    [1] = x%lx  %d\n", (unsigned long long) printsh.ss,
+    printf("    [1] = x%lx  %d\n", (unsigned long) printsh.ss,
            printsh.ssorient);
   }
 
@@ -1527,28 +1527,28 @@ void printsubseg(struct mesh *m, struct behavior *b, struct osub *s)
     printf("    Origin[%d] = NULL\n", 2 + s->ssorient);
   else
     printf("    Origin[%d] = x%lx  (%.12g, %.12g)\n",
-           2 + s->ssorient, (unsigned long long) printvertex,
+           2 + s->ssorient, (unsigned long) printvertex,
            printvertex[0], printvertex[1]);
   sdest(*s, printvertex);
   if (printvertex == (vertex) NULL)
     printf("    Dest  [%d] = NULL\n", 3 - s->ssorient);
   else
     printf("    Dest  [%d] = x%lx  (%.12g, %.12g)\n",
-           3 - s->ssorient, (unsigned long long) printvertex,
+           3 - s->ssorient, (unsigned long) printvertex,
            printvertex[0], printvertex[1]);
 
   decode(s->ss[6], printtri);
   if (printtri.tri == m->dummytri) {
     printf("    [6] = Outer space\n");
   } else {
-    printf("    [6] = x%lx  %d\n", (unsigned long long) printtri.tri,
+    printf("    [6] = x%lx  %d\n", (unsigned long) printtri.tri,
            printtri.orient);
   }
   decode(s->ss[7], printtri);
   if (printtri.tri == m->dummytri) {
     printf("    [7] = Outer space\n");
   } else {
-    printf("    [7] = x%lx  %d\n", (unsigned long long) printtri.tri,
+    printf("    [7] = x%lx  %d\n", (unsigned long) printtri.tri,
            printtri.orient);
   }
 
@@ -1557,14 +1557,14 @@ void printsubseg(struct mesh *m, struct behavior *b, struct osub *s)
     printf("    Segment origin[%d] = NULL\n", 4 + s->ssorient);
   else
     printf("    Segment origin[%d] = x%lx  (%.12g, %.12g)\n",
-           4 + s->ssorient, (unsigned long long) printvertex,
+           4 + s->ssorient, (unsigned long) printvertex,
            printvertex[0], printvertex[1]);
   segdest(*s, printvertex);
   if (printvertex == (vertex) NULL)
     printf("    Segment dest  [%d] = NULL\n", 5 - s->ssorient);
   else
     printf("    Segment dest  [%d] = x%lx  (%.12g, %.12g)\n",
-           5 - s->ssorient, (unsigned long long) printvertex,
+           5 - s->ssorient, (unsigned long) printvertex,
            printvertex[0], printvertex[1]);
 }
 
diff --git a/vision/src/algorithms/elas.cpp b/vision/src/algorithms/elas.cpp
index ca3735744..b99c309c9 100644
--- a/vision/src/algorithms/elas.cpp
+++ b/vision/src/algorithms/elas.cpp
@@ -35,7 +35,7 @@ void ELAS::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) {
 	disp = Mat(cv::Size(l.cols, l.rows), CV_32F);
 	Mat dispr(cv::Size(l.cols, l.rows), CV_32F);
 	
-	const int32_t dims[3] = {l.cols,l.rows,lbw.step};
+	const int32_t dims[3] = {l.cols,l.rows,static_cast<int32_t>(lbw.step)};
 	
 	if (disp.step/sizeof(float) != lbw.step) LOG(WARNING) << "Incorrect disparity step";
 
diff --git a/vision/src/calibrate.cpp b/vision/src/calibrate.cpp
index 7151a01bb..e5025a9d8 100644
--- a/vision/src/calibrate.cpp
+++ b/vision/src/calibrate.cpp
@@ -491,7 +491,7 @@ static double computeReprojectionErrors(
 		vector<float>& perViewErrors, bool fisheye) {
     vector<Point2f> imagePoints2;
     size_t totalPoints = 0;
-    double totalErr = 0, err;
+    double totalErr = 0;
     perViewErrors.resize(objectPoints.size());
 
     for (size_t i = 0; i < objectPoints.size(); ++i) {
@@ -502,7 +502,7 @@ static double computeReprojectionErrors(
             projectPoints(objectPoints[i], rvecs[i], tvecs[i], cameraMatrix,
             		distCoeffs, imagePoints2);
         }
-        err = norm(imagePoints[i], imagePoints2, NORM_L2);
+        double err = norm(imagePoints[i], imagePoints2, NORM_L2);
 
         size_t n = objectPoints[i].size();
         perViewErrors[i] = static_cast<float>(std::sqrt(err*err/n));
@@ -576,10 +576,6 @@ static bool _runCalibration(const Calibrate::Settings& s, Size& imageSize,
             tvecs.push_back(_tvecs.row(i));
         }
     } else {
-        int iFixedPoint = -1;
-        if (release_object)
-            iFixedPoint = s.boardSize.width - 1;
-
         rms = calibrateCamera(objectPoints, imagePoints, imageSize,
                                 cameraMatrix, distCoeffs, rvecs, tvecs,
                                 s.flag | CALIB_USE_LU);
-- 
GitLab