From 25c2a2bb5353a6cb994aebfd9dd234528c3cb812 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Tue, 30 Apr 2019 10:32:44 +0200 Subject: [PATCH] Fix compiler warnings in Windows plugins This fixes a bunch of compiler warnings in the Windows plugins. --- plugins/check_perfmon.cpp | 2 +- plugins/check_ping.cpp | 150 +++++++++++++++++++------------------- plugins/check_service.cpp | 2 +- plugins/check_update.cpp | 2 +- plugins/check_uptime.cpp | 4 +- 5 files changed, 79 insertions(+), 81 deletions(-) diff --git a/plugins/check_perfmon.cpp b/plugins/check_perfmon.cpp index c0a42f92f..0f94b12dc 100644 --- a/plugins/check_perfmon.cpp +++ b/plugins/check_perfmon.cpp @@ -317,7 +317,7 @@ bool QueryPerfData(printInfoStruct& pI) pI.dValue = pDisplayValues[0].FmtValue.longValue; break; case (PDH_FMT_LARGE): - pI.dValue = pDisplayValues[0].FmtValue.largeValue; + pI.dValue = (double) pDisplayValues[0].FmtValue.largeValue; break; default: pI.dValue = pDisplayValues[0].FmtValue.doubleValue; diff --git a/plugins/check_ping.cpp b/plugins/check_ping.cpp index e341c0beb..c918d9272 100644 --- a/plugins/check_ping.cpp +++ b/plugins/check_ping.cpp @@ -345,7 +345,7 @@ static int check_ping4(const printInfoStruct& pi, response& response) QueryPerformanceCounter(&timer2); if (((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart) < pi.timeout) - Sleep(pi.timeout - ((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart)); + Sleep((DWORD) (pi.timeout - ((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart))); } while (--num); if (l_Debug) @@ -400,82 +400,80 @@ static int check_ping6(const printInfoStruct& pi, response& response) HANDLE hIcmp = Icmp6CreateFile(); if (hIcmp == INVALID_HANDLE_VALUE) { - goto die; + printErrorInfo(GetLastError()); + + if (hIcmp) + IcmpCloseHandle(hIcmp); + + if (repBuf) + delete reinterpret_cast(repBuf); + + return 3; + } else { + IP_OPTION_INFORMATION ipInfo = { 30, 0, 0, 0, NULL }; + + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + + do { + LARGE_INTEGER timer1; + QueryPerformanceCounter(&timer1); + + if (l_Debug) + std::wcout << L"Sending Icmp echo" << '\n'; + + if (!Icmp6SendEcho2(hIcmp, NULL, NULL, NULL, &ipSource6, &ipDest6, + NULL, 0, &ipInfo, repBuf, dwRepSize, pi.timeout)) { + response.dropped++; + if (l_Debug) + std::wcout << L"Dropped: Response was 0" << '\n'; + continue; + } + + if (l_Debug) + std::wcout << "Ping recieved" << '\n'; + + Icmp6ParseReplies(repBuf, dwRepSize); + + ICMPV6_ECHO_REPLY *pEchoReply = static_cast(repBuf); + + if (pEchoReply->Status != IP_SUCCESS) { + response.dropped++; + if (l_Debug) + std::wcout << L"Dropped: echo reply status " << pEchoReply->Status << '\n'; + continue; + } + + rtt += pEchoReply->RoundTripTime; + + if (l_Debug) + std::wcout << L"Recorded rtt of " << pEchoReply->RoundTripTime << '\n'; + + if (response.pMin == 0 || pEchoReply->RoundTripTime < response.pMin) + response.pMin = pEchoReply->RoundTripTime; + else if (pEchoReply->RoundTripTime > response.pMax) + response.pMax = pEchoReply->RoundTripTime; + + LARGE_INTEGER timer2; + QueryPerformanceCounter(&timer2); + + if (((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart) < pi.timeout) + Sleep((DWORD) (pi.timeout - ((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart))); + } while (--num); + + if (l_Debug) + std::wcout << L"All pings sent. Cleaning up and returning" << '\n'; + + if (hIcmp) + IcmpCloseHandle(hIcmp); + + if (repBuf) + delete reinterpret_cast(repBuf); + + response.avg = ((double)rtt / pi.num); + + return -1; } - - IP_OPTION_INFORMATION ipInfo = { 30, 0, 0, 0, NULL }; - - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); - - do { - LARGE_INTEGER timer1; - QueryPerformanceCounter(&timer1); - - if (l_Debug) - std::wcout << L"Sending Icmp echo" << '\n'; - - if (!Icmp6SendEcho2(hIcmp, NULL, NULL, NULL, &ipSource6, &ipDest6, - NULL, 0, &ipInfo, repBuf, dwRepSize, pi.timeout)) { - response.dropped++; - if (l_Debug) - std::wcout << L"Dropped: Response was 0" << '\n'; - continue; - } - - if (l_Debug) - std::wcout << "Ping recieved" << '\n'; - - Icmp6ParseReplies(repBuf, dwRepSize); - - ICMPV6_ECHO_REPLY *pEchoReply = static_cast(repBuf); - - if (pEchoReply->Status != IP_SUCCESS) { - response.dropped++; - if (l_Debug) - std::wcout << L"Dropped: echo reply status " << pEchoReply->Status << '\n'; - continue; - } - - rtt += pEchoReply->RoundTripTime; - - if (l_Debug) - std::wcout << L"Recorded rtt of " << pEchoReply->RoundTripTime << '\n'; - - if (response.pMin == 0 || pEchoReply->RoundTripTime < response.pMin) - response.pMin = pEchoReply->RoundTripTime; - else if (pEchoReply->RoundTripTime > response.pMax) - response.pMax = pEchoReply->RoundTripTime; - - LARGE_INTEGER timer2; - QueryPerformanceCounter(&timer2); - - if (((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart) < pi.timeout) - Sleep(pi.timeout - ((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart)); - } while (--num); - - if (l_Debug) - std::wcout << L"All pings sent. Cleaning up and returning" << '\n'; - - if (hIcmp) - IcmpCloseHandle(hIcmp); - - if (repBuf) - delete reinterpret_cast(repBuf); - - response.avg = ((double)rtt / pi.num); - - return -1; -die: - printErrorInfo(GetLastError()); - - if (hIcmp) - IcmpCloseHandle(hIcmp); - - if (repBuf) - delete reinterpret_cast(repBuf); - - return 3; } int wmain(int argc, WCHAR **argv) diff --git a/plugins/check_service.cpp b/plugins/check_service.cpp index 3697e35b8..707623862 100644 --- a/plugins/check_service.cpp +++ b/plugins/check_service.cpp @@ -167,7 +167,7 @@ static std::wstring getServiceByDescription(const std::wstring& description) EnumServicesStatus(hSCM, SERVICE_WIN32 | SERVICE_DRIVER, SERVICE_STATE_ALL, lpServices, pcbBytesNeeded, &pcbBytesNeeded, &lpServicesReturned, &lpResumeHandle); - for (int index = 0; index < lpServicesReturned; index++) { + for (decltype(lpServicesReturned) index = 0; index < lpServicesReturned; index++) { LPWSTR lpCurrent = lpServices[index].lpServiceName; if (l_Debug) { diff --git a/plugins/check_update.cpp b/plugins/check_update.cpp index 161b2d692..2711d9330 100644 --- a/plugins/check_update.cpp +++ b/plugins/check_update.cpp @@ -87,7 +87,7 @@ static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoSt L"threshold will be set to one greater than the set warning threshold.\n\n" L"The \"possible-reboot\" option is not recommended since this true for nearly\n" L"every update." - , progName, progName); + , progName); std::cout << '\n'; return 0; } if (vm.count("version")) { diff --git a/plugins/check_uptime.cpp b/plugins/check_uptime.cpp index d26431b0a..93d540af2 100644 --- a/plugins/check_uptime.cpp +++ b/plugins/check_uptime.cpp @@ -143,9 +143,9 @@ static int printOutput(printInfoStruct& printInfo) state state = OK; - if (printInfo.warn.rend(printInfo.time)) + if (printInfo.warn.rend((double) printInfo.time)) state = WARNING; - if (printInfo.crit.rend(printInfo.time)) + if (printInfo.crit.rend((double) printInfo.time)) state = CRITICAL; switch (state) {