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

Commit

Permalink
resolve several issues found by cppcheck (#26869)
Browse files Browse the repository at this point in the history
* src/debug/daccess/nidump.cpp: remove dead code
found by cppcheck

[src/debug/daccess/nidump.cpp:2839] -> [src/debug/daccess/nidump.cpp:2841]: (warning) Opposite inner 'if' condition leads to a dead code block.

* src/dlls/dbgshim/dbgshim.cpp: resolve possible null pointer dereference
found by cppcheck

[src/dlls/dbgshim/dbgshim.cpp:1373] -> [src/dlls/dbgshim/dbgshim.cpp:1367]: (warning) Either the condition 'pHandleArray==NULL' is redundant or there is pointer arithmetic with NULL pointer.

* src/ilasm/assembler.cpp: resolve possible null pointer dereference
found by cppcheck

[src/ilasm/assembler.cpp:2331] -> [src/ilasm/assembler.cpp:2330]: (warning) Either the condition 'pMID==NULL' is redundant or there is possible null pointer dereference: pMID.

* src/jit/flowgraph.cpp: resolve possible null pointer dereference
found by cppcheck

[src/jit/flowgraph.cpp:11009] -> [src/jit/flowgraph.cpp:11005]: (warning) Either the condition 'block!=nullptr' is redundant or there is possible null pointer dereference: block.

* src/pal/src/debug/debug.cpp: resolve possible null pointer dereference
found by cppcheck

[src/pal/src/debug/debug.cpp:376] -> [src/pal/src/debug/debug.cpp:381]: (warning) Either the condition 'command_string' is redundant or there is possible null pointer dereference: command_string.

* src/pal/src/libunwind/src/arm/Gex_tables.c: resolve possible null pointer dereference
found by cppcheck

[src/pal/src/libunwind/src/arm/Gex_tables.c:159] -> [src/pal/src/libunwind/src/arm/Gex_tables.c:155]: (warning) Either the condition 'buf!=NULL' is redundant or there is pointer arithmetic with NULL pointer.

* src/pal/src/synchmgr/synchmanager.cpp: resolve possible null pointer dereference
found by cppcheck

[src/pal/src/synchmgr/synchmanager.cpp:2512] -> [src/pal/src/synchmgr/synchmanager.cpp:2510]: (warning) Either the condition 'NULL!=pWLNode' is redundant or there is possible null pointer dereference: pWLNode.
  • Loading branch information
chipitsine authored and janvorli committed Sep 25, 2019
1 parent cfcc757 commit 181523f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 21 deletions.
15 changes: 5 additions & 10 deletions src/debug/daccess/nidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,16 +2838,11 @@ IMetaDataImport2 * NativeImageDumper::TypeToString(PTR_CCOR_SIGNATURE &sig,
{
if (sizes[i] != 0 && lowerBounds[i] != 0)
{
if (lowerBounds[i] == 0)
buf.AppendPrintf( W("%s"), sizes[i] );
else
{
buf.AppendPrintf( W("%d ..."), lowerBounds[i] );
if (sizes[i] != 0)
buf.AppendPrintf( W("%d"),
lowerBounds[i] + sizes[i]
+ 1 );
}
buf.AppendPrintf( W("%d ..."), lowerBounds[i] );
if (sizes[i] != 0)
buf.AppendPrintf( W("%d"),
lowerBounds[i] + sizes[i]
+ 1 );
}
if (i < rank-1)
buf.Append( W(",") );
Expand Down
6 changes: 3 additions & 3 deletions src/dlls/dbgshim/dbgshim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,15 +1364,15 @@ CloseCLREnumeration(
{
PUBLIC_CONTRACT;

if ((pHandleArray + dwArrayLength) != (HANDLE*)pStringArray)
return E_INVALIDARG;

// It's possible that EnumerateCLRs found nothing to enumerate, in which case
// pointers and count are zeroed. If a debugger calls this function in that
// case, let's not try to delete [] on NULL.
if (pHandleArray == NULL)
return S_OK;

if ((pHandleArray + dwArrayLength) != (HANDLE*)pStringArray)
return E_INVALIDARG;

#ifndef FEATURE_PAL
for (DWORD i = 0; i < dwArrayLength; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ilasm/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2327,12 +2327,12 @@ void Assembler::AddMethodImpl(mdToken tkImplementedTypeSpec, __in __nullterminat
if(m_pCurClass)
{
MethodImplDescriptor* pMID = new MethodImplDescriptor;
pMID->m_fNew = TRUE;
if(pMID == NULL)
{
report->error("Failed to allocate MethodImpl Descriptor\n");
return;
}
pMID->m_fNew = TRUE;
pMID->m_tkDefiningClass = m_pCurClass->m_cl;
if(szImplementingName) //called from class scope, overriding method specified
{
Expand Down
4 changes: 2 additions & 2 deletions src/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11002,12 +11002,12 @@ void Compiler::fgUnlinkRange(BasicBlock* bBeg, BasicBlock* bEnd)

void Compiler::fgRemoveBlock(BasicBlock* block, bool unreachable)
{
BasicBlock* bPrev = block->bbPrev;

/* The block has to be either unreachable or empty */

PREFIX_ASSUME(block != nullptr);

BasicBlock* bPrev = block->bbPrev;

JITDUMP("fgRemoveBlock " FMT_BB "\n", block->bbNum);

// If we've cached any mappings from switch blocks to SwitchDesc's (which contain only the
Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ DebugBreakCommand()
FAILED:
if (command_string)
{
fprintf (stderr, "Failed to execute command: '%s'\n", command_string);
free(command_string);
}

fprintf (stderr, "Failed to execute command: '%s'\n", command_string);
return -1;
#else // ENABLE_RUN_ON_DEBUG_BREAK
return 0;
Expand Down
5 changes: 2 additions & 3 deletions src/pal/src/libunwind/src/arm/Gex_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,12 @@ HIDDEN int
arm_exidx_decode (const uint8_t *buf, uint8_t len, struct dwarf_cursor *c)
{
#define READ_OP() *buf++
assert(buf != NULL);
assert(len > 0);
const uint8_t *end = buf + len;
int ret;
struct arm_exbuf_data edata;

assert(buf != NULL);
assert(len > 0);

while (buf < end)
{
uint8_t op = READ_OP ();
Expand Down
3 changes: 2 additions & 1 deletion src/pal/src/synchmgr/synchmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2507,9 +2507,10 @@ namespace CorUnix
BYTE * pbySrc, * pbyDst = rgSendBuf;
WaitingThreadsListNode * pWLNode = SharedIDToTypePointer(WaitingThreadsListNode, shridWLNode);


_ASSERT_MSG(NULL != pWLNode, "Bad shared wait list node identifier (%p)\n", (VOID*)shridWLNode);
_ASSERT_MSG(gPID != pWLNode->dwProcessId, "WakeUpRemoteThread called on local thread\n");
_ASSERT_MSG(NULL != shridWLNode, "NULL shared identifier\n");
_ASSERT_MSG(NULL != pWLNode, "Bad shared wait list node identifier (%p)\n", (VOID*)shridWLNode);
_ASSERT_MSG(MsgSize <= PIPE_BUF, "Message too long [MsgSize=%d PIPE_BUF=%d]\n", MsgSize, (int)PIPE_BUF);

TRACE("Waking up remote thread {pid=%x, tid=%x} by sending cmd=%u and shridWLNode=%p over process pipe\n",
Expand Down

0 comments on commit 181523f

Please sign in to comment.