From cbb11cd88d985db033c744b59291a2cf03fd16be Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周二, 13 10月 2020 21:53:31 +0800 Subject: [PATCH] #ifdef _DEBUG -> #ifndef NDEBUG for better cmake compatibility --- src/library/os/linux/network.cpp | 6 +++--- src/library/licensecc.cpp | 4 ++-- src/library/os/windows/signature_verifier.cpp | 14 +++++++------- src/library/LicenseReader.cpp | 2 +- src/library/ini/SimpleIni.h | 4 ++-- src/library/os/linux/os_linux.cpp | 14 +++++++++----- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/library/LicenseReader.cpp b/src/library/LicenseReader.cpp index 47f006e..6f46d91 100644 --- a/src/library/LicenseReader.cpp +++ b/src/library/LicenseReader.cpp @@ -117,7 +117,7 @@ } } -#ifdef _DEBUG +#ifndef NDEBUG cout << "license to sign [" << oss.str() << "]" << endl; #endif return oss.str(); diff --git a/src/library/ini/SimpleIni.h b/src/library/ini/SimpleIni.h index ac703b2..7142085 100644 --- a/src/library/ini/SimpleIni.h +++ b/src/library/ini/SimpleIni.h @@ -223,7 +223,7 @@ # include <iostream> #endif // SI_SUPPORT_IOSTREAMS -#ifdef _DEBUG +#ifndef NDEBUG # ifndef assert # include <cassert> # endif @@ -2488,7 +2488,7 @@ bNeedNewLine = true; } - + // Append new empty line a_oOutput.Write(SI_NEWLINE_A); diff --git a/src/library/licensecc.cpp b/src/library/licensecc.cpp index ea34b28..f9807a2 100644 --- a/src/library/licensecc.cpp +++ b/src/library/licensecc.cpp @@ -38,7 +38,7 @@ result = true; } catch (const std::exception& ex) { LOG_ERROR("Error calculating hw_identifier: %s", ex.what()); -#ifdef _DEBUG +#ifndef NDEBUG cout << "Error occurred: " << ex.what() << std::endl; #endif } @@ -122,7 +122,7 @@ license_out->days_left = 0; } } -#ifdef _DEBUG +#ifndef NDEBUG cout << er << endl; #endif diff --git a/src/library/os/linux/network.cpp b/src/library/os/linux/network.cpp index 5873a2b..1281aca 100644 --- a/src/library/os/linux/network.cpp +++ b/src/library/os/linux/network.cpp @@ -76,7 +76,7 @@ family = ifa->ifa_addr->sa_family; /* Display interface name and family (including symbolic form of the latter for the common families) */ -#ifdef _DEBUG +#ifndef NDEBUG printf("%-8s %s (%d)\n", ifa->ifa_name, (family == AF_PACKET) ? "AF_PACKET" : (family == AF_INET) ? "AF_INET" : (family == AF_INET6) ? "AF_INET6" : "???", @@ -97,11 +97,11 @@ int i; for (i = 0; i < 6; i++) { currentAdapter->mac_address[i] = s1->sll_addr[i]; -#ifdef _DEBUG +#ifndef NDEBUG printf("%02x:", s1->sll_addr[i]); #endif } -#ifdef _DEBUG +#ifndef NDEBUG printf("\t %s\n", ifa->ifa_name); #endif } diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp index f1041a4..0f53b9c 100644 --- a/src/library/os/linux/os_linux.cpp +++ b/src/library/os/linux/os_linux.cpp @@ -1,13 +1,15 @@ #include <paths.h> #include <sys/stat.h> #include <stdio.h> +#include <cerrno> +#include <cstring> #include "../os.h" #include "../../base/logger.h" #include <mntent.h> #include <dirent.h> #include <sys/utsname.h> -#ifdef _DEBUG +#ifndef NDEBUG #include <valgrind/memcheck.h> #endif @@ -52,7 +54,7 @@ free(hexuuid); } -#define MAX_UNITS 20 +#define MAX_UNITS 40 FUNCTION_RETURN getDiskInfos(DiskInfo *diskInfos, size_t *disk_info_size) { struct stat mount_stat, sym_stat; /*static char discard[1024]; @@ -89,7 +91,7 @@ } currentDrive = 0; - while (NULL != (ent = getmntent(aFile))) { + while (NULL != (ent = getmntent(aFile)) && currentDrive < maxDrives) { if ((strncmp(ent->mnt_type, "ext", 3) == 0 || strncmp(ent->mnt_type, "xfs", 3) == 0 || strncmp(ent->mnt_type, "vfat", 4) == 0 || strncmp(ent->mnt_type, "ntfs", 4) == 0 || strncmp(ent->mnt_type, "btr", 3) == 0) && @@ -116,6 +118,8 @@ } else { tmpDrives[drive_found].preferred = 0; } + } else { + LOG_DEBUG("Error %s during stat of %s \n", std::strerror(errno), ent->mnt_fsname); } } } @@ -141,7 +145,7 @@ for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { parseUUID(dir->d_name, tmpDrives[i].disk_sn, sizeof(tmpDrives[i].disk_sn)); -#ifdef _DEBUG +#ifndef NDEBUG VALGRIND_CHECK_VALUE_IS_DEFINED(tmpDrives[i].device); LOG_DEBUG("uuid %d %s %02x%02x%02x%02x\n", i, tmpDrives[i].device, tmpDrives[i].disk_sn[0], @@ -162,7 +166,7 @@ for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { strncpy(tmpDrives[i].label, dir->d_name, 255 - 1); - printf("label %d %s %s\n", i, tmpDrives[i].label, tmpDrives[i].device); + LOG_DEBUG("label %d %s %s\n", i, tmpDrives[i].label, tmpDrives[i].device); } } } diff --git a/src/library/os/windows/signature_verifier.cpp b/src/library/os/windows/signature_verifier.cpp index a99894b..083845e 100644 --- a/src/library/os/windows/signature_verifier.cpp +++ b/src/library/os/windows/signature_verifier.cpp @@ -29,7 +29,7 @@ using namespace std; #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) -static const void formatError(DWORD status, const char* description) { +static const void formatError(DWORD status, const char *description) { char msgBuffer[256]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, status, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &msgBuffer[0], sizeof(msgBuffer) - 1, nullptr); @@ -124,7 +124,7 @@ sizeof(pubk), 0))) { result = FUNC_RET_OK; } else { -#ifdef _DEBUG +#ifndef NDEBUG formatError(status, "error importing public key"); #endif } @@ -152,7 +152,7 @@ result = FUNC_RET_OK; } else { result = FUNC_RET_ERROR; -#ifdef _DEBUG +#ifndef NDEBUG formatError(status, "error verifying signature"); #endif } @@ -162,7 +162,7 @@ } else { result = FUNC_RET_NOT_AVAIL; -#ifdef _DEBUG +#ifndef NDEBUG formatError(status, "error opening RSA provider"); #endif } @@ -207,13 +207,13 @@ result = verifyHash(pbHashData, cbHashDataLenght, signatureB64); } else { result = FUNC_RET_NOT_AVAIL; -#ifdef _DEBUG +#ifndef NDEBUG formatError(status, "error hashing data"); #endif } } else { result = FUNC_RET_NOT_AVAIL; -#ifdef _DEBUG +#ifndef NDEBUG formatError(status, "error creating hash"); #endif } @@ -223,7 +223,7 @@ } } else { result = FUNC_RET_NOT_AVAIL; -#ifdef _DEBUG +#ifndef NDEBUG formatError(status, "**** Error returned by BCryptGetProperty"); #endif } -- Gitblit v1.9.1