Skip to content

Commit 35d957a

Browse files
Merge pull request #58304 from adityamandaleeka/ancm_ca_changes_incr
Enable code analysis and address initial set of issues.
2 parents 7f85154 + c1752f6 commit 35d957a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+861
-1003
lines changed

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
301301
auto shadowCopyBaseDirectory = std::filesystem::directory_entry(shadowCopyPath);
302302
if (!shadowCopyBaseDirectory.exists())
303303
{
304-
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), NULL);
304+
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), nullptr);
305305
}
306306

307307
for (auto& entry : std::filesystem::directory_iterator(shadowCopyPath))

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ BOOL WINAPI DllMain(HMODULE hModule,
5757
// this is a bug in IIS. To try to avoid AVs, we will set a global flag
5858
g_fInShutdown = TRUE;
5959
StaticCleanup();
60+
break;
6061
default:
6162
break;
6263
}

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void Environment::CopyToDirectoryInner(const std::filesystem::path& source, cons
168168
auto destinationDirEntry = std::filesystem::directory_entry(destination);
169169
if (!destinationDirEntry.exists())
170170
{
171-
CreateDirectory(destination.wstring().c_str(), NULL);
171+
CreateDirectory(destination.wstring().c_str(), nullptr);
172172
}
173173

174174
for (auto& path : std::filesystem::directory_iterator(source))

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/EventLog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ EventLog::LogEventNoTrace(
3636
dwEventInfoType,
3737
0, // wCategory
3838
dwEventId,
39-
NULL, // lpUserSid
39+
nullptr, // lpUserSid
4040
static_cast<WORD>(eventLogDataStrings.size()), // wNumStrings
4141
0, // dwDataSize,
4242
eventLogDataStrings.data(),
43-
NULL // lpRawData
43+
nullptr // lpRawData
4444
);
4545
}
4646

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/GlobalVersionUtility.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ namespace fs = std::filesystem;
1313
std::wstring
1414
GlobalVersionUtility::GetGlobalRequestHandlerPath(PCWSTR pwzAspNetCoreFolderPath, PCWSTR pwzHandlerVersion, PCWSTR pwzHandlerName)
1515
{
16-
if (pwzAspNetCoreFolderPath == NULL)
16+
if (pwzAspNetCoreFolderPath == nullptr)
1717
{
1818
throw new std::invalid_argument("pwzAspNetCoreFolderPath is NULL");
1919
}
2020

21-
if (pwzHandlerVersion == NULL)
21+
if (pwzHandlerVersion == nullptr)
2222
{
2323
throw new std::invalid_argument("pwzHandlerVersion is NULL");
2424
}
2525

26-
if (pwzHandlerName == NULL)
26+
if (pwzHandlerName == nullptr)
2727
{
2828
throw new std::invalid_argument("pwzHandlerName is NULL");
2929
}
@@ -47,7 +47,7 @@ GlobalVersionUtility::GetGlobalRequestHandlerPath(PCWSTR pwzAspNetCoreFolderPath
4747
std::vector<fx_ver_t>
4848
GlobalVersionUtility::GetRequestHandlerVersions(PCWSTR pwzAspNetCoreFolderPath)
4949
{
50-
if (pwzAspNetCoreFolderPath == NULL)
50+
if (pwzAspNetCoreFolderPath == nullptr)
5151
{
5252
throw new std::invalid_argument("pwzAspNetCoreFolderPath is NULL");
5353
}
@@ -74,7 +74,7 @@ GlobalVersionUtility::GetRequestHandlerVersions(PCWSTR pwzAspNetCoreFolderPath)
7474
std::wstring
7575
GlobalVersionUtility::FindHighestGlobalVersion(PCWSTR pwzAspNetCoreFolderPath)
7676
{
77-
if (pwzAspNetCoreFolderPath == NULL)
77+
if (pwzAspNetCoreFolderPath == nullptr)
7878
{
7979
throw std::invalid_argument("pwzAspNetCoreFolderPath is NULL");
8080
}

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,16 @@ HostFxrResolver::InvokeWhereToFindDotnet()
400400
{
401401
HRESULT hr = S_OK;
402402
// Arguments to call where.exe
403-
STARTUPINFOW startupInfo = { 0 };
404-
PROCESS_INFORMATION processInformation = { 0 };
403+
STARTUPINFOW startupInfo{};
404+
PROCESS_INFORMATION processInformation{};
405405
SECURITY_ATTRIBUTES securityAttributes;
406406

407407
CHAR pzFileContents[READ_BUFFER_SIZE];
408408
HandleWrapper<InvalidHandleTraits> hStdOutReadPipe;
409409
HandleWrapper<InvalidHandleTraits> hStdOutWritePipe;
410410
HandleWrapper<InvalidHandleTraits> hProcess;
411411
HandleWrapper<InvalidHandleTraits> hThread;
412-
CComBSTR pwzDotnetName = NULL;
412+
CComBSTR pwzDotnetName = nullptr;
413413
DWORD dwFilePointer;
414414
BOOL fIsCurrentProcess64Bit;
415415
DWORD dwExitCode;
@@ -423,7 +423,7 @@ HostFxrResolver::InvokeWhereToFindDotnet()
423423

424424
// Set the security attributes for the read/write pipe
425425
securityAttributes.nLength = sizeof(securityAttributes);
426-
securityAttributes.lpSecurityDescriptor = NULL;
426+
securityAttributes.lpSecurityDescriptor = nullptr;
427427
securityAttributes.bInheritHandle = TRUE;
428428

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

445445
// Create a process to invoke where.exe
446-
FINISHED_LAST_ERROR_IF(!CreateProcessW(NULL,
446+
FINISHED_LAST_ERROR_IF(!CreateProcessW(nullptr,
447447
pwzDotnetName,
448-
NULL,
449-
NULL,
448+
nullptr,
449+
nullptr,
450450
TRUE,
451451
CREATE_NO_WINDOW,
452-
NULL,
453-
NULL,
452+
nullptr,
453+
nullptr,
454454
&startupInfo,
455455
&processInformation
456456
));
@@ -480,7 +480,7 @@ HostFxrResolver::InvokeWhereToFindDotnet()
480480

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

495495
if (dwNumBytesRead >= READ_BUFFER_SIZE)
496496
{

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ std::optional<DWORD> RegistryKey::TryGetDWORD(HKEY section, const std::wstring&
1818

1919
std::optional<std::wstring> RegistryKey::TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName)
2020
{
21-
DWORD cbData;
21+
DWORD cbData{};
2222

2323
if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ, nullptr, nullptr, &cbData)))
2424
{

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ServerErrorHandler : public REQUEST_HANDLER
1515
m_disableStartupPage(disableStartupPage),
1616
m_statusCode(statusCode),
1717
m_subStatusCode(subStatusCode),
18-
m_statusText(std::move(statusText)),
18+
m_statusText(statusText),
1919
m_ExceptionInfoContent(responseContent)
2020
{
2121
}

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/StringHelpers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ std::wstring to_wide_string(const std::string& source, const int length, const u
4141

4242
std::wstring destination;
4343

44-
int nChars = MultiByteToWideChar(codePage, 0, source.data(), length, NULL, 0);
44+
int nChars = MultiByteToWideChar(codePage, 0, source.data(), length, nullptr, 0);
4545
THROW_LAST_ERROR_IF(nChars == 0);
4646

4747
destination.resize(nChars);

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ GetVersionInfoString()
7373
{
7474
DWORD verHandle = 0;
7575
UINT size = 0;
76-
LPVOID lpBuffer = NULL;
76+
LPVOID lpBuffer = nullptr;
7777

7878
auto path = GetModuleName();
7979

@@ -92,7 +92,7 @@ GetVersionInfoString()
9292
RETURN_IF_FAILED(E_FAIL);
9393
}
9494

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

@@ -114,7 +114,7 @@ std::wstring
114114
GetModuleName()
115115
{
116116
WCHAR path[MAX_PATH];
117-
LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, sizeof(path)));
117+
LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, _countof(path)));
118118
return path;
119119
}
120120

@@ -218,7 +218,7 @@ DebugInitialize(HMODULE hModule)
218218
cbData = sizeof(dwData);
219219
if ((RegQueryValueEx(hKey,
220220
L"DebugFlags",
221-
NULL,
221+
nullptr,
222222
&dwType,
223223
(LPBYTE)&dwData,
224224
&cbData) == NO_ERROR) &&
@@ -409,7 +409,10 @@ DebugPrintfW(
409409

410410
hr = strCooked.SafeVsnwprintf(szFormat, args );
411411

412+
#pragma warning(push)
413+
#pragma warning(disable: 26477) // va_end uses 0
412414
va_end( args );
415+
#pragma warning(pop)
413416

414417
if (FAILED (hr))
415418
{
@@ -453,7 +456,10 @@ DebugPrintf(
453456

454457
hr = strCooked.SafeVsnprintf(szFormat, args );
455458

459+
#pragma warning(push)
460+
#pragma warning(disable: 26477) // va_end uses 0
456461
va_end( args );
462+
#pragma warning(pop)
457463

458464
if (FAILED (hr))
459465
{

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ FILE_UTILITY::ConvertPathToFullPath(
4141
{
4242
HRESULT hr = S_OK;
4343
STRU strFileFullPath;
44-
LPWSTR pszFullPath = NULL;
44+
LPWSTR pszFullPath = nullptr;
4545

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

7373
if(_wfullpath( pszFullPath,
7474
strFileFullPath.QueryStr(),
75-
strFileFullPath.QueryCCH() + 1 ) == NULL )
75+
strFileFullPath.QueryCCH() + 1 ) == nullptr )
7676
{
7777
hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
7878
goto Finished;
@@ -87,10 +87,10 @@ FILE_UTILITY::ConvertPathToFullPath(
8787

8888
Finished:
8989

90-
if ( pszFullPath != NULL )
90+
if ( pszFullPath != nullptr )
9191
{
9292
delete[] pszFullPath;
93-
pszFullPath = NULL;
93+
pszFullPath = nullptr;
9494
}
9595

9696
return hr;

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class STTIMER
1313
public:
1414

1515
STTIMER()
16-
: _pTimer( NULL )
16+
: _pTimer( nullptr )
1717
{
1818
fInCanel = FALSE;
1919
}
@@ -25,7 +25,7 @@ class STTIMER
2525
{
2626
CancelTimer();
2727
CloseThreadpoolTimer( _pTimer );
28-
_pTimer = NULL;
28+
_pTimer = nullptr;
2929
}
3030
}
3131

@@ -39,7 +39,7 @@ class STTIMER
3939
{
4040
_pTimer = CreateThreadpoolTimer( pfnCallback,
4141
pContext,
42-
NULL );
42+
nullptr );
4343

4444
if ( !_pTimer )
4545
{
@@ -74,9 +74,9 @@ class STTIMER
7474
// re-enabled by setting non-zero initial wait or
7575
// period values.
7676
//
77-
if (_pTimer != NULL)
77+
if (_pTimer != nullptr)
7878
{
79-
SetThreadpoolTimer(_pTimer, NULL, 0, 0);
79+
SetThreadpoolTimer(_pTimer, nullptr, 0, 0);
8080
}
8181

8282
return;
@@ -106,7 +106,7 @@ class STTIMER
106106
// Wait until any callbacks queued prior to disabling
107107
// have completed.
108108
//
109-
if (_pTimer != NULL)
109+
if (_pTimer != nullptr)
110110
{
111111
WaitForThreadpoolTimerCallbacks(_pTimer, TRUE);
112112
}
@@ -124,21 +124,21 @@ class STTIMER
124124
)
125125
{
126126
STRU* pstruLogFilePath = (STRU*)Context;
127-
HANDLE hStdoutHandle = NULL;
127+
HANDLE hStdoutHandle = nullptr;
128128
SECURITY_ATTRIBUTES saAttr = { 0 };
129129
HRESULT hr = S_OK;
130130

131131
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
132132
saAttr.bInheritHandle = TRUE;
133-
saAttr.lpSecurityDescriptor = NULL;
133+
saAttr.lpSecurityDescriptor = nullptr;
134134

135135
hStdoutHandle = CreateFileW(pstruLogFilePath->QueryStr(),
136136
FILE_READ_DATA,
137137
FILE_SHARE_WRITE,
138138
&saAttr,
139139
OPEN_ALWAYS,
140140
FILE_ATTRIBUTE_NORMAL,
141-
NULL);
141+
nullptr);
142142
if (hStdoutHandle == INVALID_HANDLE_VALUE)
143143
{
144144
hr = HRESULT_FROM_WIN32(GetLastError());

src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/CommonLibTests.vcxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ProjectGuid>{1eac8125-1765-4e2d-8cbe-56dc98a1c8c1}</ProjectGuid>
1010
<Keyword>Win32Proj</Keyword>
1111
<ConfigurationType>Application</ConfigurationType>
12-
<PlatformToolset>$(PlatformToolsetVersion)</PlatformToolset>
12+
<PlatformToolset>v$(PlatformToolsetVersion)</PlatformToolset>
1313
<CharacterSet>Unicode</CharacterSet>
1414
<IsTestProject>true</IsTestProject>
1515
<DisableArcadeTestFramework>true</DisableArcadeTestFramework>

0 commit comments

Comments
 (0)