From 7c4e7d7daf3a6fe3ed237fa487b4da3e429eabf2 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 7 Sep 2019 17:42:52 +0200 Subject: [PATCH] fix underflow --- src/Decoder.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Decoder.c b/src/Decoder.c index ea0fe36..70d5dbe 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -4534,14 +4534,17 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, default: break; } - ZYDIS_CHECK(ZydisDecodeOperands(context, instruction, definition)); - const ZydisRegister reg = - instruction->operands[instruction->operandCount - 1].reg.value; - if ((reg == ZYDIS_REGISTER_FLAGS ) || (reg == ZYDIS_REGISTER_EFLAGS) || - (reg == ZYDIS_REGISTER_RFLAGS)) - { - ZydisSetAccessedFlags(instruction, definition); - } + ZYDIS_CHECK(ZydisDecodeOperands(context, instruction, definition)); + if (instruction->operandCount) + { + const ZydisRegister reg = + instruction->operands[instruction->operandCount - 1].reg.value; + if ((reg == ZYDIS_REGISTER_FLAGS) || (reg == ZYDIS_REGISTER_EFLAGS) || + (reg == ZYDIS_REGISTER_RFLAGS)) + { + ZydisSetAccessedFlags(instruction, definition); + } + } } return ZYDIS_STATUS_SUCCESS;