gcontini
2020-12-05 907a46213e5ca3e741744f67ad71966b70b89e38
fix Codacy warnings
5个文件已修改
26 ■■■■■ 已修改文件
src/library/base/EventRegistry.cpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/EventRegistry.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/licensecc.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/limits/license_verifier.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/windows/os_win.cpp 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/EventRegistry.cpp
@@ -10,6 +10,7 @@
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include "EventRegistry.h"
#define LIC_ID_NOT_DEFINED "UNDEF"
@@ -41,6 +42,12 @@
    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());
}
src/library/base/EventRegistry.h
@@ -55,6 +55,7 @@
    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_ */
src/library/licensecc.cpp
@@ -40,7 +40,7 @@
        } 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 {
@@ -124,7 +124,8 @@
        }
    }
#ifndef NDEBUG
    cout << er << endl;
    const string evlog = er.to_string();
    LOG_DEBUG("License status %s", evlog.c_str());
#endif
    if (license_out != nullptr) {
src/library/limits/license_verifier.cpp
@@ -70,7 +70,7 @@
    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);
@@ -89,7 +89,7 @@
    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;
}
src/library/os/windows/os_win.cpp
@@ -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;
@@ -29,7 +30,7 @@
    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};
@@ -44,6 +45,7 @@
            // 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) {
@@ -52,9 +54,8 @@
                    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');