Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address variable initialization warnings in ANCM (C26494) #58904

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -402,21 +402,21 @@ HostFxrResolver::InvokeWhereToFindDotnet()
// Arguments to call where.exe
STARTUPINFOW startupInfo{};
PROCESS_INFORMATION processInformation{};
SECURITY_ATTRIBUTES securityAttributes;
SECURITY_ATTRIBUTES securityAttributes{};

CHAR pzFileContents[READ_BUFFER_SIZE];
CHAR pzFileContents[READ_BUFFER_SIZE]{0};
HandleWrapper<InvalidHandleTraits> hStdOutReadPipe;
HandleWrapper<InvalidHandleTraits> hStdOutWritePipe;
HandleWrapper<InvalidHandleTraits> hProcess;
HandleWrapper<InvalidHandleTraits> hThread;
CComBSTR pwzDotnetName = nullptr;
DWORD dwFilePointer;
BOOL fIsCurrentProcess64Bit;
DWORD dwExitCode;
DWORD dwFilePointer = 0;
BOOL fIsCurrentProcess64Bit = FALSE;
DWORD dwExitCode = 0;
STRU struDotnetSubstring;
STRU struDotnetLocationsString;
DWORD dwNumBytesRead;
DWORD dwBinaryType;
DWORD dwNumBytesRead = 0;
DWORD dwBinaryType = 0;
INT index = 0;
INT prevIndex = 0;
std::optional<fs::path> result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ StandardStreamRedirection::~StandardStreamRedirection() noexcept(false)
void StandardStreamRedirection::Start()
{
SECURITY_ATTRIBUTES saAttr = { 0 };
HANDLE hStdErrReadPipe;
HANDLE hStdErrWritePipe;
HANDLE hStdErrReadPipe = nullptr;
HANDLE hStdErrWritePipe = nullptr;

// To make Console.* functions work, allocate a console
// in the current process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ StdWrapper::~StdWrapper() = default;
HRESULT
StdWrapper::StartRedirection()
{
HANDLE stdHandle;
HANDLE stdHandle = nullptr;

// In IIS, stdout and stderr are set to null as w3wp is created with DETACHED_PROCESS,
// so fileno(m_stdStream) returns -2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::optional<std::shared_ptr<ConfigurationSection>> WebConfigConfigurationSecti
std::vector<std::shared_ptr<ConfigurationSection>> WebConfigConfigurationSection::GetCollection() const
{
std::vector<std::shared_ptr<ConfigurationSection>> elements;
HRESULT findElementResult;
HRESULT findElementResult = S_OK;
CComPtr<IAppHostElementCollection> elementCollection = nullptr;
CComPtr<IAppHostElement> collectionEntry = nullptr;
ENUM_INDEX index{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ConfigUtility
HRESULT
FindKeyValuePair(IAppHostElement* pElement, PCWSTR key, STRU& strHandlerVersionValue)
{
HRESULT hr;
HRESULT hr = S_OK;
CComPtr<IAppHostElement> pHandlerSettings = nullptr;
CComPtr<IAppHostElementCollection> pHandlerSettingsCollection = nullptr;
CComPtr<IAppHostElement> pHandlerVar = nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ DebugInitialize(HMODULE hModule)
KEY_READ,
&hKey) == NO_ERROR)
{
DWORD dwType;
DWORD dwData;
DWORD cbData;
DWORD dwType{0};
DWORD dwData{0};
DWORD cbData{0};

cbData = sizeof(dwData);
if ((RegQueryValueEx(hKey,
Expand Down Expand Up @@ -373,7 +373,7 @@ DebugPrintW(

if (IsEnabled(ASPNETCORE_DEBUG_FLAG_EVENTLOG))
{
WORD eventType;
WORD eventType = EVENTLOG_INFORMATION_TYPE;
switch (dwFlag)
{
case ASPNETCORE_DEBUG_FLAG_ERROR:
Expand Down
10 changes: 4 additions & 6 deletions src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class STTIMER
DWORD dwPeriod = 0
)
{
FILETIME ftInitialWait;
FILETIME ftInitialWait{};

if ( dwInitialWait == 0 && dwPeriod == 0 )
{
Expand Down Expand Up @@ -186,12 +186,10 @@ class STELAPSED
_dwPerfCountsPerMillisecond( 0 ),
_fUsingHighResolution( FALSE )
{
LARGE_INTEGER li;
BOOL fResult;

LARGE_INTEGER li{};
_dwInitTickCount = GetTickCount64();

fResult = QueryPerformanceFrequency( &li );
BOOL fResult = QueryPerformanceFrequency( &li );

if ( !fResult )
{
Expand Down Expand Up @@ -224,7 +222,7 @@ class STELAPSED
LONGLONG
QueryElapsedTime()
{
LARGE_INTEGER li;
LARGE_INTEGER li{};

if ( _fUsingHighResolution && QueryPerformanceCounter( &li ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<Rule Id="C26491" Action="Error" />
<Rule Id="C26492" Action="None" /> <!-- Don't use const_cast to cast away const. -->
<Rule Id="C26493" Action="None" /> <!-- Don't use C-style casts. -->
<Rule Id="C26494" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize an object. -->
<Rule Id="C26494" Action="Error" /> <!-- Variable 'variable' is uninitialized. Always initialize an object. -->
<Rule Id="C26495" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize a member variable -->
<Rule Id="C26496" Action="None" /> <!-- The variable 'variable' is assigned only once, mark it as const. -->
<Rule Id="C26497" Action="Error" />
Expand Down
52 changes: 25 additions & 27 deletions src/Servers/IIS/AspNetCoreModuleV2/IISLib/ahutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ DeleteElementFromCollection(
)
{
HRESULT hr = NOERROR;
ULONG index;
ULONG index = 0;

VARIANT varIndex;
VariantInit( &varIndex );
Expand Down Expand Up @@ -627,15 +627,13 @@ FindElementInCollection(
VARIANT varKeyValue;
VariantInit( &varKeyValue );

DWORD count;
DWORD i;
DWORD count = 0;
DWORD i = 0;

BSTR bstrKeyName = nullptr;
PFN_FIND_COMPARE_PROC compareProc;

compareProc = (BehaviorFlags & FIND_ELEMENT_CASE_INSENSITIVE)
? &FindCompareCaseInsensitive
: &FindCompareCaseSensitive;
PFN_FIND_COMPARE_PROC compareProc = (BehaviorFlags & FIND_ELEMENT_CASE_INSENSITIVE)
? &FindCompareCaseInsensitive
: &FindCompareCaseSensitive;

bstrKeyName = SysAllocString( szKeyName );
if( !bstrKeyName )
Expand Down Expand Up @@ -761,8 +759,6 @@ GetLocationFromFile(
CComPtr<IAppHostConfigLocationCollection> pLocationCollection;
CComPtr<IAppHostConfigLocation> pLocation;

BSTR bstrLocationPath = nullptr;

*ppLocation = nullptr;
*pFound = FALSE;

Expand All @@ -773,21 +769,23 @@ GetLocationFromFile(
if( FAILED(hr) )
{
DBGERROR_HR(hr);
goto exit;
return hr;
}

DWORD count;
DWORD i;
DWORD count = 0;
DWORD i = 0;
VARIANT varIndex;
VariantInit( &varIndex );

hr = pLocationCollection->get_Count( &count );
if( FAILED(hr) )
{
DBGERROR_HR(hr);
goto exit;
return hr;
}

BSTR bstrLocationPath = nullptr;

for( i = 0; i < count; i++ )
{
varIndex.vt = VT_UI4;
Expand Down Expand Up @@ -841,8 +839,8 @@ GetSectionFromLocation(

CComPtr<IAppHostElement> pSectionElement;

DWORD count;
DWORD i;
DWORD count = 0;
DWORD i = 0;

VARIANT varIndex;
VariantInit( &varIndex );
Expand Down Expand Up @@ -1002,8 +1000,8 @@ ClearElementFromAllSites(
CComPtr<IAppHostElementCollection> pSitesCollection;
CComPtr<IAppHostElement> pSiteElement;
CComPtr<IAppHostChildElementCollection> pChildCollection;
ENUM_INDEX index;
BOOL found;
ENUM_INDEX index{};
BOOL found = false;

//
// Enumerate the sites, remove the specified elements.
Expand Down Expand Up @@ -1074,7 +1072,7 @@ ClearElementFromAllLocations(
CComPtr<IAppHostConfigLocationCollection> pLocationCollection;
CComPtr<IAppHostConfigLocation> pLocation;
CComPtr<IAppHostChildElementCollection> pChildCollection;
ENUM_INDEX index;
ENUM_INDEX index{};

//
// Enum the <location> tags, remove the specified elements.
Expand Down Expand Up @@ -1125,10 +1123,10 @@ ClearLocationElements(
IN CONST WCHAR * szElementName
)
{
HRESULT hr;
HRESULT hr = S_OK;
CComPtr<IAppHostElement> pElement;
ENUM_INDEX index;
BOOL matched;
ENUM_INDEX index{};
BOOL matched = false;

for (hr = FindFirstLocationElement(pLocation, &index, &pElement) ;
SUCCEEDED(hr) ;
Expand Down Expand Up @@ -1199,10 +1197,10 @@ ClearChildElementsByName(
OUT BOOL * pFound
)
{
HRESULT hr;
HRESULT hr = S_OK;
CComPtr<IAppHostElement> pElement;
ENUM_INDEX index;
BOOL matched;
ENUM_INDEX index{};
BOOL matched = false;

*pFound = FALSE;

Expand Down Expand Up @@ -1253,7 +1251,7 @@ GetSitesCollection(
OUT IAppHostElementCollection ** pSitesCollection
)
{
HRESULT hr;
HRESULT hr = S_OK;
CComPtr<IAppHostElement> pSitesElement;

BSTR bstrConfigPath = SysAllocString(szConfigPath);
Expand Down Expand Up @@ -1304,7 +1302,7 @@ GetLocationCollection(
OUT IAppHostConfigLocationCollection ** pLocationCollection
)
{
HRESULT hr;
HRESULT hr = S_OK;
CComPtr<IAppHostConfigManager> pConfigMgr;
CComPtr<IAppHostConfigFile> pConfigFile;

Expand Down
16 changes: 8 additions & 8 deletions src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Return Values:
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};

DWORD ib;
DWORD ich;
DWORD cchEncoded;
BYTE b0, b1, b2;
DWORD ib{0};
DWORD ich{0};
DWORD cchEncoded{0};
BYTE b0{0}, b1{0}, b2{0};
BYTE * pbDecodedBuffer = static_cast<BYTE*>(pDecodedBuffer);

// Calculate encoded string size.
Expand Down Expand Up @@ -177,10 +177,10 @@ Return Values:
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};

DWORD ib;
DWORD ich;
DWORD cchEncoded;
BYTE b0, b1, b2;
DWORD ib{0};
DWORD ich{0};
DWORD cchEncoded{0};
BYTE b0{0}, b1{0}, b2{0};
BYTE * pbDecodedBuffer = (BYTE *) pDecodedBuffer;

// Calculate encoded string size.
Expand Down
20 changes: 10 additions & 10 deletions src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ HASH_TABLE<_Record,_Key>::DeleteIf(
PVOID pvContext
)
{
HASH_NODE<_Record> *pNode;
HASH_NODE<_Record> **ppPreviousNodeNextPointer;
HASH_NODE<_Record> *pNode = nullptr;
HASH_NODE<_Record> **ppPreviousNodeNextPointer = nullptr;

_tableLock.ExclusiveAcquire();

Expand Down Expand Up @@ -568,7 +568,7 @@ HASH_TABLE<_Record,_Key>::Apply(
PVOID pvContext
)
{
HASH_NODE<_Record> *pNode;
HASH_NODE<_Record> *pNode = nullptr;

_tableLock.SharedAcquire();

Expand All @@ -595,13 +595,13 @@ HASH_TABLE<_Record,_Key>::RehashTableIfNeeded(
VOID
)
{
HASH_NODE<_Record> **ppBuckets;
DWORD nBuckets;
HASH_NODE<_Record> *pNode;
HASH_NODE<_Record> *pNextNode;
HASH_NODE<_Record> **ppNextPointer;
HASH_NODE<_Record> *pNewNextNode;
DWORD nNewBuckets;
HASH_NODE<_Record> **ppBuckets = nullptr;
DWORD nBuckets = 0;
HASH_NODE<_Record> *pNode = nullptr;
HASH_NODE<_Record> *pNextNode = nullptr;
HASH_NODE<_Record> **ppNextPointer = nullptr;
HASH_NODE<_Record> *pNewNextNode = nullptr;
DWORD nNewBuckets = 0;

//
// If number of items has become too many, we will double the hash table
Expand Down
12 changes: 6 additions & 6 deletions src/Servers/IIS/AspNetCoreModuleV2/IISLib/listentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ RemoveEntryList(
IN PLIST_ENTRY Entry
)
{
PLIST_ENTRY Blink;
PLIST_ENTRY Flink;
PLIST_ENTRY Blink = nullptr;
PLIST_ENTRY Flink = nullptr;

Flink = Entry->Flink;
Blink = Entry->Blink;
Expand All @@ -55,8 +55,8 @@ RemoveHeadList(
IN PLIST_ENTRY ListHead
)
{
PLIST_ENTRY Flink;
PLIST_ENTRY Entry;
PLIST_ENTRY Flink = nullptr;
PLIST_ENTRY Entry = nullptr;

Entry = ListHead->Flink;
Flink = Entry->Flink;
Expand All @@ -73,8 +73,8 @@ RemoveTailList(
IN PLIST_ENTRY ListHead
)
{
PLIST_ENTRY Blink;
PLIST_ENTRY Entry;
PLIST_ENTRY Blink = nullptr;
PLIST_ENTRY Entry = nullptr;

Entry = ListHead->Blink;
Blink = Entry->Blink;
Expand Down
7 changes: 3 additions & 4 deletions src/Servers/IIS/AspNetCoreModuleV2/IISLib/reftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ Return Value:

} // WriteRefTraceLog


LONG
__cdecl
WriteRefTraceLogEx(
Expand Down Expand Up @@ -156,9 +155,9 @@ Return Value:
--*/
{

REF_TRACE_LOG_ENTRY entry;
ULONG hash;
DWORD cStackFramesSkipped;
REF_TRACE_LOG_ENTRY entry{};
ULONG hash = 0;
DWORD cStackFramesSkipped = 0;

//
// Initialize the entry.
Expand Down
Loading
Loading