Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c8a3780

Browse files
author
Koundinya Veluri
authored
Fix static analysis issues (#11466)
Fix static analysis issues
1 parent 39a841c commit c8a3780

File tree

13 files changed

+77
-43
lines changed

13 files changed

+77
-43
lines changed

src/debug/shared/amd64/primitives.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void CORDbgCopyThreadContext(DT_CONTEXT* pDst, const DT_CONTEXT* pSrc)
6363
if ((dstFlags & srcFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
6464
{
6565
// Xmm0-Xmm15
66-
CopyContextChunk(&(pDst->Xmm0), &(pSrc->Xmm0), &(pDst->Xmm15) + sizeof(M128A),
66+
CopyContextChunk(&(pDst->Xmm0), &(pSrc->Xmm0), &(pDst->Xmm15) + 1,
6767
CONTEXT_FLOATING_POINT);
6868

6969
// MxCsr

src/dlls/mscorpe/iceefilegen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ HRESULT ICeeFileGen::CreateCeeFileFromICeeGen(ICeeGen *pICeeGen, HCEEFILE *ceeFi
151151
return E_POINTER;
152152
CCeeGen *genFrom = reinterpret_cast<CCeeGen*>(pICeeGen);
153153
CeeFileGenWriter *gen = NULL;
154-
if (FAILED(CeeFileGenWriter::CreateNewInstance(genFrom, gen, createFlags))) return FALSE;
154+
HRESULT hr = CeeFileGenWriter::CreateNewInstance(genFrom, gen, createFlags);
155+
if (FAILED(hr))
156+
return hr;
155157
TESTANDRETURN(gen != NULL, E_OUTOFMEMORY);
156158
*ceeFile = gen;
157159
return S_OK;

src/ilasm/prebuilt/asmparse.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,9 +1834,16 @@ YYSTATIC char *yyscpy(register char*t, register char*f)
18341834

18351835
YYSTATIC short yyn;
18361836
YYSTATIC short yystate = 0;
1837-
YYSTATIC short *yyps= &yys[-1];
1837+
#ifdef _PREFAST_
1838+
#pragma warning(push)
1839+
#pragma warning(disable: 6200) // Index '-1' is out of valid index range...for non-stack buffer...
1840+
#endif
1841+
YYSTATIC short *yyps= &yys[-1];
18381842
YYSTATIC YYSTYPE *yypv= &yyv[-1];
1839-
YYSTATIC short yyj;
1843+
#ifdef _PREFAST_
1844+
#pragma warning(pop)
1845+
#endif
1846+
YYSTATIC short yyj;
18401847
YYSTATIC short yym;
18411848

18421849
#endif

src/inc/winrt/paraminstanceapi.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,14 @@ namespace Ro { namespace detail {
16421642
DWORD dwcb;
16431643
DWORD dwcbResult;
16441644

1645+
#ifdef _PREFAST_
1646+
#pragma warning(push)
1647+
#pragma warning(disable: 33098) // "Banned hash algorithm is used" - SHA-1 is required for compatibility
1648+
#endif // _PREFAST_
16451649
CHKNT(BCryptOpenAlgorithmProvider(&_hAlg, BCRYPT_SHA1_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0));
1650+
#ifdef _PREFAST_
1651+
#pragma warning(pop)
1652+
#endif // _PREFAST_
16461653

16471654
CHKNT(BCryptGetProperty(_hAlg, BCRYPT_OBJECT_LENGTH, reinterpret_cast<PBYTE>(&dwcb), sizeof(dwcb), &dwcbResult, 0));
16481655

src/md/ceefilegen/cceegen.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,30 @@ HRESULT STDMETHODCALLTYPE CreateICeeGen(REFIID riid, void **pCeeGen)
3838

3939
HRESULT CCeeGen::CreateNewInstance(CCeeGen* & pGen) // static, public
4040
{
41-
pGen = new CCeeGen();
42-
_ASSERTE(pGen != NULL);
43-
TESTANDRETURNMEMORY(pGen);
41+
NewHolder<CCeeGen> pGenHolder(new CCeeGen());
42+
_ASSERTE(pGenHolder != NULL);
43+
TESTANDRETURNMEMORY(pGenHolder);
4444

45-
pGen->m_peSectionMan = new PESectionMan;
46-
_ASSERTE(pGen->m_peSectionMan != NULL);
47-
TESTANDRETURNMEMORY(pGen->m_peSectionMan);
45+
pGenHolder->m_peSectionMan = new PESectionMan;
46+
_ASSERTE(pGenHolder->m_peSectionMan != NULL);
47+
TESTANDRETURNMEMORY(pGenHolder->m_peSectionMan);
4848

49-
HRESULT hr = pGen->m_peSectionMan->Init();
50-
TESTANDRETURNHR(hr);
49+
HRESULT hr = pGenHolder->m_peSectionMan->Init();
50+
if (FAILED(hr))
51+
{
52+
pGenHolder->Cleanup();
53+
return hr;
54+
}
5155

52-
hr = pGen->Init();
53-
TESTANDRETURNHR(hr);
56+
hr = pGenHolder->Init();
57+
if (FAILED(hr))
58+
{
59+
// Init() calls Cleanup() on failure
60+
return hr;
61+
}
5462

63+
pGen = pGenHolder.Extract();
5564
return hr;
56-
5765
}
5866

5967
STDMETHODIMP CCeeGen::QueryInterface(REFIID riid, void** ppv)

src/md/enc/mdinternalrw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ HRESULT MDInternalRW::GetItemGuid( // return hresult
23932393

23942394
// Get the GUID, if any.
23952395
hr = GetCustomAttributeByName(tkObj, INTEROP_GUID_TYPE, (const void**)&pBlob, &cbBlob);
2396-
if (hr != S_FALSE)
2396+
if (SUCCEEDED(hr) && hr != S_FALSE)
23972397
{
23982398
// Should be in format. Total length == 41
23992399
// <0x0001><0x24>01234567-0123-0123-0123-001122334455<0x0000>

src/vm/ceeload.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12770,6 +12770,11 @@ void Module::LogTokenAccess(mdToken token, SectionFormat format, ULONG flagnum)
1277012770
if (!m_nativeImageProfiling)
1277112771
return;
1277212772

12773+
if (flagnum >= CORBBTPROF_TOKEN_MAX_NUM_FLAGS)
12774+
{
12775+
return;
12776+
}
12777+
1277312778
mdToken rid = RidFromToken(token);
1277412779
CorTokenType tkType = (CorTokenType) TypeFromToken(token);
1277512780
SectionFormat tkKind = (SectionFormat) (tkType >> 24);
@@ -12798,8 +12803,9 @@ void Module::LogTokenAccess(mdToken token, SectionFormat format, ULONG flagnum)
1279812803
else if (tkKind == (SectionFormat) (ibcMethodSpec >> 24))
1279912804
tkKind = IbcMethodSpecSection;
1280012805

12806+
_ASSERTE(tkKind >= 0);
1280112807
_ASSERTE(tkKind < SectionFormatCount);
12802-
if (tkKind >= SectionFormatCount)
12808+
if (tkKind < 0 || tkKind >= SectionFormatCount)
1280312809
{
1280412810
return;
1280512811
}

src/vm/corhost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,7 @@ HRESULT CCLRErrorReportingManager::BucketParamsCache::SetAt(BucketParameterIndex
25702570
{
25712571
LIMITED_METHOD_CONTRACT;
25722572

2573-
if (index >= InvalidBucketParamIndex)
2573+
if (index < 0 || index >= InvalidBucketParamIndex)
25742574
{
25752575
_ASSERTE(!"bad bucket parameter index");
25762576
return E_INVALIDARG;

src/vm/dwreport.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,30 +1526,28 @@ BOOL RunWatson(
15261526
return false;
15271527
}
15281528

1529+
{
1530+
BOOL ret = WszCreateProcess(watsonAppName,
1531+
watsonCommandLine,
1532+
NULL,
1533+
NULL,
1534+
TRUE,
1535+
NULL,
1536+
NULL,
1537+
NULL,
1538+
&startupInfo,
1539+
&processInformation);
1540+
1541+
if (FALSE == ret)
15291542
{
1530-
BOOL ret = WszCreateProcess(watsonAppName,
1531-
watsonCommandLine,
1532-
NULL,
1533-
NULL,
1534-
TRUE,
1535-
NULL,
1536-
NULL,
1537-
NULL,
1538-
&startupInfo,
1539-
&processInformation);
1540-
1541-
if (FALSE == ret)
1542-
{
1543-
//
1544-
// Watson failed to start up.
1545-
//
1546-
// This can happen if e.g. Watson wasn't installed on the machine.
1547-
//
1548-
return E_FAIL;
1549-
1550-
}
1551-
1543+
//
1544+
// Watson failed to start up.
1545+
//
1546+
// This can happen if e.g. Watson wasn't installed on the machine.
1547+
//
1548+
return FALSE;
15521549
}
1550+
}
15531551

15541552

15551553

src/vm/jitinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ CorInfoType CEEInfo::asCorInfoType(CorElementType eeType,
360360
_ASSERTE((CorInfoType) map[ELEMENT_TYPE_PTR] == CORINFO_TYPE_PTR);
361361
_ASSERTE((CorInfoType) map[ELEMENT_TYPE_TYPEDBYREF] == CORINFO_TYPE_REFANY);
362362

363-
CorInfoType res = ((unsigned)eeType < ELEMENT_TYPE_MAX) ? ((CorInfoType) map[eeType]) : CORINFO_TYPE_UNDEF;
363+
CorInfoType res = ((unsigned)eeType < ELEMENT_TYPE_MAX) ? ((CorInfoType) map[(unsigned)eeType]) : CORINFO_TYPE_UNDEF;
364364

365365
if (clsRet)
366366
*clsRet = CORINFO_CLASS_HANDLE(typeHndUpdated.AsPtr());

0 commit comments

Comments
 (0)