Skip to content

Commit

Permalink
Jump directly to exit on error and eliminate the stop variable
Browse files Browse the repository at this point in the history
  • Loading branch information
turol committed Aug 26, 2024
1 parent c611c8a commit 5577520
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions bddisasm/bdx86_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -3341,13 +3341,12 @@ NdFindInstruction(
NDSTATUS status;
const ND_TABLE *pTable;
ND_IDBE *pIns;
ND_BOOL stop, redf2, redf3;
ND_BOOL redf2, redf3;
ND_UINT32 nextOpcode;

// pre-init
status = ND_STATUS_SUCCESS;
pIns = (ND_IDBE *)ND_NULL;
stop = ND_FALSE;
nextOpcode = 0;
redf2 = redf3 = ND_FALSE;

Expand Down Expand Up @@ -3379,22 +3378,22 @@ NdFindInstruction(
break;
}

while ((!stop) && (ND_NULL != pTable))
while (ND_NULL != pTable)
{
switch (pTable->Type)
{
case ND_ILUT_INSTRUCTION:
// We've found the leaf entry, which is an instruction - we can leave.
pIns = (ND_IDBE *)(((ND_TABLE_INSTRUCTION *)pTable)->Instruction);
stop = ND_TRUE;
goto success;
break;

case ND_ILUT_OPCODE:
// We need an opcode to keep going.
status = NdFetchOpcode(Instrux, Code, Instrux->Length, Size);
if (!ND_SUCCESS(status))
{
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}

Expand All @@ -3409,7 +3408,7 @@ NdFindInstruction(
status = NdFetchModrmSibDisplacement(Instrux, Code, Instrux->Length, Size);
if (!ND_SUCCESS(status))
{
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}
}
Expand All @@ -3418,7 +3417,7 @@ NdFindInstruction(
status = NdFetchOpcode(Instrux, Code, Instrux->Length, Size);
if (!ND_SUCCESS(status))
{
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}

Expand All @@ -3433,7 +3432,7 @@ NdFindInstruction(
status = NdFetchModrmSibDisplacement(Instrux, Code, Instrux->Length, Size);
if (!ND_SUCCESS(status))
{
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}
}
Expand All @@ -3450,7 +3449,7 @@ NdFindInstruction(
status = NdFetchModrmSibDisplacement(Instrux, Code, Instrux->Length, Size);
if (!ND_SUCCESS(status))
{
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}
}
Expand All @@ -3467,7 +3466,7 @@ NdFindInstruction(
status = NdFetchModrmSibDisplacement(Instrux, Code, Instrux->Length, Size);
if (!ND_SUCCESS(status))
{
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}
}
Expand Down Expand Up @@ -3658,7 +3657,7 @@ NdFindInstruction(
status = NdFetchModrmSibDisplacement(Instrux, Code, Instrux->Length, Size);
if (!ND_SUCCESS(status))
{
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}
}
Expand Down Expand Up @@ -3717,24 +3716,20 @@ NdFindInstruction(

default:
status = ND_STATUS_INTERNAL_ERROR;
stop = ND_TRUE;
goto cleanup_and_exit;
break;
}
}

// Error - leave now.
if (!ND_SUCCESS(status))
{
goto cleanup_and_exit;
}

// No encoding found - leave now.
if (ND_NULL == pIns)
{
status = ND_STATUS_INVALID_ENCODING;
goto cleanup_and_exit;
}

success:

// Bingo! Valid instruction found for the encoding. If Modrm is needed and we didn't fetch it - do it now.
if ((pIns->Attributes & ND_FLAG_MODRM) && (!Instrux->HasModRm))
{
Expand Down

0 comments on commit 5577520

Please sign in to comment.