From 02bd7badabc6c527aa5834b4032412e5d9c773f4 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Mon, 16 Sep 2019 17:57:25 +0300
Subject: [PATCH] More cppcheck error removals

---
 applications/groupview/src/main.cpp           |  3 +-
 .../include/ftl/cuda_matrix_util.hpp          |  1 +
 applications/reconstruct/src/dibr.cu          | 17 +++++------
 components/codecs/src/nvpipe_encoder.cpp      |  2 --
 components/common/cpp/src/configuration.cpp   |  2 +-
 components/common/cpp/src/uri.cpp             |  5 ++--
 components/rgbd-sources/src/snapshot.cpp      |  2 +-
 components/rgbd-sources/test/channel_unit.cpp | 12 ++++----
 components/rgbd-sources/test/source_unit.cpp  | 28 +++++++++----------
 9 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/applications/groupview/src/main.cpp b/applications/groupview/src/main.cpp
index 99820d759..6b32221ef 100644
--- a/applications/groupview/src/main.cpp
+++ b/applications/groupview/src/main.cpp
@@ -110,11 +110,12 @@ void modeLeftRight(ftl::Configurable *root) {
 	});
 	
 	int idx = 0;
-	int key;
 
 	Mat show;
 	
 	while (ftl::running) {
+		int key;
+		
 		while (!new_frames) {
 			for (auto src : sources) { src->grab(30); }
 			key = cv::waitKey(10);
diff --git a/applications/reconstruct/include/ftl/cuda_matrix_util.hpp b/applications/reconstruct/include/ftl/cuda_matrix_util.hpp
index e8d803e6f..4dd1db7fa 100644
--- a/applications/reconstruct/include/ftl/cuda_matrix_util.hpp
+++ b/applications/reconstruct/include/ftl/cuda_matrix_util.hpp
@@ -1606,6 +1606,7 @@ inline __device__ __host__ matNxM<2, 2> matNxM<2, 2>::getInverse() const
 
 // To Matrix from floatNxN
 template<>
+// cppcheck-suppress syntaxError
 template<>
 inline __device__ __host__  matNxM<1, 1>::matNxM(const float& other)
 {
diff --git a/applications/reconstruct/src/dibr.cu b/applications/reconstruct/src/dibr.cu
index fade36343..66428ce30 100644
--- a/applications/reconstruct/src/dibr.cu
+++ b/applications/reconstruct/src/dibr.cu
@@ -158,8 +158,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp
 	const int upsample = min(UPSAMPLE_MAX, int((r) * params.camera.fx / camPos.z));
 
 	// Not on screen so stop now...
-	if (screenPos.x + upsample < 0 || screenPos.y + upsample < 0 ||
-            screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return;
+	if (screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return;
             
     // TODO:(Nick) Check depth buffer and don't do anything if already hidden?
 
@@ -181,7 +180,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp
 		// and depth remains within the bounds.
 		// How to find min and max depths?
 
-        float ld = nearest.z;
+        //float ld = nearest.z;
 
 		// TODO: (Nick) Estimate depth using points plane, but needs better normals.
 		//float t;
@@ -241,7 +240,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp
                 }*/
 
                 //nearest = params.camera.kinectDepthToSkeleton(screenPos.x+u,screenPos.y+v,d);  // ld + (d - ld)*0.8f
-                ld = d;
+                //ld = d;
 			}
 		//}
 	}
@@ -287,8 +286,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp
 	const int upsample = min(UPSAMPLE_MAX, int((4.0f*r) * params.camera.fx / camPos.z));
 
 	// Not on screen so stop now...
-	if (screenPos.x + upsample < 0 || screenPos.y + upsample < 0 ||
-            screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return;
+	if (screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return;
             
 	// TODO:(Nick) Check depth buffer and don't do anything if already hidden?
 	
@@ -575,7 +573,7 @@ __global__ void dibr_attribute_contrib_kernel(
 	const ftl::voxhash::DepthCameraCUDA &camera = c_cameras[cam];
 
 	const int tid = (threadIdx.x + threadIdx.y * blockDim.x);
-	const int warp = tid / WARP_SIZE;
+	//const int warp = tid / WARP_SIZE;
 	const int x = (blockIdx.x*blockDim.x + threadIdx.x) / WARP_SIZE;
 	const int y = blockIdx.y*blockDim.y + threadIdx.y;
 
@@ -592,8 +590,7 @@ __global__ void dibr_attribute_contrib_kernel(
     const int upsample = 8; //min(UPSAMPLE_MAX, int((5.0f*r) * params.camera.fx / camPos.z));
 
 	// Not on screen so stop now...
-	if (screenPos.x < 0 || screenPos.y < 0 ||
-            screenPos.x >= depth_in.width() || screenPos.y >= depth_in.height()) return;
+	if (screenPos.x >= depth_in.width() || screenPos.y >= depth_in.height()) return;
             
     // Is this point near the actual surface and therefore a contributor?
     const float d = ((float)depth_in.tex2D((int)screenPos.x, (int)screenPos.y)/1000.0f);
@@ -722,7 +719,7 @@ void ftl::cuda::dibr(const TextureObject<int> &depth_out,
 	cudaSafeCall(cudaDeviceSynchronize());
 #endif
 
-	int i=3;
+	//int i=3;
 
 	bool noSplatting = params.m_flags & ftl::render::kNoSplatting;
 
diff --git a/components/codecs/src/nvpipe_encoder.cpp b/components/codecs/src/nvpipe_encoder.cpp
index cbae706ef..e03dc7073 100644
--- a/components/codecs/src/nvpipe_encoder.cpp
+++ b/components/codecs/src/nvpipe_encoder.cpp
@@ -30,8 +30,6 @@ void NvPipeEncoder::reset() {
 
 /* Check preset resolution is not better than actual resolution. */
 definition_t NvPipeEncoder::_verifiedDefinition(definition_t def, const cv::Mat &in) {
-	bool is_float = in.type() == CV_32F;
-
 	int height = ftl::codecs::getHeight(def);
 
 	// FIXME: Make sure this can't go forever
diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp
index 476b09cab..8a3849e8e 100644
--- a/components/common/cpp/src/configuration.cpp
+++ b/components/common/cpp/src/configuration.cpp
@@ -458,7 +458,7 @@ Configurable *ftl::config::configure(ftl::config::json_t &cfg) {
 	loguru::g_preamble_uptime = false;
 	loguru::g_preamble_thread = false;
 	int argc = 1;
-	const char *argv[] = {"d",0};
+	const char *argv[]{"d",0};
 	loguru::init(argc, const_cast<char**>(argv), "--verbosity");
 
 	config_index.clear();
diff --git a/components/common/cpp/src/uri.cpp b/components/common/cpp/src/uri.cpp
index 0db7a4af5..90fb33522 100644
--- a/components/common/cpp/src/uri.cpp
+++ b/components/common/cpp/src/uri.cpp
@@ -41,8 +41,9 @@ void URI::_parse(uri_t puri) {
 	// NOTE: Non-standard additions to allow for Unix style relative file names.
 	if (suri[0] == '.') {
 		char cwdbuf[1024];
-		getcwd(cwdbuf, 1024);
-		suri = string("file://") + string(cwdbuf) + suri.substr(1);
+		if (getcwd(cwdbuf, 1024)) {
+			suri = string("file://") + string(cwdbuf) + suri.substr(1);
+		}
 	} else if (suri[0] == '~') {
 #ifdef WIN32
 		suri = string("file://") + string(std::getenv("HOMEDRIVE")) + string(std::getenv("HOMEPATH")) + suri.substr(1);
diff --git a/components/rgbd-sources/src/snapshot.cpp b/components/rgbd-sources/src/snapshot.cpp
index 8ce89fa08..7a80ee677 100644
--- a/components/rgbd-sources/src/snapshot.cpp
+++ b/components/rgbd-sources/src/snapshot.cpp
@@ -169,7 +169,7 @@ bool SnapshotWriter::addRGBD(size_t source, const cv::Mat &rgb, const cv::Mat &d
 void SnapshotWriter::writeIndex() {
 	FileStorage fs(".yml", FileStorage::WRITE + FileStorage::MEMORY);
 
-	vector<string> channels = {"time", "rgb_left", "depth_left"};
+	vector<string> channels{"time", "rgb_left", "depth_left"};
 
 	fs << "sources" << sources_;
 	fs << "params" <<params_;
diff --git a/components/rgbd-sources/test/channel_unit.cpp b/components/rgbd-sources/test/channel_unit.cpp
index eb88777bd..251716785 100644
--- a/components/rgbd-sources/test/channel_unit.cpp
+++ b/components/rgbd-sources/test/channel_unit.cpp
@@ -26,7 +26,7 @@ TEST_CASE("Channel or-ing", "") {
 
         cs |= Channel::Right;
 
-        REQUIRE( cs.count() == 2 );
+        REQUIRE( (cs.count() == 2) );
         REQUIRE( cs.has(Channel::Right) );
         REQUIRE( cs.has(Channel::Depth) );
 	}
@@ -36,7 +36,7 @@ TEST_CASE("Channel or-ing", "") {
 
         cs = Channel::Right | Channel::Flow | Channel::Left;
 
-        REQUIRE( cs.count() == 3 );
+        REQUIRE( (cs.count() == 3) );
         REQUIRE( cs.has(Channel::Right) );
         REQUIRE( cs.has(Channel::Flow) );
         REQUIRE( cs.has(Channel::Left) );
@@ -45,7 +45,7 @@ TEST_CASE("Channel or-ing", "") {
     SECTION("Combine multiple channels at init") {
 		Channels cs = Channel::Right | Channel::Flow | Channel::Left;
 
-        REQUIRE( cs.count() == 3 );
+        REQUIRE( (cs.count() == 3) );
         REQUIRE( cs.has(Channel::Right) );
         REQUIRE( cs.has(Channel::Flow) );
         REQUIRE( cs.has(Channel::Left) );
@@ -58,7 +58,7 @@ TEST_CASE("Channel adding", "") {
 
         cs += Channel::Right;
 
-        REQUIRE( cs.count() == 2 );
+        REQUIRE( (cs.count() == 2) );
         REQUIRE( cs.has(Channel::Right) );
         REQUIRE( cs.has(Channel::Depth) );
 	}
@@ -68,7 +68,7 @@ TEST_CASE("Channel adding", "") {
 
         cs = Channel::Right + Channel::Flow + Channel::Left;
 
-        REQUIRE( cs.count() == 3 );
+        REQUIRE( (cs.count() == 3) );
         REQUIRE( cs.has(Channel::Right) );
         REQUIRE( cs.has(Channel::Flow) );
         REQUIRE( cs.has(Channel::Left) );
@@ -81,7 +81,7 @@ TEST_CASE("Channel subtracting", "") {
 
         cs -= Channel::Flow;
 
-        REQUIRE( cs.count() == 2 );
+        REQUIRE( (cs.count() == 2) );
         REQUIRE( cs.has(Channel::Right) );
         REQUIRE( cs.has(Channel::Left) );
 	}
diff --git a/components/rgbd-sources/test/source_unit.cpp b/components/rgbd-sources/test/source_unit.cpp
index 4b14bee18..dca38be2f 100644
--- a/components/rgbd-sources/test/source_unit.cpp
+++ b/components/rgbd-sources/test/source_unit.cpp
@@ -14,7 +14,7 @@ class Snapshot {};
 
 class SnapshotReader {
 	public:
-	SnapshotReader(const std::string &) {}
+	explicit SnapshotReader(const std::string &) {}
 	Snapshot readArchive() { return Snapshot(); };
 };
 
@@ -22,7 +22,7 @@ namespace detail {
 
 class ImageSource : public ftl::rgbd::detail::Source {
 	public:
-	ImageSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
+	explicit ImageSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
 		last_type = "image";
 	}
 	ImageSource(ftl::rgbd::Source *host, const std::string &f) : ftl::rgbd::detail::Source(host) {
@@ -37,7 +37,7 @@ class ImageSource : public ftl::rgbd::detail::Source {
 
 class StereoVideoSource : public ftl::rgbd::detail::Source {
 	public:
-	StereoVideoSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
+	explicit StereoVideoSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
 		last_type = "video";
 	}
 	StereoVideoSource(ftl::rgbd::Source *host, const std::string &f) : ftl::rgbd::detail::Source(host) {
@@ -52,7 +52,7 @@ class StereoVideoSource : public ftl::rgbd::detail::Source {
 
 class NetSource : public ftl::rgbd::detail::Source {
 	public:
-	NetSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
+	explicit NetSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
 		last_type = "net";
 	}
 
@@ -76,7 +76,7 @@ class SnapshotSource : public ftl::rgbd::detail::Source {
 
 class RealsenseSource : public ftl::rgbd::detail::Source {
 	public:
-	RealsenseSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
+	explicit RealsenseSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) {
 		last_type = "realsense";
 	}
 
@@ -122,11 +122,11 @@ using ftl::rgbd::Source;
 using ftl::config::json_t;
 
 TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
-	json_t global = {{"$id","ftl://test"}};
+	json_t global = json_t{{"$id","ftl://test"}};
 	ftl::config::configure(global);
 
 	SECTION("with valid image file uri") {
-		json_t cfg = {
+		json_t cfg = json_t{
 			{"$id","ftl://test/1"},
 			{"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/image.png"}
 		};
@@ -139,7 +139,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
 	}
 
 	SECTION("with valid video file uri") {
-		json_t cfg = {
+		json_t cfg = json_t{
 			{"$id","ftl://test/2"},
 			{"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/video.mp4"}
 		};
@@ -152,7 +152,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
 	}
 
 	SECTION("with valid net uri") {
-		json_t cfg = {
+		json_t cfg = json_t{
 			{"$id","ftl://test/2"},
 			{"uri","ftl://utu.fi/dummy"}
 		};
@@ -165,7 +165,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
 	}
 
 	SECTION("with an invalid uri") {
-		json_t cfg = {
+		json_t cfg = json_t{
 			{"$id","ftl://test/2"},
 			{"uri","not a uri"}
 		};
@@ -177,7 +177,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
 	}
 
 	SECTION("with an invalid file uri") {
-		json_t cfg = {
+		json_t cfg = json_t{
 			{"$id","ftl://test/2"},
 			{"uri","file:///not/a/file"}
 		};
@@ -189,7 +189,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
 	}
 
 	SECTION("with a missing file") {
-		json_t cfg = {
+		json_t cfg = json_t{
 			{"$id","ftl://test/2"},
 			{"uri","file:///data/image2.png"}
 		};
@@ -202,11 +202,11 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") {
 }
 
 TEST_CASE("Source::set(uri)", "[rgbd]") {
-	json_t global = {{"$id","ftl://test"}};
+	json_t global = json_t{{"$id","ftl://test"}};
 	ftl::config::configure(global);
 
 	SECTION("change to different valid URI type") {
-		json_t cfg = {
+		json_t cfg = json_t{
 			{"$id","ftl://test/1"},
 			{"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/image.png"}
 		};
-- 
GitLab