Skip to content

Commit

Permalink
fix Codacy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gcontini committed Dec 5, 2020
1 parent 3abfa2c commit 907a462
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/library/base/EventRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>

#include "EventRegistry.h"
#define LIC_ID_NOT_DEFINED "UNDEF"
Expand Down Expand Up @@ -41,6 +42,12 @@ ostream &operator<<(std::ostream &out, const EventRegistry &er) {
return out;
}

string EventRegistry::to_string() const {
std::stringstream ss;
ss << this;
return ss.str();
}

void EventRegistry::append(const EventRegistry &eventRegistry) {
logs.insert(logs.end(), eventRegistry.logs.begin(), eventRegistry.logs.end());
}
Expand Down
1 change: 1 addition & 0 deletions src/library/base/EventRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class EventRegistry {
void addEvent(LCC_EVENT_TYPE event, const std::string &licenseLocationId);
void addEvent(LCC_EVENT_TYPE event, const char *licenseLocationId = nullptr, const char *info = nullptr);
void exportLastEvents(AuditEvent *auditEvents, int nlogs);
std::string to_string() const;
};
} // namespace license
#endif /* EVENTREGISTRY_H_ */
5 changes: 3 additions & 2 deletions src/library/licensecc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool identify_pc(LCC_API_HW_IDENTIFICATION_STRATEGY pc_id_method, char* chbuffer
} catch (const std::exception& ex) {
LOG_ERROR("Error calculating hw_identifier: %s", ex.what());
#ifndef NDEBUG
cout << "Error occurred: " << ex.what() << std::endl;
cerr << "Error occurred in identify_pc: " << ex.what() << std::endl;
#endif
}
} else {
Expand Down Expand Up @@ -124,7 +124,8 @@ LCC_EVENT_TYPE acquire_license(const CallerInformations* callerInformation, cons
}
}
#ifndef NDEBUG
cout << er << endl;
const string evlog = er.to_string();
LOG_DEBUG("License status %s", evlog.c_str());
#endif

if (license_out != nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions src/library/limits/license_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ LicenseInfo LicenseVerifier::toLicenseInfo(const FullLicenseInfo& fullLicInfo) c

const auto expiry = fullLicInfo.m_limits.find(PARAM_EXPIRY_DATE);
if (expiry != fullLicInfo.m_limits.end()) {
strncpy(info.expiry_date, expiry->second.c_str(), sizeof(info.expiry_date));
mstrlcpy(info.expiry_date, expiry->second.c_str(), sizeof(info.expiry_date));
info.has_expiry = true;
const double secs = difftime(seconds_from_epoch(expiry->second), time(nullptr));
info.days_left = max((int)round(secs / (60 * 60 * 24)), 0);
Expand All @@ -89,7 +89,7 @@ LicenseInfo LicenseVerifier::toLicenseInfo(const FullLicenseInfo& fullLicInfo) c

const auto proprietary_data = fullLicInfo.m_limits.find(PARAM_EXTRA_DATA);
if (proprietary_data != fullLicInfo.m_limits.end()) {
strncpy(info.proprietary_data, proprietary_data->second.c_str(), LCC_API_PROPRIETARY_DATA_SIZE);
mstrlcpy(info.proprietary_data, proprietary_data->second.c_str(), sizeof(info.proprietary_data));
}
return info;
}
Expand Down
9 changes: 5 additions & 4 deletions src/library/os/windows/os_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iphlpapi.h>
#include <stdio.h>

#include "../../base/string_utils.h"
#include "../../base/logger.h"
#include "../os.h"
using namespace std;
Expand All @@ -29,7 +30,7 @@ FUNCTION_RETURN getDiskInfos(std::vector<DiskInfo>& diskInfos) {
DWORD fileMaxLen;
size_t ndrives = 0, drives_scanned = 0;
DWORD fileFlags;
char volName[MAX_PATH], fileSysName[MAX_PATH];
char volName[MAX_PATH];
DWORD volSerial = 0;
const DWORD dwSize = MAX_PATH;
char szLogicalDrives[MAX_PATH] = {0};
Expand All @@ -44,6 +45,7 @@ FUNCTION_RETURN getDiskInfos(std::vector<DiskInfo>& diskInfos) {
// get the next drive
UINT driveType = GetDriveType(szSingleDrive);
if (driveType == DRIVE_FIXED) {
char fileSysName[MAX_PATH];
BOOL success = GetVolumeInformation(szSingleDrive, volName, MAX_PATH, &volSerial, &fileMaxLen,
&fileFlags, fileSysName, MAX_PATH);
if (success) {
Expand All @@ -52,9 +54,8 @@ FUNCTION_RETURN getDiskInfos(std::vector<DiskInfo>& diskInfos) {
DiskInfo diskInfo = {};
diskInfo.id = (int)ndrives;
diskInfo.label_initialized = true;
strncpy(diskInfo.device, volName, min(std::size_t{MAX_PATH}, sizeof(volName)) - 1);
strncpy(diskInfo.label, fileSysName,
min(sizeof(diskInfos[ndrives].label), sizeof(fileSysName)) - 1);
mstrlcpy(diskInfo.device, volName, min(std::size_t{MAX_PATH}, sizeof(volName)));
mstrlcpy(diskInfo.label, fileSysName, min(sizeof(diskInfos[ndrives].label), sizeof(fileSysName)));
memcpy(diskInfo.disk_sn, &volSerial, sizeof(DWORD));
diskInfo.sn_initialized = true;
diskInfo.preferred = (szSingleDrive[0] == 'C');
Expand Down

0 comments on commit 907a462

Please sign in to comment.