From b71231e80c32a77023197ad96bb4acdbb5bb22f5 Mon Sep 17 00:00:00 2001
From: Felipe Shi Iu Wu <felipeshiwu@gmail.com>
Date: Tue, 18 Oct 2016 11:00:23 -0200
Subject: [PATCH] Issue #28: Lint gitlab-ci

Signed-off-by: Felipe Shi Iu Wu <felipeshiwu@gmail.com>
---
 src/linux/get_user_count.cpp |  8 +++++---
 src/linux/inventory.cpp      |  3 ++-
 src/windows/get_macaddr.cpp  | 10 ++++++----
 src/windows/get_time.cpp     |  2 +-
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/linux/get_user_count.cpp b/src/linux/get_user_count.cpp
index c942ee4a..c7eb324c 100644
--- a/src/linux/get_user_count.cpp
+++ b/src/linux/get_user_count.cpp
@@ -204,7 +204,8 @@ static struct user_log * last_modified() {
     /*
      *    Which file do we want to read?
      */
-    ufile = (char *)(WTMP_FILE);
+    char *auxar = WTMP_FILE;
+    ufile = auxar;
     time(&lastdown);
 
     /*
@@ -481,11 +482,12 @@ int get_user_count() {
 
     std::string wtmp_path = "/var/log/wtmp";
     struct stat buffer;
-    if (stat(wtmp_path.c_str(), &buffer) != 0) { //file not exists
+    if (stat(wtmp_path.c_str(), &buffer) != 0) {  // file not exists
         ofstream wtmp_file;
         wtmp_file.open(wtmp_path.c_str());
         wtmp_file.close();
-        chown(wtmp_path.c_str(), getpwnam("root")->pw_uid, getgrnam("tty")->gr_gid);
+        chown(wtmp_path.c_str(), getpwnam("root")->pw_uid,
+                                 getgrnam("tty")->gr_gid);
         chmod(wtmp_path.c_str(), 664);
     }
 
diff --git a/src/linux/inventory.cpp b/src/linux/inventory.cpp
index 88e11663..ff41037b 100644
--- a/src/linux/inventory.cpp
+++ b/src/linux/inventory.cpp
@@ -65,7 +65,8 @@ Json::Value get_inventory() {
     inv["contact_date"] =
     */
 
-    if (inv["data"]["os_distro"].asString().find("Linux Comunicações") != std::string::npos) {
+    if (inv["data"]["os_distro"].asString().find("Linux Comunicações")
+                                                != std::string::npos) {
         try {
             inv["data"]["machine_type"] = get_machine_type();
         }
diff --git a/src/windows/get_macaddr.cpp b/src/windows/get_macaddr.cpp
index 83454c82..d5bf70f3 100644
--- a/src/windows/get_macaddr.cpp
+++ b/src/windows/get_macaddr.cpp
@@ -24,9 +24,10 @@
 string get_macaddr() {
     PIP_ADAPTER_INFO AdapterInfo;
     DWORD dwBufLen = sizeof(AdapterInfo);
-    char *mac_addr = (char*)malloc(17);
+    char *mac_addr = reinterpret_cast<char*>malloc(17);
 
-    AdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO));
+    AdapterInfo = (reinterpret_cast<char*>IP_ADAPTER_INFO *)
+                             malloc(sizeof(IP_ADAPTER_INFO));
     if (AdapterInfo == NULL) {
         printf("Error allocating memory needed to call GetAdaptersinfo\n");
     }
@@ -35,7 +36,8 @@ string get_macaddr() {
     // the dwBufLen variable
     if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW) {
 
-        AdapterInfo = (IP_ADAPTER_INFO *) malloc(dwBufLen);
+        AdapterInfo = (reinterpret_cast<char*>IP_ADAPTER_INFO *)
+                                                malloc(dwBufLen);
         if (AdapterInfo == NULL) {
             printf("Error allocating memory needed to call GetAdaptersinfo\n");
         }
@@ -46,7 +48,7 @@ string get_macaddr() {
         // Contains pointer to current adapter info
         PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
 
-        sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
+        snprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
         pAdapterInfo->Address[0], pAdapterInfo->Address[1],
         pAdapterInfo->Address[2], pAdapterInfo->Address[3],
         pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
diff --git a/src/windows/get_time.cpp b/src/windows/get_time.cpp
index 4bef83fa..85410a97 100644
--- a/src/windows/get_time.cpp
+++ b/src/windows/get_time.cpp
@@ -30,7 +30,7 @@ std::string get_time() {
     char buffer[20];
 
     time(&rawtime);
-    timeinfo = localtime(&rawtime);
+    timeinfo = localtime_r(&rawtime, timeinfo);
 
     // HH:MM:SS
     strftime(buffer, 20, "%H:%M:%S", timeinfo);
-- 
GitLab