Skip to content

Commit

Permalink
Merge pull request #1938 from mjunix/small-fixes
Browse files Browse the repository at this point in the history
Fix potential array out of bounds
  • Loading branch information
kabeor committed Jan 19, 2023
2 parents 7ed00ec + 313ce26 commit b59bbc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions arch/RISCV/RISCVDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static DecodeStatus DecodeGPRRegisterClass(MCInst *Inst, uint64_t RegNo,
{
unsigned Reg = 0;

if (RegNo > sizeof(GPRDecoderTable))
if (RegNo >= ARR_SIZE(GPRDecoderTable))
return MCDisassembler_Fail;

// We must define our own mapping from RegNo to register identifier.
Expand Down Expand Up @@ -101,7 +101,7 @@ static DecodeStatus DecodeFPR32RegisterClass(MCInst *Inst, uint64_t RegNo,
{
unsigned Reg = 0;

if (RegNo > sizeof(FPR32DecoderTable))
if (RegNo >= ARR_SIZE(FPR32DecoderTable))
return MCDisassembler_Fail;

// We must define our own mapping from RegNo to register identifier.
Expand Down Expand Up @@ -141,7 +141,7 @@ static DecodeStatus DecodeFPR64RegisterClass(MCInst *Inst, uint64_t RegNo,
{
unsigned Reg = 0;

if (RegNo > sizeof(FPR64DecoderTable))
if (RegNo >= ARR_SIZE(FPR64DecoderTable))
return MCDisassembler_Fail;

// We must define our own mapping from RegNo to register identifier.
Expand Down
2 changes: 1 addition & 1 deletion arch/TMS320C64x/TMS320C64xMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ const char *TMS320C64x_group_name(csh handle, unsigned int id)
#ifndef CAPSTONE_DIET
unsigned int i;

if (id >= TMS320C64X_GRP_ENDING)
if (id >= ARR_SIZE(group_name_maps))
return NULL;

for (i = 0; i < ARR_SIZE(group_name_maps); i++) {
Expand Down

0 comments on commit b59bbc5

Please sign in to comment.