]> granicus.if.org Git - icinga2/commitdiff
Use <reinterpret_cast>()
authorJean Flach <jean-marcel.flach@netways.de>
Fri, 14 Nov 2014 15:26:30 +0000 (16:26 +0100)
committerJean Flach <jean-marcel.flach@netways.de>
Fri, 14 Nov 2014 15:26:30 +0000 (16:26 +0100)
plugins/check_disk.cpp
plugins/check_network.cpp
plugins/check_procs.cpp
plugins/check_service.cpp

index c81a4e61f76b253337a6ecf1ed741442d8e60bbc..b8a968f057db5e3c04208fc9cca6ca145fed75a9 100644 (file)
@@ -275,13 +275,13 @@ int check_drives(vector<drive>& vDrives)
 
        while (GetLastError() != ERROR_NO_MORE_FILES) {
                volumeNameEnd = wcslen(szVolumeName) - 1;
-               szVolumePathNames = (PWCHAR) new BYTE[dwVolumePathNamesLen * sizeof(wchar_t)];
+               szVolumePathNames = reinterpret_cast<wchar_t*>(new WCHAR[dwVolumePathNamesLen]);
 
                while (!GetVolumePathNamesForVolumeName(szVolumeName, szVolumePathNames, dwVolumePathNamesLen, &dwVolumePathNamesLen)) {
                        if (GetLastError() != ERROR_MORE_DATA)
                                break;
-                       delete[] szVolumePathNames;
-                       szVolumePathNames = (PWCHAR) new BYTE[dwVolumePathNamesLen * sizeof(wchar_t)];
+                       delete[] reinterpret_cast<wchar_t*>(szVolumePathNames);
+                       szVolumePathNames = reinterpret_cast<wchar_t*>(new WCHAR[dwVolumePathNamesLen]);
 
                }
 
index 326ecc9af131c12b3d97381a12ace5be9f482f1d..688f78fbc508bfa5a2490d0745652b8bc67a56cd 100644 (file)
@@ -239,13 +239,13 @@ int check_network(vector <nInterface>& vInterfaces)
 
        err = PdhGetFormattedCounterArray(phCounterIn, PDH_FMT_LONG, &dwBufferSizeIn, &dwItemCount, pDisplayValuesIn);
        if (err == PDH_MORE_DATA || SUCCEEDED(err))
-               pDisplayValuesIn = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeIn];
+               pDisplayValuesIn = reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(new BYTE[dwItemCount*dwBufferSizeIn]);
        else
                goto die;
        
        err = PdhGetFormattedCounterArray(phCounterOut, PDH_FMT_LONG, &dwBufferSizeOut, &dwItemCount, pDisplayValuesOut);
        if (err == PDH_MORE_DATA || SUCCEEDED(err))
-               pDisplayValuesOut = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeOut];
+               pDisplayValuesOut = reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(new BYTE[dwItemCount*dwBufferSizeIn]);
        else
                goto die;
 
@@ -272,8 +272,8 @@ die:
        if (phQuery)
                PdhCloseQuery(phQuery);
        if (pDisplayValuesIn)
-               delete pDisplayValuesIn;
+               delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesIn);
        if (pDisplayValuesOut)
-               delete pDisplayValuesOut;
+               delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesOut);
        return 3;
 }
\ No newline at end of file
index da47e1b466340db74aa9b4b69219adb08bd016a5..942c027db1ee8be67ccaf02ac98983412a704bda 100644 (file)
@@ -256,7 +256,7 @@ int countProcs(const wstring user)
                        && GetLastError() != ERROR_INSUFFICIENT_BUFFER) 
                        continue;
 
-               pSIDTokenUser = (PTOKEN_USER)new BYTE[dwReturnLength];
+               pSIDTokenUser = reinterpret_cast<PTOKEN_USER>(new BYTE[dwReturnLength]);
                memset(pSIDTokenUser, 0, dwReturnLength);
 
                if (!pSIDTokenUser)
@@ -276,8 +276,8 @@ int countProcs(const wstring user)
                        && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
                        continue;
                
-               AcctName = (LPWSTR) new wchar_t[dwAcctName];
-               DomainName = (LPWSTR) new wchar_t[dwDomainName];
+               AcctName = reinterpret_cast<LPWSTR>(new WCHAR[dwAcctName]);
+               DomainName = reinterpret_cast<LPWSTR>(new WCHAR[dwDomainName]);
 
                if (!AcctName || !DomainName)
                        continue;
@@ -289,6 +289,8 @@ int countProcs(const wstring user)
                if (!wcscmp(AcctName, wuser)) 
                        ++numProcs;
                
+               delete[] reinterpret_cast<LPWSTR>(AcctName);
+               delete[] reinterpret_cast<LPWSTR>(DomainName);
 
        } while (Process32Next(hProcessSnap, &pe32));
        
@@ -300,5 +302,7 @@ die:
                CloseHandle(hProcess);
        if (hToken)
                CloseHandle(hToken);
+       if (pSIDTokenUser)
+               delete[] reinterpret_cast<PTOKEN_USER>(pSIDTokenUser);
        return numProcs;
 }
\ No newline at end of file
index 885e14442180e7f7f7494f944340220555e66389..b55045420bf38ad6269f58c962ed4c8eade51310 100644 (file)
@@ -178,7 +178,7 @@ int ServiceStatus(const printInfoStruct& printInfo)
                && GetLastError() != ERROR_MORE_DATA) 
                goto die;
 
-       lpServices = new BYTE[*pcbBytesNeeded];
+       lpServices = reinterpret_cast<LPBYTE>(new BYTE[*pcbBytesNeeded]);
        cbBufSize = *pcbBytesNeeded;
 
        if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
@@ -196,7 +196,7 @@ int ServiceStatus(const printInfoStruct& printInfo)
 
 die:
        if (lpServices)
-               delete lpServices;
+               delete[] reinterpret_cast<LPBYTE>(lpServices);
        wcout << L"Service " << printInfo.service << L" could not be found" << endl;
        return -1;
 }