Skip to content

Commit

Permalink
fix: remove all Windows warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ncvicchi committed Dec 5, 2024
1 parent e4e5ec2 commit fd4f0cf
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22)

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")

if(NOT WIN32)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
endif()

Expand Down
1 change: 1 addition & 0 deletions src/cmake/ConfigureTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function(configure_target target)
/w14546 # Function pointer conversion to a different size
/w14547 # Function pointer conversion to a different calling convention
)
add_definitions(-D_WIN32_WINNT=0x0601)
target_compile_options(${target} PRIVATE ${msvc_warnings})
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/common/cmdHelper/include/cmdHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace Utils

if (file)
{
while (fgets(buffer.data(), bufferSize, file.get()))
while (fgets(buffer.data(), static_cast<int>(bufferSize), file.get()))
{
result += buffer.data();
}
Expand Down
12 changes: 6 additions & 6 deletions src/common/data_provider/src/network/networkWindowsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,14 @@ class NetworkWindowsInterface final : public INetworkInterfaceWrapper
{
const auto txPackets { ifRow->OutUcastPkts + ifRow->OutNUcastPkts };
const auto rxPackets { ifRow->InUcastPkts + ifRow->InNUcastPkts };
retVal.txPackets = txPackets;
retVal.rxPackets = rxPackets;
retVal.txPackets = static_cast<unsigned int>(txPackets);
retVal.rxPackets = static_cast<unsigned int>(rxPackets);
retVal.txBytes = ifRow->OutOctets;
retVal.rxBytes = ifRow->InOctets;
retVal.txErrors = ifRow->OutErrors;
retVal.rxErrors = ifRow->InErrors;
retVal.txDropped = ifRow->OutDiscards;
retVal.rxDropped = ifRow->InDiscards;
retVal.txErrors = static_cast<unsigned int>(ifRow->OutErrors);
retVal.rxErrors = static_cast<unsigned int>(ifRow->InErrors);
retVal.txDropped = static_cast<unsigned int>(ifRow->OutDiscards);
retVal.rxDropped = static_cast<unsigned int>(ifRow->InDiscards);
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/common/data_provider/src/osinfo/sysOsInfoWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include "registryHelper.h"
#include "sharedDefs.h"

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4996)
#endif

static std::string getVersion(const bool isMinor = false)
{
std::string version;
Expand Down Expand Up @@ -54,7 +59,6 @@ static std::string getVersion(const bool isMinor = false)
{
OSVERSIONINFOEX osvi{};
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

if (GetVersionEx (reinterpret_cast<OSVERSIONINFO*>(&osvi)))
{
version = std::to_string(isMinor ? osvi.dwMinorVersion : osvi.dwMajorVersion);
Expand Down Expand Up @@ -281,6 +285,10 @@ static std::string getName()
return name.empty() ? "Microsoft Windows" : name;
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif

static std::string getMachine()
{
static const std::map<std::string, std::string> ARCH_MAP
Expand Down
12 changes: 6 additions & 6 deletions src/common/data_provider/src/ports/portWindowsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class WindowsPortWrapper final : public IPortWrapper
public:
WindowsPortWrapper(const _MIB_TCPROW_OWNER_PID& data, const std::map<pid_t, std::string>& processDataList)
: m_protocol { "tcp" }
, m_localPort { ntohs(data.dwLocalPort) }
, m_localPort { static_cast<int32_t>(ntohs(static_cast<u_short>(data.dwLocalPort))) }
, m_localIpAddress { getIpV4Address(data.dwLocalAddr) }
, m_remotePort { ntohs(data.dwRemotePort) }
, m_remotePort { static_cast<int32_t>(ntohs(static_cast<u_short>(data.dwRemotePort))) }
, m_remoteIpAddress { getIpV4Address(data.dwRemoteAddr) }
, m_state { data.dwState }
, m_pid { data.dwOwningPid }
Expand All @@ -104,9 +104,9 @@ class WindowsPortWrapper final : public IPortWrapper

WindowsPortWrapper(const _MIB_TCP6ROW_OWNER_PID& data, const std::map<pid_t, std::string>& processDataList)
: m_protocol { "tcp6" }
, m_localPort { ntohs(data.dwLocalPort) }
, m_localPort { static_cast<int32_t>(ntohs(static_cast<u_short>(data.dwLocalPort))) }
, m_localIpAddress { Utils::NetworkWindowsHelper::getIpV6Address(data.ucLocalAddr) }
, m_remotePort { ntohs(data.dwRemotePort) }
, m_remotePort { static_cast<int32_t>(ntohs(static_cast<u_short>(data.dwRemotePort))) }
, m_remoteIpAddress { Utils::NetworkWindowsHelper::getIpV6Address(data.ucRemoteAddr) }
, m_state { data.dwState }
, m_pid { data.dwOwningPid }
Expand All @@ -115,7 +115,7 @@ class WindowsPortWrapper final : public IPortWrapper

WindowsPortWrapper(const _MIB_UDPROW_OWNER_PID& data, const std::map<pid_t, std::string>& processDataList)
: m_protocol { "udp" }
, m_localPort { ntohs(data.dwLocalPort) }
, m_localPort { static_cast<int32_t>(ntohs(static_cast<u_short>(data.dwLocalPort))) }
, m_localIpAddress { getIpV4Address(data.dwLocalAddr) }
, m_remotePort { 0 }
, m_state { 0 }
Expand All @@ -125,7 +125,7 @@ class WindowsPortWrapper final : public IPortWrapper

WindowsPortWrapper(const _MIB_UDP6ROW_OWNER_PID& data, const std::map<pid_t, std::string>& processDataList)
: m_protocol("udp6")
, m_localPort { ntohs(data.dwLocalPort) }
, m_localPort { static_cast<int32_t>(ntohs(static_cast<u_short>(data.dwLocalPort))) }
, m_localIpAddress { Utils::NetworkWindowsHelper::getIpV6Address(data.ucLocalAddr) }
, m_remotePort { 0 }
, m_state { 0 }
Expand Down
4 changes: 2 additions & 2 deletions src/common/data_provider/src/sysInfoWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class SysInfoProcess final
// Reference: https://stackoverflow.com/a/1986486
if (GetProcessMemoryInfo(m_hProcess, &pMemCounters, sizeof(pMemCounters)))
{
m_pageFileUsage = pMemCounters.PagefileUsage;
m_virtualSize = pMemCounters.WorkingSetSize + pMemCounters.PagefileUsage;
m_pageFileUsage = static_cast<DWORD>(pMemCounters.PagefileUsage);
m_virtualSize = static_cast<int32_t>(pMemCounters.WorkingSetSize + pMemCounters.PagefileUsage);
}

// else: Unable to retrieve page file usage from current process
Expand Down
2 changes: 1 addition & 1 deletion src/common/dbsync/src/sqlite/sqlite_dbengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ bool SQLiteDBEngine::getPKListLeftOnly(const std::string& t1,
if (tableFields.end() != it)
{
getTableData(stmt,
index,
static_cast<int32_t>(index),
std::get<TableHeader::Type>(*it),
std::get<TableHeader::Name>(*it),
registerFields);
Expand Down
2 changes: 1 addition & 1 deletion src/common/dbsync/src/sqlite/sqlite_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void Statement::bind(const int32_t index, const std::string& value)
sqlite3_bind_text(m_stmt.get(),
index,
value.c_str(),
value.length(),
static_cast<int>(value.length()),
SQLITE_TRANSIENT)
};
checkSqliteResult(result, sqlite3_errmsg(m_connection->db().get()));
Expand Down
2 changes: 1 addition & 1 deletion src/common/windowsHelper/include/windowsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ namespace Utils
if (offset < rawDataSize)
{
const auto len{ nullptr != tmp ? strlen(tmp) : 0 };
offset += len + sizeof(char);
offset += static_cast<DWORD>(len + sizeof(char));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/inventory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ add_library(Inventory
src/inventory.cpp
src/inventoryImp.cpp
src/inventoryNormalizer.cpp)

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(Inventory PRIVATE /WX- /w)
target_compile_options(Inventory PRIVATE /WX-)
endif()

target_include_directories(Inventory PUBLIC
Expand Down

0 comments on commit fd4f0cf

Please sign in to comment.