]> granicus.if.org Git - icinga2/commitdiff
Fix compiler warnings in Windows plugins 7153/head
authorMichael Insel <michael@insel.email>
Tue, 30 Apr 2019 08:32:44 +0000 (10:32 +0200)
committerMichael Insel <michael@insel.email>
Tue, 30 Apr 2019 08:32:44 +0000 (10:32 +0200)
This fixes a bunch of compiler warnings in the Windows plugins.

plugins/check_perfmon.cpp
plugins/check_ping.cpp
plugins/check_service.cpp
plugins/check_update.cpp
plugins/check_uptime.cpp

index c0a42f92fd62c6ccae1667475af7188ba2c817b1..0f94b12dc5347fefb06cb9a0f1a8fee66eb665e9 100644 (file)
@@ -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;
index e341c0beb876eb3c4403864ec24fd2582fe69127..c918d927216e063af9126ed99f3ac5ee5fb2ea31 100644 (file)
@@ -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());
 
-       IP_OPTION_INFORMATION ipInfo = { 30, 0, 0, 0, NULL };
-
-       LARGE_INTEGER frequency;
-       QueryPerformanceFrequency(&frequency);
-
-       do {
-               LARGE_INTEGER timer1;
-               QueryPerformanceCounter(&timer1);
+               if (hIcmp)
+                       IcmpCloseHandle(hIcmp);
 
-               if (l_Debug)
-                       std::wcout << L"Sending Icmp echo" << '\n';
+               if (repBuf)
+                       delete reinterpret_cast<BYTE *>(repBuf);
 
-               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;
-               }
+               return 3;
+       } else {
+               IP_OPTION_INFORMATION ipInfo = { 30, 0, 0, 0, NULL };
 
-               if (l_Debug)
-                       std::wcout << "Ping recieved" << '\n';
+               LARGE_INTEGER frequency;
+               QueryPerformanceFrequency(&frequency);
 
-               Icmp6ParseReplies(repBuf, dwRepSize);
+               do {
+                       LARGE_INTEGER timer1;
+                       QueryPerformanceCounter(&timer1);
 
-               ICMPV6_ECHO_REPLY *pEchoReply = static_cast<ICMPV6_ECHO_REPLY *>(repBuf);
+                       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 (pEchoReply->Status != IP_SUCCESS) {
-                       response.dropped++;
                        if (l_Debug)
-                               std::wcout << L"Dropped: echo reply status " << pEchoReply->Status << '\n';
-                       continue;
-               }
+                               std::wcout << "Ping recieved" << '\n';
 
-               rtt += pEchoReply->RoundTripTime;
+                       Icmp6ParseReplies(repBuf, dwRepSize);
 
-               if (l_Debug)
-                       std::wcout << L"Recorded rtt of " << pEchoReply->RoundTripTime << '\n';
+                       ICMPV6_ECHO_REPLY *pEchoReply = static_cast<ICMPV6_ECHO_REPLY *>(repBuf);
 
-               if (response.pMin == 0 || pEchoReply->RoundTripTime < response.pMin)
-                       response.pMin = pEchoReply->RoundTripTime;
-               else if (pEchoReply->RoundTripTime > response.pMax)
-                       response.pMax = pEchoReply->RoundTripTime;
+                       if (pEchoReply->Status != IP_SUCCESS) {
+                               response.dropped++;
+                               if (l_Debug)
+                                       std::wcout << L"Dropped: echo reply status " << pEchoReply->Status << '\n';
+                               continue;
+                       }
 
-               LARGE_INTEGER timer2;
-               QueryPerformanceCounter(&timer2);
+                       rtt += pEchoReply->RoundTripTime;
 
-               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"Recorded rtt of " << pEchoReply->RoundTripTime << '\n';
 
-       if (l_Debug)
-               std::wcout << L"All pings sent. Cleaning up and returning" << '\n';
+                       if (response.pMin == 0 || pEchoReply->RoundTripTime < response.pMin)
+                               response.pMin = pEchoReply->RoundTripTime;
+                       else if (pEchoReply->RoundTripTime > response.pMax)
+                               response.pMax = pEchoReply->RoundTripTime;
 
-       if (hIcmp)
-               IcmpCloseHandle(hIcmp);
+                       LARGE_INTEGER timer2;
+                       QueryPerformanceCounter(&timer2);
 
-       if (repBuf)
-               delete reinterpret_cast<BYTE *>(repBuf);
+                       if (((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart) < pi.timeout)
+                               Sleep((DWORD) (pi.timeout - ((timer2.QuadPart - timer1.QuadPart) * 1000 / frequency.QuadPart)));
+               } while (--num);
 
-       response.avg = ((double)rtt / pi.num);
+               if (l_Debug)
+                       std::wcout << L"All pings sent. Cleaning up and returning" << '\n';
 
-       return -1;
-die:
-       printErrorInfo(GetLastError());
+               if (hIcmp)
+                       IcmpCloseHandle(hIcmp);
 
-       if (hIcmp)
-               IcmpCloseHandle(hIcmp);
+               if (repBuf)
+                       delete reinterpret_cast<BYTE *>(repBuf);
 
-       if (repBuf)
-               delete reinterpret_cast<BYTE *>(repBuf);
+               response.avg = ((double)rtt / pi.num);
 
-       return 3;
+               return -1;
+       }
 }
 
 int wmain(int argc, WCHAR **argv)
index 3697e35b86613c616bc5565f428b649f78e51b4c..70762386258ce549ce3612f784544dfd6c4aeb8d 100644 (file)
@@ -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) {
index 161b2d6926f6f44047313812dc40c259d94b4781..2711d9330f370db5431190c706dc47711ac83a52 100644 (file)
@@ -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")) {
index d26431b0a2f7deac7bc328bcb35b4beac739ec0d..93d540af21f2525b0debf6f49199bbd00e4ac94e 100644 (file)
@@ -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) {