Skip to content

Commit d48bfe2

Browse files
adityamandaleekacaptainsafia
authored andcommitted
Address variable initialization warnings in ANCM (C26494) (#58904)
1 parent 4877557 commit d48bfe2

25 files changed

+118
-124
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,21 +402,21 @@ HostFxrResolver::InvokeWhereToFindDotnet()
402402
// Arguments to call where.exe
403403
STARTUPINFOW startupInfo{};
404404
PROCESS_INFORMATION processInformation{};
405-
SECURITY_ATTRIBUTES securityAttributes;
405+
SECURITY_ATTRIBUTES securityAttributes{};
406406

407-
CHAR pzFileContents[READ_BUFFER_SIZE];
407+
CHAR pzFileContents[READ_BUFFER_SIZE]{0};
408408
HandleWrapper<InvalidHandleTraits> hStdOutReadPipe;
409409
HandleWrapper<InvalidHandleTraits> hStdOutWritePipe;
410410
HandleWrapper<InvalidHandleTraits> hProcess;
411411
HandleWrapper<InvalidHandleTraits> hThread;
412412
CComBSTR pwzDotnetName = nullptr;
413-
DWORD dwFilePointer;
414-
BOOL fIsCurrentProcess64Bit;
415-
DWORD dwExitCode;
413+
DWORD dwFilePointer = 0;
414+
BOOL fIsCurrentProcess64Bit = FALSE;
415+
DWORD dwExitCode = 0;
416416
STRU struDotnetSubstring;
417417
STRU struDotnetLocationsString;
418-
DWORD dwNumBytesRead;
419-
DWORD dwBinaryType;
418+
DWORD dwNumBytesRead = 0;
419+
DWORD dwBinaryType = 0;
420420
INT index = 0;
421421
INT prevIndex = 0;
422422
std::optional<fs::path> result;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ StandardStreamRedirection::~StandardStreamRedirection() noexcept(false)
5555
void StandardStreamRedirection::Start()
5656
{
5757
SECURITY_ATTRIBUTES saAttr = { 0 };
58-
HANDLE hStdErrReadPipe;
59-
HANDLE hStdErrWritePipe;
58+
HANDLE hStdErrReadPipe = nullptr;
59+
HANDLE hStdErrWritePipe = nullptr;
6060

6161
// To make Console.* functions work, allocate a console
6262
// in the current process.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ StdWrapper::~StdWrapper() = default;
3232
HRESULT
3333
StdWrapper::StartRedirection()
3434
{
35-
HANDLE stdHandle;
35+
HANDLE stdHandle = nullptr;
3636

3737
// In IIS, stdout and stderr are set to null as w3wp is created with DETACHED_PROCESS,
3838
// so fileno(m_stdStream) returns -2.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ std::optional<std::shared_ptr<ConfigurationSection>> WebConfigConfigurationSecti
6565
std::vector<std::shared_ptr<ConfigurationSection>> WebConfigConfigurationSection::GetCollection() const
6666
{
6767
std::vector<std::shared_ptr<ConfigurationSection>> elements;
68-
HRESULT findElementResult;
68+
HRESULT findElementResult = S_OK;
6969
CComPtr<IAppHostElementCollection> elementCollection = nullptr;
7070
CComPtr<IAppHostElement> collectionEntry = nullptr;
7171
ENUM_INDEX index{};

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ class WWWServerTraceProvider
5959
enumAreaFlags AreaFlags,
6060
DWORD dwVerbosity )
6161
{
62-
HRESULT hr;
6362
HTTP_TRACE_CONFIGURATION TraceConfig;
6463
TraceConfig.pProviderGuid = GetProviderGuid();
65-
hr = pHttpTraceContext->GetTraceConfiguration( &TraceConfig );
64+
HRESULT hr = pHttpTraceContext->GetTraceConfiguration( &TraceConfig );
6665
if ( FAILED( hr ) || !TraceConfig.fProviderEnabled )
6766
{
6867
return FALSE;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ConfigUtility
6161
HRESULT
6262
FindKeyValuePair(IAppHostElement* pElement, PCWSTR key, STRU& strHandlerVersionValue)
6363
{
64-
HRESULT hr;
64+
HRESULT hr = S_OK;
6565
CComPtr<IAppHostElement> pHandlerSettings = nullptr;
6666
CComPtr<IAppHostElementCollection> pHandlerSettingsCollection = nullptr;
6767
CComPtr<IAppHostElement> pHandlerVar = nullptr;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ DebugInitialize(HMODULE hModule)
211211
KEY_READ,
212212
&hKey) == NO_ERROR)
213213
{
214-
DWORD dwType;
215-
DWORD dwData;
216-
DWORD cbData;
214+
DWORD dwType{0};
215+
DWORD dwData{0};
216+
DWORD cbData{0};
217217

218218
cbData = sizeof(dwData);
219219
if ((RegQueryValueEx(hKey,
@@ -373,7 +373,7 @@ DebugPrintW(
373373

374374
if (IsEnabled(ASPNETCORE_DEBUG_FLAG_EVENTLOG))
375375
{
376-
WORD eventType;
376+
WORD eventType = EVENTLOG_INFORMATION_TYPE;
377377
switch (dwFlag)
378378
{
379379
case ASPNETCORE_DEBUG_FLAG_ERROR:

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class STTIMER
6161
DWORD dwPeriod = 0
6262
)
6363
{
64-
FILETIME ftInitialWait;
64+
FILETIME ftInitialWait{};
6565

6666
if ( dwInitialWait == 0 && dwPeriod == 0 )
6767
{
@@ -186,12 +186,10 @@ class STELAPSED
186186
_dwPerfCountsPerMillisecond( 0 ),
187187
_fUsingHighResolution( FALSE )
188188
{
189-
LARGE_INTEGER li;
190-
BOOL fResult;
191-
189+
LARGE_INTEGER li{};
192190
_dwInitTickCount = GetTickCount64();
193191

194-
fResult = QueryPerformanceFrequency( &li );
192+
BOOL fResult = QueryPerformanceFrequency( &li );
195193

196194
if ( !fResult )
197195
{
@@ -224,7 +222,7 @@ class STELAPSED
224222
LONGLONG
225223
QueryElapsedTime()
226224
{
227-
LARGE_INTEGER li;
225+
LARGE_INTEGER li{};
228226

229227
if ( _fUsingHighResolution && QueryPerformanceCounter( &li ) )
230228
{

src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<Rule Id="C26491" Action="Error" />
9393
<Rule Id="C26492" Action="None" /> <!-- Don't use const_cast to cast away const. -->
9494
<Rule Id="C26493" Action="None" /> <!-- Don't use C-style casts. -->
95-
<Rule Id="C26494" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize an object. -->
95+
<Rule Id="C26494" Action="Error" /> <!-- Variable 'variable' is uninitialized. Always initialize an object. -->
9696
<Rule Id="C26495" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize a member variable -->
9797
<Rule Id="C26496" Action="None" /> <!-- The variable 'variable' is assigned only once, mark it as const. -->
9898
<Rule Id="C26497" Action="Error" />

src/Servers/IIS/AspNetCoreModuleV2/IISLib/ahutil.cpp

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ DeleteElementFromCollection(
489489
)
490490
{
491491
HRESULT hr = NOERROR;
492-
ULONG index;
492+
ULONG index = 0;
493493

494494
VARIANT varIndex;
495495
VariantInit( &varIndex );
@@ -627,15 +627,13 @@ FindElementInCollection(
627627
VARIANT varKeyValue;
628628
VariantInit( &varKeyValue );
629629

630-
DWORD count;
631-
DWORD i;
630+
DWORD count = 0;
631+
DWORD i = 0;
632632

633633
BSTR bstrKeyName = nullptr;
634-
PFN_FIND_COMPARE_PROC compareProc;
635-
636-
compareProc = (BehaviorFlags & FIND_ELEMENT_CASE_INSENSITIVE)
637-
? &FindCompareCaseInsensitive
638-
: &FindCompareCaseSensitive;
634+
PFN_FIND_COMPARE_PROC compareProc = (BehaviorFlags & FIND_ELEMENT_CASE_INSENSITIVE)
635+
? &FindCompareCaseInsensitive
636+
: &FindCompareCaseSensitive;
639637

640638
bstrKeyName = SysAllocString( szKeyName );
641639
if( !bstrKeyName )
@@ -761,8 +759,6 @@ GetLocationFromFile(
761759
CComPtr<IAppHostConfigLocationCollection> pLocationCollection;
762760
CComPtr<IAppHostConfigLocation> pLocation;
763761

764-
BSTR bstrLocationPath = nullptr;
765-
766762
*ppLocation = nullptr;
767763
*pFound = FALSE;
768764

@@ -773,21 +769,23 @@ GetLocationFromFile(
773769
if( FAILED(hr) )
774770
{
775771
DBGERROR_HR(hr);
776-
goto exit;
772+
return hr;
777773
}
778774

779-
DWORD count;
780-
DWORD i;
775+
DWORD count = 0;
776+
DWORD i = 0;
781777
VARIANT varIndex;
782778
VariantInit( &varIndex );
783779

784780
hr = pLocationCollection->get_Count( &count );
785781
if( FAILED(hr) )
786782
{
787783
DBGERROR_HR(hr);
788-
goto exit;
784+
return hr;
789785
}
790786

787+
BSTR bstrLocationPath = nullptr;
788+
791789
for( i = 0; i < count; i++ )
792790
{
793791
varIndex.vt = VT_UI4;
@@ -841,8 +839,8 @@ GetSectionFromLocation(
841839

842840
CComPtr<IAppHostElement> pSectionElement;
843841

844-
DWORD count;
845-
DWORD i;
842+
DWORD count = 0;
843+
DWORD i = 0;
846844

847845
VARIANT varIndex;
848846
VariantInit( &varIndex );
@@ -1002,8 +1000,8 @@ ClearElementFromAllSites(
10021000
CComPtr<IAppHostElementCollection> pSitesCollection;
10031001
CComPtr<IAppHostElement> pSiteElement;
10041002
CComPtr<IAppHostChildElementCollection> pChildCollection;
1005-
ENUM_INDEX index;
1006-
BOOL found;
1003+
ENUM_INDEX index{};
1004+
BOOL found = false;
10071005

10081006
//
10091007
// Enumerate the sites, remove the specified elements.
@@ -1074,7 +1072,7 @@ ClearElementFromAllLocations(
10741072
CComPtr<IAppHostConfigLocationCollection> pLocationCollection;
10751073
CComPtr<IAppHostConfigLocation> pLocation;
10761074
CComPtr<IAppHostChildElementCollection> pChildCollection;
1077-
ENUM_INDEX index;
1075+
ENUM_INDEX index{};
10781076

10791077
//
10801078
// Enum the <location> tags, remove the specified elements.
@@ -1125,10 +1123,10 @@ ClearLocationElements(
11251123
IN CONST WCHAR * szElementName
11261124
)
11271125
{
1128-
HRESULT hr;
1126+
HRESULT hr = S_OK;
11291127
CComPtr<IAppHostElement> pElement;
1130-
ENUM_INDEX index;
1131-
BOOL matched;
1128+
ENUM_INDEX index{};
1129+
BOOL matched = false;
11321130

11331131
for (hr = FindFirstLocationElement(pLocation, &index, &pElement) ;
11341132
SUCCEEDED(hr) ;
@@ -1199,10 +1197,10 @@ ClearChildElementsByName(
11991197
OUT BOOL * pFound
12001198
)
12011199
{
1202-
HRESULT hr;
1200+
HRESULT hr = S_OK;
12031201
CComPtr<IAppHostElement> pElement;
1204-
ENUM_INDEX index;
1205-
BOOL matched;
1202+
ENUM_INDEX index{};
1203+
BOOL matched = false;
12061204

12071205
*pFound = FALSE;
12081206

@@ -1253,7 +1251,7 @@ GetSitesCollection(
12531251
OUT IAppHostElementCollection ** pSitesCollection
12541252
)
12551253
{
1256-
HRESULT hr;
1254+
HRESULT hr = S_OK;
12571255
CComPtr<IAppHostElement> pSitesElement;
12581256

12591257
BSTR bstrConfigPath = SysAllocString(szConfigPath);
@@ -1304,7 +1302,7 @@ GetLocationCollection(
13041302
OUT IAppHostConfigLocationCollection ** pLocationCollection
13051303
)
13061304
{
1307-
HRESULT hr;
1305+
HRESULT hr = S_OK;
13081306
CComPtr<IAppHostConfigManager> pConfigMgr;
13091307
CComPtr<IAppHostConfigFile> pConfigFile;
13101308

0 commit comments

Comments
 (0)