From 9c33ad84278353286bbb4118cd11ca3fcfec439a Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周六, 31 10月 2020 23:36:25 +0800
Subject: [PATCH] codacy cleanup

---
 src/library/os/linux/execution_environment.cpp        |   14 ++++++--------
 /dev/null                                             |    5 -----
 src/library/hw_identifier/hw_identifier_facade.cpp    |    1 +
 src/library/hw_identifier/identification_strategy.cpp |    1 -
 src/library/os/windows/network.cpp                    |    1 -
 doc/api/extend.rst                                    |    5 ++---
 src/inspector/inspector.cpp                           |    2 +-
 src/library/os/linux/os_linux.cpp                     |    4 +++-
 .github/workflows/cpp.yml                             |    2 +-
 src/library/base/base64.cpp                           |    4 ++--
 README.md                                             |    4 ++--
 doc/index.rst                                         |    6 ++++--
 12 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml
index fdc6e2e..f118b8b 100644
--- a/.github/workflows/cpp.yml
+++ b/.github/workflows/cpp.yml
@@ -1,4 +1,4 @@
-name: Github_Actions
+name: Github_CI
 on:
    push: 
 jobs:
diff --git a/README.md b/README.md
index 051c66b..4c7012e 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,8 @@
 [![Standard](https://img.shields.io/badge/c%2B%2B-11-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization)
 [![unstable](http://badges.github.io/stability-badges/dist/unstable.svg)](http://github.com/badges/stability-badges)
 [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
-[![Build Status](https://travis-ci.org/open-license-manager/open-license-manager.svg?branch=develop)](https://travis-ci.org/open-license-manager/open-license-manager)
-![Github_Actions](https://github.com/open-license-manager/open-license-manager/workflows/Github_Actions/badge.svg)
+[![travis](https://travis-ci.org/open-license-manager/open-license-manager.svg?branch=develop)](https://travis-ci.org/open-license-manager/open-license-manager)
+[![Github_CI](https://github.com/open-license-manager/open-license-manager/workflows/Github_CI/badge.svg)](https://github.com/open-license-manager/open-license-manager/actions)
 [![Codacy Badge](https://api.codacy.com/project/badge/Grade/62d6e1bb22d648bd85b6f3bc344a545a)](https://www.codacy.com/manual/gcontini/open-license-manager?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=open-license-manager/open-license-manager&amp;utm_campaign=Badge_Grade)
 [![codecov](https://codecov.io/gh/open-license-manager/open-license-manager/branch/develop/graph/badge.svg)](https://codecov.io/gh/open-license-manager/open-license-manager)
 [![Github Issues](https://img.shields.io/github/issues/open-license-manager/open-license-manager)](http://github.com/open-license-manager/open-license-manager/issues)
diff --git a/doc/api/extend.rst b/doc/api/extend.rst
index 2521a92..d7cd17d 100644
--- a/doc/api/extend.rst
+++ b/doc/api/extend.rst
@@ -21,19 +21,18 @@
 ============================================
 
 Included with the library there are three hardware identification strategies: `IP_ADDRESS`, `STRATEGY_ETHERNET` (mac address) and 
-`STRATEGY_ETHERNET` (partition serial number). If you want to change the preferred one:
+`STRATEGY_DISK` (partition serial number). If you want to change the preferred one:
   
   - locate the file `licensecc_properties.h`` (usually in ``projects/<$project_name>/include/licensecc/<$project_name>``
   - you can change the order of the strategies in the following code block (the strategies will be tried in sequence until the first one succeeds):
 
-.. code-block:: c
 
+.. code-block:: c
 #define LCC_BARE_TO_METAL_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_ETHERNET, STRATEGY_NONE }
 #define LCC_VM_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE }
 #define LCC_LXC_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE }
 #define LCC_DOCKER_STRATEGIES { STRATEGY_NONE }
 #define LCC_CLOUD_STRATEGIES { STRATEGY_NONE }
-
 
    
 Custom license locator 
diff --git a/doc/index.rst b/doc/index.rst
index 2eeec3e..161e54d 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -11,8 +11,10 @@
 .. _unstable: http://github.com/badges/stability-badges
 .. |License| image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
 .. _License: ttps://opensource.org/licenses/BSD-3-Clause
-.. |BuildStatus| image:: https://travis-ci.org/open-license-manager/open-license-manager.svg?branch=develop
-.. _BuildStatus: https://travis-ci.org/open-license-manager/open-license-manager
+.. |TravisBuild| image:: https://travis-ci.org/open-license-manager/open-license-manager.svg?branch=develop
+.. _TravisBuild: https://travis-ci.org/open-license-manager/open-license-manager
+.. |GithubCI| image:: https://github.com/open-license-manager/open-license-manager/workflows/Github_CI/badge.svg
+.. _GithubCI: https://github.com/open-license-manager/open-license-manager/actions
 .. |CodacyBadge| image:: https://api.codacy.com/project/badge/Grade/62d6e1bb22d648bd85b6f3bc344a545a
 .. _CodacyBadge: https://www.codacy.com/manual/gcontini/open-license-manager?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=open-license-manager/open-license-manager&amp;utm_campaign=Badge_Grade
 .. |codecov| image:: https://codecov.io/gh/open-license-manager/open-license-manager/branch/develop/graph/badge.svg
diff --git a/git_rebase.sh b/git_rebase.sh
deleted file mode 100755
index 118c92a..0000000
--- a/git_rebase.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "contini.mailing@gmail.com" ]; then
-     GIT_AUTHOR_EMAIL="1121667+gcontini@users.noreply.github.com";
-     GIT_AUTHOR_NAME="gcontini";
-     GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
-     GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all
diff --git a/src/inspector/inspector.cpp b/src/inspector/inspector.cpp
index eb23c0e..c4283a1 100644
--- a/src/inspector/inspector.cpp
+++ b/src/inspector/inspector.cpp
@@ -107,7 +107,7 @@
 				 << static_cast<unsigned int>(osAdapter.ipv4_address[1]) << "-"
 				 << static_cast<unsigned int>(osAdapter.ipv4_address[0]) << "]" << endl;
 			cout << "   mac address [" << std::hex;
-			for (int i = 0; i < 8; i++) {
+			for (int i = 0; i < sizeof(osAdapter.mac_address); i++) {
 				if (i != 0) {
 					cout << ":";
 				}
diff --git a/src/library/base/base64.cpp b/src/library/base/base64.cpp
index caa0ddc..4eaf10e 100644
--- a/src/library/base/base64.cpp
+++ b/src/library/base/base64.cpp
@@ -48,7 +48,7 @@
 string base64(const void* binaryData, size_t len, int lineLenght) {
 	const unsigned char* bin = (const unsigned char*)binaryData;
 
-	int rc = 0;  // result counter
+	// int rc = 0;  // result counter
 	unsigned int byteNo;  // I need this after the loop
 
 	int modulusLen = len % 3;
@@ -108,7 +108,7 @@
 	tmp_str.erase(std::remove(tmp_str.begin(), tmp_str.end(), '\n'), tmp_str.end());
 	const unsigned char* safeAsciiPtr = (const unsigned char*)tmp_str.c_str();
 	std::vector<uint8_t> bin;
-	int cb = 0;
+	// int cb = 0;
 	unsigned int charNo;
 	int pad = 0;
 	size_t len = tmp_str.size();
diff --git a/src/library/hw_identifier/hw_identifier_facade.cpp b/src/library/hw_identifier/hw_identifier_facade.cpp
index d8c4ee0..193dfab 100644
--- a/src/library/hw_identifier/hw_identifier_facade.cpp
+++ b/src/library/hw_identifier/hw_identifier_facade.cpp
@@ -53,6 +53,7 @@
 	unique_ptr<IdentificationStrategy> strategy_ptr = IdentificationStrategy::get_strategy(strategy);
 	HwIdentifier pc_id;
 	FUNCTION_RETURN result = strategy_ptr->generate_pc_id(pc_id);
+	pc_id.set_use_environment_var(use_env_var);
 	if (result != FUNC_RET_OK) {
 		throw logic_error("strategy " + to_string(strategy_ptr->identification_strategy()) + " failed");
 	}
diff --git a/src/library/hw_identifier/identification_strategy.cpp b/src/library/hw_identifier/identification_strategy.cpp
index ad9cf46..38233d0 100644
--- a/src/library/hw_identifier/identification_strategy.cpp
+++ b/src/library/hw_identifier/identification_strategy.cpp
@@ -23,7 +23,6 @@
 }
 
 FUNCTION_RETURN IdentificationStrategy::generate_pc_id(HwIdentifier& pc_id) const {
-	vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> data;
 	const vector<HwIdentifier> available_ids = alternative_ids();
 	FUNCTION_RETURN result = FUNC_RET_NOT_AVAIL;
 	if (available_ids.size() > 0) {
diff --git a/src/library/os/linux/execution_environment.cpp b/src/library/os/linux/execution_environment.cpp
index 75520eb..1ca0cd0 100644
--- a/src/library/os/linux/execution_environment.cpp
+++ b/src/library/os/linux/execution_environment.cpp
@@ -1,9 +1,10 @@
 /*
- * virtualization.cpp
+ * execution_environment.cpp
  *
  *  Created on: Dec 15, 2019
  *      Author: GC
  */
+#define __STDC_WANT_LIB_EXT1__1
 #include <paths.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -31,10 +32,10 @@
 	char path[MAX_PATH] = {0};
 	char proc_path[MAX_PATH], pidStr[64];
 	pid_t pid = getpid();
-	sprintf(pidStr, "%d", pid);
-	strcpy(proc_path, "/proc/");
-	strcat(proc_path, pidStr);
-	strcat(proc_path, "/cgroup");
+	snprintf(pidStr, sizeof(pidStr), "%d", pid);
+	strncpy(proc_path, "/proc/", sizeof(proc_path));
+	strncat(proc_path, pidStr, sizeof(proc_path));
+	strncpy(proc_path, "/cgroup", sizeof(proc_path));
 
 	FILE *fp;
 	char *line = NULL;
@@ -48,9 +49,6 @@
 	}
 
 	while ((read = getline(&line, &len, fp)) != -1 && result == 0) {
-		// line[len]=0;
-		// printf("Retrieved line of length %zu:\n", read);
-		// printf("%s", line);
 		if (strstr(line, "docker") != NULL) {
 			result = CONTAINER_TYPE::DOCKER;
 		}
diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp
index c203e4e..2915808 100644
--- a/src/library/os/linux/os_linux.cpp
+++ b/src/library/os/linux/os_linux.cpp
@@ -97,7 +97,7 @@
 
 FUNCTION_RETURN parse_blkid(const std::string &blkid_file_content, std::vector<DiskInfo> &diskInfos_out,
 							std::unordered_map<std::string, int> &disk_by_uuid) {
-	DiskInfo diskInfo;
+	DiskInfo diskInfo = {};
 	int diskNum = 0;
 	for (std::size_t oldpos = 0, pos = 0; (pos = blkid_file_content.find("</device>", oldpos)) != std::string::npos;
 		 oldpos = pos + 1) {
@@ -111,6 +111,8 @@
 		parseUUID(disk_sn.c_str(), diskInfo.disk_sn, sizeof(diskInfo.disk_sn));
 		std::string disk_type = getAttribute(cur_dev, "TYPE");
 		disk_by_uuid.insert(std::pair<std::string, int>(disk_sn, diskInfo.id));
+		diskInfo.label_initialized = true;
+		diskInfo.sn_initialized = true;
 		// unlikely that somebody put the swap on a removable disk.
 		// this is a first rough guess on what can be a preferred disk for blkid devices
 		// just in case /etc/fstab can't be accessed or it is not up to date.
diff --git a/src/library/os/windows/network.cpp b/src/library/os/windows/network.cpp
index 5116d39..ad8c5ab 100644
--- a/src/library/os/windows/network.cpp
+++ b/src/library/os/windows/network.cpp
@@ -127,7 +127,6 @@
 	}
 
 	IP_ADAPTER_INFO* pAdapter = pAdapterInfo;
-	FUNCTION_RETURN result = FUNC_RET_OK;
 	while (pAdapter) {
 		if (pAdapter->Type == MIB_IF_TYPE_ETHERNET) {
 			OsAdapterInfo ai = {};

--
Gitblit v1.9.1