From: Jan Kotas Date: Wed, 15 May 2019 02:07:53 +0000 (-0700) Subject: Fix issues reported by PREfast static analysis tool (#24577) X-Git-Tag: accepted/tizen/unified/20190813.215958~42^2~218 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=718598334310f6ad331ba2893ee4557beffaa74c;p=platform%2Fupstream%2Fcoreclr.git Fix issues reported by PREfast static analysis tool (#24577) --- diff --git a/src/binder/applicationcontext.cpp b/src/binder/applicationcontext.cpp index dc7b9ad..f768ab9 100644 --- a/src/binder/applicationcontext.cpp +++ b/src/binder/applicationcontext.cpp @@ -144,8 +144,6 @@ namespace BINDER_SPACE m_pFailureCache = pFailureCache; } - - m_fCanExplicitlyBindToNativeImages = false; Exit: BINDER_LOG_LEAVE_HR(W("ApplicationContext::Init"), hr); diff --git a/src/binder/clrprivbinderassemblyloadcontext.cpp b/src/binder/clrprivbinderassemblyloadcontext.cpp index 03819b8..1681115 100644 --- a/src/binder/clrprivbinderassemblyloadcontext.cpp +++ b/src/binder/clrprivbinderassemblyloadcontext.cpp @@ -216,10 +216,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::SetupContext(DWORD dwAppDomainId, { // Save the reference to the AppDomain in which the binder lives pBinder->m_appContext.SetAppDomainId(dwAppDomainId); - - // Mark that this binder can explicitly bind to native images - pBinder->m_appContext.SetExplicitBindToNativeImages(true); - + // Save reference to the TPABinder that is required to be present. _ASSERTE(pTPABinder != NULL); pBinder->m_pTPABinder = pTPABinder; diff --git a/src/binder/inc/applicationcontext.hpp b/src/binder/inc/applicationcontext.hpp index cd1a245..83893f3 100644 --- a/src/binder/inc/applicationcontext.hpp +++ b/src/binder/inc/applicationcontext.hpp @@ -173,19 +173,6 @@ namespace BINDER_SPACE SimpleNameToFileNameMap * m_pTrustedPlatformAssemblyMap; TpaFileNameHash * m_pFileNameHash; - - bool m_fCanExplicitlyBindToNativeImages; -public: - inline void SetExplicitBindToNativeImages(bool fCanExplicitlyBindToNativeImages) - { - m_fCanExplicitlyBindToNativeImages = fCanExplicitlyBindToNativeImages; - } - - inline bool CanExplicitlyBindToNativeImages() - { - return m_fCanExplicitlyBindToNativeImages; - } -protected: }; #include "applicationcontext.inl" diff --git a/src/binder/inc/assemblyidentity.hpp b/src/binder/inc/assemblyidentity.hpp index 4d7c7f1..16a4484 100644 --- a/src/binder/inc/assemblyidentity.hpp +++ b/src/binder/inc/assemblyidentity.hpp @@ -40,7 +40,7 @@ namespace BINDER_SPACE IDENTITY_FLAG_CONTENT_TYPE = 0x800, IDENTITY_FLAG_FULL_NAME = (IDENTITY_FLAG_SIMPLE_NAME | IDENTITY_FLAG_VERSION) - } IdentityFlags; + }; AssemblyIdentity() { diff --git a/src/binder/inc/fusionassemblyname.hpp b/src/binder/inc/fusionassemblyname.hpp index f0f69d3..fcfea95 100644 --- a/src/binder/inc/fusionassemblyname.hpp +++ b/src/binder/inc/fusionassemblyname.hpp @@ -52,8 +52,6 @@ private: LPWSTR _pwzTextualIdentity; LPWSTR _pwzTextualIdentityILFull; - DWORD _dw; - public: // IUnknown methods STDMETHODIMP QueryInterface(REFIID riid,void ** ppv); diff --git a/src/binder/inc/stringlexer.inl b/src/binder/inc/stringlexer.inl index f8bc381..a3954bd 100644 --- a/src/binder/inc/stringlexer.inl +++ b/src/binder/inc/stringlexer.inl @@ -129,7 +129,7 @@ WCHAR StringLexer::DecodeUTF16Character() // See http://www.ietf.org/rfc/rfc2781.txt for details on UTF-16 encoding. WCHAR wcCurrentChar = 0; - SIZE_T nCharacters = m_end - m_cursor + 1; + SCOUNT_T nCharacters = m_end - m_cursor + 1; WCHAR wcChar1 = GetRawCharacter(); if (wcChar1 < 0xd800) diff --git a/src/classlibnative/bcltype/arraynative.cpp b/src/classlibnative/bcltype/arraynative.cpp index 528105a..605cd29 100644 --- a/src/classlibnative/bcltype/arraynative.cpp +++ b/src/classlibnative/bcltype/arraynative.cpp @@ -591,7 +591,7 @@ void ArrayNative::UnBoxEachElement(BASEARRAYREF pSrc, unsigned int srcIndex, BAS MethodTable * pDestMT = destTH.GetMethodTable(); PREFIX_ASSUME(pDestMT != NULL); - const unsigned int destSize = pDestMT->GetNumInstanceFieldBytes(); + SIZE_T destSize = pDest->GetComponentSize(); BYTE* srcData = (BYTE*) pSrc->GetDataPtr() + srcIndex * sizeof(OBJECTREF); BYTE* data = (BYTE*) pDest->GetDataPtr() + destIndex * destSize; diff --git a/src/debug/ildbsymlib/symwrite.cpp b/src/debug/ildbsymlib/symwrite.cpp index 4d3fb53..80b09a7 100644 --- a/src/debug/ildbsymlib/symwrite.cpp +++ b/src/debug/ildbsymlib/symwrite.cpp @@ -202,7 +202,7 @@ HRESULT SymWriter::GetOrCreateDocument( { ULONG UrlEntry; DWORD strLength = WszWideCharToMultiByte(CP_UTF8, 0, wcsUrl, -1, 0, 0, 0, 0); - LPSTR multiByteURL = (LPSTR) new char [strLength+1]; + LPSTR multiByteURL = (LPSTR) new char [strLength]; HRESULT hr = S_OK; if (multiByteURL == NULL) @@ -210,7 +210,7 @@ HRESULT SymWriter::GetOrCreateDocument( return E_OUTOFMEMORY; } - WszWideCharToMultiByte(CP_UTF8, 0, wcsUrl, -1, multiByteURL, strLength+1, 0, 0); + WszWideCharToMultiByte(CP_UTF8, 0, wcsUrl, -1, multiByteURL, strLength, 0, 0); if (m_pStringPool->FindString(multiByteURL, &UrlEntry) == S_FALSE) // no file of that name has been seen before { diff --git a/src/gc/env/gcenv.os.h b/src/gc/env/gcenv.os.h index 7fa1ba7..393bd1f 100644 --- a/src/gc/env/gcenv.os.h +++ b/src/gc/env/gcenv.os.h @@ -444,7 +444,7 @@ public: static void GetMemoryStatus(uint32_t* memory_load, uint64_t* available_physical, uint64_t* available_page_file); // Get size of an OS memory page - static uint32_t GetPageSize(); + static size_t GetPageSize(); // // Misc diff --git a/src/gc/env/gcenv.unix.inl b/src/gc/env/gcenv.unix.inl index 50683ae..42b8a43 100644 --- a/src/gc/env/gcenv.unix.inl +++ b/src/gc/env/gcenv.unix.inl @@ -11,7 +11,7 @@ extern uint32_t g_pageSizeUnixInl; #define OS_PAGE_SIZE GCToOSInterface::GetPageSize() -__forceinline uint32_t GCToOSInterface::GetPageSize() +__forceinline size_t GCToOSInterface::GetPageSize() { return g_pageSizeUnixInl; } diff --git a/src/gc/env/gcenv.windows.inl b/src/gc/env/gcenv.windows.inl index 3b15dfd..7e81016 100644 --- a/src/gc/env/gcenv.windows.inl +++ b/src/gc/env/gcenv.windows.inl @@ -10,7 +10,7 @@ #define OS_PAGE_SIZE GCToOSInterface::GetPageSize() -__forceinline uint32_t GCToOSInterface::GetPageSize() +__forceinline size_t GCToOSInterface::GetPageSize() { return 0x1000; } diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index e8f2400..c6a858c 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -28077,15 +28077,7 @@ BOOL gc_heap::find_card(uint32_t* card_table, { card_word_value = *(++last_card_word); } while ((last_card_word < &card_table [card_word_end]) && - -#ifdef _MSC_VER - (card_word_value == (1 << card_word_width)-1) -#else - // if left shift count >= width of type, - // gcc reports error. - (card_word_value == ~0u) -#endif // _MSC_VER - ); + (card_word_value == ~0u /* (1 << card_word_width)-1 */)); bit_position = 0; } } while (card_word_value & 1); @@ -30477,7 +30469,7 @@ size_t gc_heap::joined_youngest_desired (size_t new_allocation) uint32_t memory_load = 0; get_memory_info (&memory_load); settings.exit_memory_load = memory_load; - dprintf (2, ("Current emory load: %d", memory_load)); + dprintf (2, ("Current memory load: %d", memory_load)); size_t final_total = trim_youngest_desired (memory_load, total_new_allocation, total_min_allocation); @@ -37418,7 +37410,7 @@ void GCHeap::DiagScanDependentHandles (handle_scan_fn fn, int gen_number, ScanCo // Go through and touch (read) each page straddled by a memory block. void TouchPages(void * pStart, size_t cb) { - const uint32_t pagesize = OS_PAGE_SIZE; + const size_t pagesize = OS_PAGE_SIZE; _ASSERTE(0 == (pagesize & (pagesize-1))); // Must be a power of 2. if (cb) { diff --git a/src/gc/handletablecore.cpp b/src/gc/handletablecore.cpp index 7e531f9..5fc661c 100644 --- a/src/gc/handletablecore.cpp +++ b/src/gc/handletablecore.cpp @@ -1409,7 +1409,7 @@ uint32_t SegmentInsertBlockFromFreeListWorker(TableSegment *pSegment, uint32_t u void * pvCommit = pSegment->rgValue + (uCommitLine * HANDLE_HANDLES_PER_BLOCK); // we should commit one more page of handles - uint32_t dwCommit = OS_PAGE_SIZE; + size_t dwCommit = OS_PAGE_SIZE; // commit the memory if (!GCToOSInterface::VirtualCommit(pvCommit, dwCommit)) @@ -1774,7 +1774,7 @@ BOOL DoesSegmentNeedsToTrimExcessPages(TableSegment *pSegment) if (uEmptyLine < uDecommitLine) { // derive some useful info about the page size - uintptr_t dwPageRound = (uintptr_t)OS_PAGE_SIZE - 1; + uintptr_t dwPageRound = OS_PAGE_SIZE - 1; uintptr_t dwPageMask = ~dwPageRound; // compute the address corresponding to the empty line diff --git a/src/gc/softwarewritewatch.h b/src/gc/softwarewritewatch.h index e59fd61..92ffbf8 100644 --- a/src/gc/softwarewritewatch.h +++ b/src/gc/softwarewritewatch.h @@ -8,7 +8,7 @@ #include "gcinterface.h" #include "gc.h" -#define WRITE_WATCH_UNIT_SIZE 0x1000 +#define WRITE_WATCH_UNIT_SIZE ((size_t)0x1000) #ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP #ifndef DACCESS_COMPILE diff --git a/src/gcinfo/gcinfoencoder.cpp b/src/gcinfo/gcinfoencoder.cpp index 090c089..bb989d6 100644 --- a/src/gcinfo/gcinfoencoder.cpp +++ b/src/gcinfo/gcinfoencoder.cpp @@ -1802,7 +1802,7 @@ void GcInfoEncoder::Build() const size_t sizeofEncodedNumBitsPerPointer = BitStreamWriter::SizeofVarLengthUnsigned(numBitsPerPointer, POINTER_SIZE_ENCBASE); const size_t sizeofNoIndirection = m_NumCallSites * (numRegisters + numStackSlots); const size_t sizeofIndirection = sizeofEncodedNumBitsPerPointer // Encode the pointer sizes - + (m_NumCallSites * numBitsPerPointer) // Encoe the pointers + + (m_NumCallSites * numBitsPerPointer) // Encode the pointers + 7 // Up to 7 bits of alignment padding + sizeofSets; // Encode the actual live sets diff --git a/src/inc/metadatatracker.h b/src/inc/metadatatracker.h index 1427b18..3b0059b 100644 --- a/src/inc/metadatatracker.h +++ b/src/inc/metadatatracker.h @@ -71,8 +71,7 @@ public: m_ModuleName = NULL; - DWORD len = (DWORD)wcslen(modName); - _ASSERTE(len + 1 != 0); // Prevent Overflow + size_t len = wcslen(modName); m_ModuleName = new wchar_t[len + 1]; NewArrayHolder moduleNameHolder(m_ModuleName); wcscpy_s((wchar_t *)m_ModuleName, len + 1, (wchar_t *)modName); diff --git a/src/inc/utilcode.h b/src/inc/utilcode.h index cf4b8dd..17c8b14 100644 --- a/src/inc/utilcode.h +++ b/src/inc/utilcode.h @@ -1899,12 +1899,12 @@ public: { WRAPPER_NO_CONTRACT; _ASSERTE(iIndex < m_iCount); - return ((void *) ((size_t) Ptr() + (iIndex * m_iElemSize))); + return (BYTE*) Ptr() + (iIndex * (size_t)m_iElemSize); } - int Size() + size_t Size() { LIMITED_METHOD_CONTRACT; - return (m_iCount * m_iElemSize); + return (m_iCount * (size_t)m_iElemSize); } int Count() { @@ -2408,7 +2408,7 @@ protected: HASHENTRY *EntryPtr(ULONG iEntry) { LIMITED_METHOD_DAC_CONTRACT; - return (PTR_HASHENTRY(m_pcEntries + (iEntry * m_iEntrySize))); + return (PTR_HASHENTRY(m_pcEntries + (iEntry * (size_t)m_iEntrySize))); } ULONG ItemIndex(HASHENTRY *p) @@ -2859,7 +2859,7 @@ void CHashTableAndData::InitFreeChain( BYTE* pcPtr; _ASSERTE(iEnd > iStart); - pcPtr = (BYTE*)m_pcEntries + iStart * m_iEntrySize; + pcPtr = (BYTE*)m_pcEntries + iStart * (size_t)m_iEntrySize; for (++iStart; iStart < iEnd; ++iStart) { ((FREEHASHENTRY *) pcPtr)->iFree = iStart; @@ -3117,13 +3117,13 @@ class CClosedHashBase BYTE *EntryPtr(int iEntry) { LIMITED_METHOD_CONTRACT; - return (m_rgData + (iEntry * m_iEntrySize)); + return (m_rgData + (iEntry * (size_t)m_iEntrySize)); } BYTE *EntryPtr(int iEntry, BYTE *rgData) { LIMITED_METHOD_CONTRACT; - return (rgData + (iEntry * m_iEntrySize)); + return (rgData + (iEntry * (size_t)m_iEntrySize)); } public: diff --git a/src/vm/classcompat.cpp b/src/vm/classcompat.cpp index 473e328..b677045 100644 --- a/src/vm/classcompat.cpp +++ b/src/vm/classcompat.cpp @@ -3290,7 +3290,7 @@ HRESULT MethodTableBuilder::FindMethodDeclarationForMethodImpl( if (TypeFromToken(typeref) == mdtMethodDef) { mdTypeDef typeDef; - hr = pMDInternalImport->GetParentToken(typeref, &typeDef); + IfFailRet(pMDInternalImport->GetParentToken(typeref, &typeDef)); // Make sure it is a typedef if (TypeFromToken(typeDef) != mdtTypeDef) diff --git a/src/vm/method.hpp b/src/vm/method.hpp index 68626c7..cf532f8 100644 --- a/src/vm/method.hpp +++ b/src/vm/method.hpp @@ -210,16 +210,13 @@ class MethodDesc public: - enum - { #ifdef _WIN64 - ALIGNMENT_SHIFT = 3, + static const int ALIGNMENT_SHIFT = 3; #else - ALIGNMENT_SHIFT = 2, + static const int ALIGNMENT_SHIFT = 2; #endif - ALIGNMENT = (1<GetParentToken(typeref, &typeDef); + IfFailRet(pMDInternalImport->GetParentToken(typeref, &typeDef)); if (TypeFromToken(typeDef) != mdtTypeDef) { // A mdtMethodDef must be parented by a mdtTypeDef diff --git a/src/zap/zapimage.cpp b/src/zap/zapimage.cpp index 196337d..2dce179 100644 --- a/src/zap/zapimage.cpp +++ b/src/zap/zapimage.cpp @@ -2238,20 +2238,20 @@ BOOL ZapImage::ShouldCompileMethodDef(mdMethodDef md) mdToken tkExtends; if (td != mdTypeDefNil) { - m_pMDImport->GetTypeDefProps(td, NULL, &tkExtends); + IfFailThrow(m_pMDImport->GetTypeDefProps(td, NULL, &tkExtends)); mdAssembly tkAssembly; DWORD dwAssemblyFlags; - m_pMDImport->GetAssemblyFromScope(&tkAssembly); + IfFailThrow(m_pMDImport->GetAssemblyFromScope(&tkAssembly)); if (TypeFromToken(tkAssembly) == mdtAssembly) { - m_pMDImport->GetAssemblyProps(tkAssembly, + IfFailThrow(m_pMDImport->GetAssemblyProps(tkAssembly, NULL, NULL, // Public Key NULL, // Hash Algorithm NULL, // Name NULL, // MetaData - &dwAssemblyFlags); + &dwAssemblyFlags)); if (IsAfContentType_WindowsRuntime(dwAssemblyFlags)) { @@ -2259,7 +2259,7 @@ BOOL ZapImage::ShouldCompileMethodDef(mdMethodDef md) { LPCSTR szNameSpace = NULL; LPCSTR szName = NULL; - m_pMDImport->GetNameOfTypeRef(tkExtends, &szNameSpace, &szName); + IfFailThrow(m_pMDImport->GetNameOfTypeRef(tkExtends, &szNameSpace, &szName)); if (!strcmp(szNameSpace, "System") && !_stricmp((szName), "Attribute")) {