Skip to content

Commit

Permalink
Merge pull request #58304 from adityamandaleeka/ancm_ca_changes_incr
Browse files Browse the repository at this point in the history
Enable code analysis and address initial set of issues.
  • Loading branch information
adityamandaleeka authored Oct 10, 2024
2 parents 7f85154 + c1752f6 commit 35d957a
Show file tree
Hide file tree
Showing 56 changed files with 861 additions and 1,003 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
auto shadowCopyBaseDirectory = std::filesystem::directory_entry(shadowCopyPath);
if (!shadowCopyBaseDirectory.exists())
{
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), NULL);
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), nullptr);
}

for (auto& entry : std::filesystem::directory_iterator(shadowCopyPath))
Expand Down
1 change: 1 addition & 0 deletions src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ BOOL WINAPI DllMain(HMODULE hModule,
// this is a bug in IIS. To try to avoid AVs, we will set a global flag
g_fInShutdown = TRUE;
StaticCleanup();
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void Environment::CopyToDirectoryInner(const std::filesystem::path& source, cons
auto destinationDirEntry = std::filesystem::directory_entry(destination);
if (!destinationDirEntry.exists())
{
CreateDirectory(destination.wstring().c_str(), NULL);
CreateDirectory(destination.wstring().c_str(), nullptr);
}

for (auto& path : std::filesystem::directory_iterator(source))
Expand Down
4 changes: 2 additions & 2 deletions src/Servers/IIS/AspNetCoreModuleV2/CommonLib/EventLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ EventLog::LogEventNoTrace(
dwEventInfoType,
0, // wCategory
dwEventId,
NULL, // lpUserSid
nullptr, // lpUserSid
static_cast<WORD>(eventLogDataStrings.size()), // wNumStrings
0, // dwDataSize,
eventLogDataStrings.data(),
NULL // lpRawData
nullptr // lpRawData
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ namespace fs = std::filesystem;
std::wstring
GlobalVersionUtility::GetGlobalRequestHandlerPath(PCWSTR pwzAspNetCoreFolderPath, PCWSTR pwzHandlerVersion, PCWSTR pwzHandlerName)
{
if (pwzAspNetCoreFolderPath == NULL)
if (pwzAspNetCoreFolderPath == nullptr)
{
throw new std::invalid_argument("pwzAspNetCoreFolderPath is NULL");
}

if (pwzHandlerVersion == NULL)
if (pwzHandlerVersion == nullptr)
{
throw new std::invalid_argument("pwzHandlerVersion is NULL");
}

if (pwzHandlerName == NULL)
if (pwzHandlerName == nullptr)
{
throw new std::invalid_argument("pwzHandlerName is NULL");
}
Expand All @@ -47,7 +47,7 @@ GlobalVersionUtility::GetGlobalRequestHandlerPath(PCWSTR pwzAspNetCoreFolderPath
std::vector<fx_ver_t>
GlobalVersionUtility::GetRequestHandlerVersions(PCWSTR pwzAspNetCoreFolderPath)
{
if (pwzAspNetCoreFolderPath == NULL)
if (pwzAspNetCoreFolderPath == nullptr)
{
throw new std::invalid_argument("pwzAspNetCoreFolderPath is NULL");
}
Expand All @@ -74,7 +74,7 @@ GlobalVersionUtility::GetRequestHandlerVersions(PCWSTR pwzAspNetCoreFolderPath)
std::wstring
GlobalVersionUtility::FindHighestGlobalVersion(PCWSTR pwzAspNetCoreFolderPath)
{
if (pwzAspNetCoreFolderPath == NULL)
if (pwzAspNetCoreFolderPath == nullptr)
{
throw std::invalid_argument("pwzAspNetCoreFolderPath is NULL");
}
Expand Down
22 changes: 11 additions & 11 deletions src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,16 @@ HostFxrResolver::InvokeWhereToFindDotnet()
{
HRESULT hr = S_OK;
// Arguments to call where.exe
STARTUPINFOW startupInfo = { 0 };
PROCESS_INFORMATION processInformation = { 0 };
STARTUPINFOW startupInfo{};
PROCESS_INFORMATION processInformation{};
SECURITY_ATTRIBUTES securityAttributes;

CHAR pzFileContents[READ_BUFFER_SIZE];
HandleWrapper<InvalidHandleTraits> hStdOutReadPipe;
HandleWrapper<InvalidHandleTraits> hStdOutWritePipe;
HandleWrapper<InvalidHandleTraits> hProcess;
HandleWrapper<InvalidHandleTraits> hThread;
CComBSTR pwzDotnetName = NULL;
CComBSTR pwzDotnetName = nullptr;
DWORD dwFilePointer;
BOOL fIsCurrentProcess64Bit;
DWORD dwExitCode;
Expand All @@ -423,7 +423,7 @@ HostFxrResolver::InvokeWhereToFindDotnet()

// Set the security attributes for the read/write pipe
securityAttributes.nLength = sizeof(securityAttributes);
securityAttributes.lpSecurityDescriptor = NULL;
securityAttributes.lpSecurityDescriptor = nullptr;
securityAttributes.bInheritHandle = TRUE;

LOG_INFO(L"Invoking where.exe to find dotnet.exe");
Expand All @@ -443,14 +443,14 @@ HostFxrResolver::InvokeWhereToFindDotnet()
pwzDotnetName = L"\"where.exe\" dotnet.exe";

// Create a process to invoke where.exe
FINISHED_LAST_ERROR_IF(!CreateProcessW(NULL,
FINISHED_LAST_ERROR_IF(!CreateProcessW(nullptr,
pwzDotnetName,
NULL,
NULL,
nullptr,
nullptr,
TRUE,
CREATE_NO_WINDOW,
NULL,
NULL,
nullptr,
nullptr,
&startupInfo,
&processInformation
));
Expand Down Expand Up @@ -480,7 +480,7 @@ HostFxrResolver::InvokeWhereToFindDotnet()

// Where succeeded.
// Reset file pointer to the beginning of the file.
dwFilePointer = SetFilePointer(hStdOutReadPipe, 0, NULL, FILE_BEGIN);
dwFilePointer = SetFilePointer(hStdOutReadPipe, 0, nullptr, FILE_BEGIN);
if (dwFilePointer == INVALID_SET_FILE_POINTER)
{
FINISHED_IF_FAILED(E_FAIL);
Expand All @@ -490,7 +490,7 @@ HostFxrResolver::InvokeWhereToFindDotnet()
// As the call to where.exe succeeded (dotnet.exe was found), ReadFile should not hang.
// TODO consider putting ReadFile in a separate thread with a timeout to guarantee it doesn't block.
//
FINISHED_LAST_ERROR_IF (!ReadFile(hStdOutReadPipe, pzFileContents, READ_BUFFER_SIZE, &dwNumBytesRead, NULL));
FINISHED_LAST_ERROR_IF (!ReadFile(hStdOutReadPipe, pzFileContents, READ_BUFFER_SIZE, &dwNumBytesRead, nullptr));

if (dwNumBytesRead >= READ_BUFFER_SIZE)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std::optional<DWORD> RegistryKey::TryGetDWORD(HKEY section, const std::wstring&

std::optional<std::wstring> RegistryKey::TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName)
{
DWORD cbData;
DWORD cbData{};

if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ, nullptr, nullptr, &cbData)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ServerErrorHandler : public REQUEST_HANDLER
m_disableStartupPage(disableStartupPage),
m_statusCode(statusCode),
m_subStatusCode(subStatusCode),
m_statusText(std::move(statusText)),
m_statusText(statusText),
m_ExceptionInfoContent(responseContent)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::wstring to_wide_string(const std::string& source, const int length, const u

std::wstring destination;

int nChars = MultiByteToWideChar(codePage, 0, source.data(), length, NULL, 0);
int nChars = MultiByteToWideChar(codePage, 0, source.data(), length, nullptr, 0);
THROW_LAST_ERROR_IF(nChars == 0);

destination.resize(nChars);
Expand Down
14 changes: 10 additions & 4 deletions src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ GetVersionInfoString()
{
DWORD verHandle = 0;
UINT size = 0;
LPVOID lpBuffer = NULL;
LPVOID lpBuffer = nullptr;

auto path = GetModuleName();

Expand All @@ -92,7 +92,7 @@ GetVersionInfoString()
RETURN_IF_FAILED(E_FAIL);
}

LPVOID pvProductName = NULL;
LPVOID pvProductName = nullptr;
unsigned int iProductNameLen = 0;
RETURN_LAST_ERROR_IF(!VerQueryValue(verData.data(), _T("\\StringFileInfo\\040904b0\\FileDescription"), &pvProductName, &iProductNameLen));

Expand All @@ -114,7 +114,7 @@ std::wstring
GetModuleName()
{
WCHAR path[MAX_PATH];
LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, sizeof(path)));
LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, _countof(path)));
return path;
}

Expand Down Expand Up @@ -218,7 +218,7 @@ DebugInitialize(HMODULE hModule)
cbData = sizeof(dwData);
if ((RegQueryValueEx(hKey,
L"DebugFlags",
NULL,
nullptr,
&dwType,
(LPBYTE)&dwData,
&cbData) == NO_ERROR) &&
Expand Down Expand Up @@ -409,7 +409,10 @@ DebugPrintfW(

hr = strCooked.SafeVsnwprintf(szFormat, args );

#pragma warning(push)
#pragma warning(disable: 26477) // va_end uses 0
va_end( args );
#pragma warning(pop)

if (FAILED (hr))
{
Expand Down Expand Up @@ -453,7 +456,10 @@ DebugPrintf(

hr = strCooked.SafeVsnprintf(szFormat, args );

#pragma warning(push)
#pragma warning(disable: 26477) // va_end uses 0
va_end( args );
#pragma warning(pop)

if (FAILED (hr))
{
Expand Down
8 changes: 4 additions & 4 deletions src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FILE_UTILITY::ConvertPathToFullPath(
{
HRESULT hr = S_OK;
STRU strFileFullPath;
LPWSTR pszFullPath = NULL;
LPWSTR pszFullPath = nullptr;

// if relative path, prefix with root path and then convert to absolute path.
if ( PathIsRelative(pszPath) )
Expand Down Expand Up @@ -72,7 +72,7 @@ FILE_UTILITY::ConvertPathToFullPath(

if(_wfullpath( pszFullPath,
strFileFullPath.QueryStr(),
strFileFullPath.QueryCCH() + 1 ) == NULL )
strFileFullPath.QueryCCH() + 1 ) == nullptr )
{
hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
goto Finished;
Expand All @@ -87,10 +87,10 @@ FILE_UTILITY::ConvertPathToFullPath(

Finished:

if ( pszFullPath != NULL )
if ( pszFullPath != nullptr )
{
delete[] pszFullPath;
pszFullPath = NULL;
pszFullPath = nullptr;
}

return hr;
Expand Down
18 changes: 9 additions & 9 deletions src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class STTIMER
public:

STTIMER()
: _pTimer( NULL )
: _pTimer( nullptr )
{
fInCanel = FALSE;
}
Expand All @@ -25,7 +25,7 @@ class STTIMER
{
CancelTimer();
CloseThreadpoolTimer( _pTimer );
_pTimer = NULL;
_pTimer = nullptr;
}
}

Expand All @@ -39,7 +39,7 @@ class STTIMER
{
_pTimer = CreateThreadpoolTimer( pfnCallback,
pContext,
NULL );
nullptr );

if ( !_pTimer )
{
Expand Down Expand Up @@ -74,9 +74,9 @@ class STTIMER
// re-enabled by setting non-zero initial wait or
// period values.
//
if (_pTimer != NULL)
if (_pTimer != nullptr)
{
SetThreadpoolTimer(_pTimer, NULL, 0, 0);
SetThreadpoolTimer(_pTimer, nullptr, 0, 0);
}

return;
Expand Down Expand Up @@ -106,7 +106,7 @@ class STTIMER
// Wait until any callbacks queued prior to disabling
// have completed.
//
if (_pTimer != NULL)
if (_pTimer != nullptr)
{
WaitForThreadpoolTimerCallbacks(_pTimer, TRUE);
}
Expand All @@ -124,21 +124,21 @@ class STTIMER
)
{
STRU* pstruLogFilePath = (STRU*)Context;
HANDLE hStdoutHandle = NULL;
HANDLE hStdoutHandle = nullptr;
SECURITY_ATTRIBUTES saAttr = { 0 };
HRESULT hr = S_OK;

saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
saAttr.lpSecurityDescriptor = nullptr;

hStdoutHandle = CreateFileW(pstruLogFilePath->QueryStr(),
FILE_READ_DATA,
FILE_SHARE_WRITE,
&saAttr,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
nullptr);
if (hStdoutHandle == INVALID_HANDLE_VALUE)
{
hr = HRESULT_FROM_WIN32(GetLastError());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ProjectGuid>{1eac8125-1765-4e2d-8cbe-56dc98a1c8c1}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>$(PlatformToolsetVersion)</PlatformToolset>
<PlatformToolset>v$(PlatformToolsetVersion)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<IsTestProject>true</IsTestProject>
<DisableArcadeTestFramework>true</DisableArcadeTestFramework>
Expand Down
Loading

0 comments on commit 35d957a

Please sign in to comment.