Use <reinterpret_cast>()

This commit is contained in:
Jean Flach 2014-11-14 16:26:30 +01:00
parent e1b5954e62
commit 0054e78a58
4 changed files with 16 additions and 12 deletions

View File

@ -275,13 +275,13 @@ int check_drives(vector<drive>& vDrives)
while (GetLastError() != ERROR_NO_MORE_FILES) { while (GetLastError() != ERROR_NO_MORE_FILES) {
volumeNameEnd = wcslen(szVolumeName) - 1; 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)) { while (!GetVolumePathNamesForVolumeName(szVolumeName, szVolumePathNames, dwVolumePathNamesLen, &dwVolumePathNamesLen)) {
if (GetLastError() != ERROR_MORE_DATA) if (GetLastError() != ERROR_MORE_DATA)
break; break;
delete[] szVolumePathNames; delete[] reinterpret_cast<wchar_t*>(szVolumePathNames);
szVolumePathNames = (PWCHAR) new BYTE[dwVolumePathNamesLen * sizeof(wchar_t)]; szVolumePathNames = reinterpret_cast<wchar_t*>(new WCHAR[dwVolumePathNamesLen]);
} }

View File

@ -239,13 +239,13 @@ int check_network(vector <nInterface>& vInterfaces)
err = PdhGetFormattedCounterArray(phCounterIn, PDH_FMT_LONG, &dwBufferSizeIn, &dwItemCount, pDisplayValuesIn); err = PdhGetFormattedCounterArray(phCounterIn, PDH_FMT_LONG, &dwBufferSizeIn, &dwItemCount, pDisplayValuesIn);
if (err == PDH_MORE_DATA || SUCCEEDED(err)) 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 else
goto die; goto die;
err = PdhGetFormattedCounterArray(phCounterOut, PDH_FMT_LONG, &dwBufferSizeOut, &dwItemCount, pDisplayValuesOut); err = PdhGetFormattedCounterArray(phCounterOut, PDH_FMT_LONG, &dwBufferSizeOut, &dwItemCount, pDisplayValuesOut);
if (err == PDH_MORE_DATA || SUCCEEDED(err)) 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 else
goto die; goto die;
@ -272,8 +272,8 @@ die:
if (phQuery) if (phQuery)
PdhCloseQuery(phQuery); PdhCloseQuery(phQuery);
if (pDisplayValuesIn) if (pDisplayValuesIn)
delete pDisplayValuesIn; delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesIn);
if (pDisplayValuesOut) if (pDisplayValuesOut)
delete pDisplayValuesOut; delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesOut);
return 3; return 3;
} }

View File

@ -256,7 +256,7 @@ int countProcs(const wstring user)
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
continue; continue;
pSIDTokenUser = (PTOKEN_USER)new BYTE[dwReturnLength]; pSIDTokenUser = reinterpret_cast<PTOKEN_USER>(new BYTE[dwReturnLength]);
memset(pSIDTokenUser, 0, dwReturnLength); memset(pSIDTokenUser, 0, dwReturnLength);
if (!pSIDTokenUser) if (!pSIDTokenUser)
@ -276,8 +276,8 @@ int countProcs(const wstring user)
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
continue; continue;
AcctName = (LPWSTR) new wchar_t[dwAcctName]; AcctName = reinterpret_cast<LPWSTR>(new WCHAR[dwAcctName]);
DomainName = (LPWSTR) new wchar_t[dwDomainName]; DomainName = reinterpret_cast<LPWSTR>(new WCHAR[dwDomainName]);
if (!AcctName || !DomainName) if (!AcctName || !DomainName)
continue; continue;
@ -289,6 +289,8 @@ int countProcs(const wstring user)
if (!wcscmp(AcctName, wuser)) if (!wcscmp(AcctName, wuser))
++numProcs; ++numProcs;
delete[] reinterpret_cast<LPWSTR>(AcctName);
delete[] reinterpret_cast<LPWSTR>(DomainName);
} while (Process32Next(hProcessSnap, &pe32)); } while (Process32Next(hProcessSnap, &pe32));
@ -300,5 +302,7 @@ die:
CloseHandle(hProcess); CloseHandle(hProcess);
if (hToken) if (hToken)
CloseHandle(hToken); CloseHandle(hToken);
if (pSIDTokenUser)
delete[] reinterpret_cast<PTOKEN_USER>(pSIDTokenUser);
return numProcs; return numProcs;
} }

View File

@ -178,7 +178,7 @@ int ServiceStatus(const printInfoStruct& printInfo)
&& GetLastError() != ERROR_MORE_DATA) && GetLastError() != ERROR_MORE_DATA)
goto die; goto die;
lpServices = new BYTE[*pcbBytesNeeded]; lpServices = reinterpret_cast<LPBYTE>(new BYTE[*pcbBytesNeeded]);
cbBufSize = *pcbBytesNeeded; cbBufSize = *pcbBytesNeeded;
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
@ -196,7 +196,7 @@ int ServiceStatus(const printInfoStruct& printInfo)
die: die:
if (lpServices) if (lpServices)
delete lpServices; delete[] reinterpret_cast<LPBYTE>(lpServices);
wcout << L"Service " << printInfo.service << L" could not be found" << endl; wcout << L"Service " << printInfo.service << L" could not be found" << endl;
return -1; return -1;
} }