summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2019-05-14 19:07:53 -0700
committerGitHub <noreply@github.com>2019-05-14 19:07:53 -0700
commit718598334310f6ad331ba2893ee4557beffaa74c (patch)
tree7bc4830b29442e79be150b67dc0f67473e5ba681
parent6a85ca560a7dfa109c6f17c0b76d93373dbd5a00 (diff)
downloadcoreclr-718598334310f6ad331ba2893ee4557beffaa74c.tar.gz
coreclr-718598334310f6ad331ba2893ee4557beffaa74c.tar.bz2
coreclr-718598334310f6ad331ba2893ee4557beffaa74c.zip
Fix issues reported by PREfast static analysis tool (#24577)
-rw-r--r--src/binder/applicationcontext.cpp2
-rw-r--r--src/binder/clrprivbinderassemblyloadcontext.cpp5
-rw-r--r--src/binder/inc/applicationcontext.hpp13
-rw-r--r--src/binder/inc/assemblyidentity.hpp2
-rw-r--r--src/binder/inc/fusionassemblyname.hpp2
-rw-r--r--src/binder/inc/stringlexer.inl2
-rw-r--r--src/classlibnative/bcltype/arraynative.cpp2
-rw-r--r--src/debug/ildbsymlib/symwrite.cpp4
-rw-r--r--src/gc/env/gcenv.os.h2
-rw-r--r--src/gc/env/gcenv.unix.inl2
-rw-r--r--src/gc/env/gcenv.windows.inl2
-rw-r--r--src/gc/gc.cpp14
-rw-r--r--src/gc/handletablecore.cpp4
-rw-r--r--src/gc/softwarewritewatch.h2
-rw-r--r--src/gcinfo/gcinfoencoder.cpp2
-rw-r--r--src/inc/metadatatracker.h3
-rw-r--r--src/inc/utilcode.h14
-rw-r--r--src/vm/classcompat.cpp2
-rw-r--r--src/vm/method.hpp11
-rw-r--r--src/vm/methodtablebuilder.cpp2
-rw-r--r--src/zap/zapimage.cpp10
21 files changed, 35 insertions, 67 deletions
diff --git a/src/binder/applicationcontext.cpp b/src/binder/applicationcontext.cpp
index dc7b9ad6e3..f768ab9686 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 03819b8bf9..168111560f 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 cd1a2455e4..83893f33ce 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 4d7c7f1bac..16a448448b 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 f0f69d3274..fcfea95eaf 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 f8bc3816a4..a3954bd62e 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 528105a476..605cd2905b 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 4d3fb53f2f..80b09a7237 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 7fa1ba7062..393bd1fe18 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 50683aeea8..42b8a434a0 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 3b15dfd890..7e81016735 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 e8f2400c1b..c6a858c8fa 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 7e531f9ce6..5fc661c000 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 e59fd61d04..92ffbf82db 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 090c0895d6..bb989d6650 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 1427b189a7..3b0059b61f 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<wchar_t> 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 cf4b8ddf12..17c8b14afc 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<MemMgr>::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 473e328200..b677045f0b 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 68626c7bc4..cf532f8102 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<<ALIGNMENT_SHIFT),
- ALIGNMENT_MASK = (ALIGNMENT-1)
- };
+ static const size_t ALIGNMENT = (1 << ALIGNMENT_SHIFT);
+ static const size_t ALIGNMENT_MASK = (ALIGNMENT - 1);
#ifdef _DEBUG
diff --git a/src/vm/methodtablebuilder.cpp b/src/vm/methodtablebuilder.cpp
index 609eda0b3f..e8a7e9339f 100644
--- a/src/vm/methodtablebuilder.cpp
+++ b/src/vm/methodtablebuilder.cpp
@@ -2434,7 +2434,7 @@ HRESULT MethodTableBuilder::FindMethodDeclarationForMethodImpl(
if (TypeFromToken(typeref) == mdtMethodDef)
{ // If parent is a method def then this is a varags method
mdTypeDef typeDef;
- hr = pMDInternalImport->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 196337d86e..2dce179071 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"))
{