diff mbox

Commit: AArch64 sim: Fix off by one error checking for invalid vector array element

Message ID 87fuvnu9q7.fsf@redhat.com
State New
Headers show

Commit Message

Nick Clifton March 18, 2016, 2:44 p.m. UTC
Hi Guys,

  I am checking in the patch below to fix an off-by-one error pointed
  out by Mike Frysinger in my previous delta to the AArch64 simulator's
  vector register get and set functions.

Cheers
  Nick

sim/aarch64/ChangeLog
2016-03-18  Nick Clifton  <nickc@redhat.com>

	* cpustate.c (GET_VEC_ELEMENT): Fix off by one error checking
	for an invalid element index.
	(SET_VEC_ELEMENT): Likewise.

Comments

Andreas Schwab March 18, 2016, 2:54 p.m. UTC | #1
Nick Clifton <nickc@redhat.com> writes:

> diff --git a/sim/aarch64/cpustate.c b/sim/aarch64/cpustate.c
> index 86b1b15..19f485e 100644
> --- a/sim/aarch64/cpustate.c
> +++ b/sim/aarch64/cpustate.c
> @@ -345,7 +345,7 @@ aarch64_set_FP_long_double (sim_cpu *cpu, VReg reg, FRegister a)
>  #define GET_VEC_ELEMENT(REG, ELEMENT, FIELD)	   \
>    do						   \
>      {						   \
> -      if (element > ARRAY_SIZE (cpu->fr[0].FIELD)) \
> +      if (element >= ARRAY_SIZE (cpu->fr[0].FIELD)) \

s/element/ELEMENT/

Andreas.
Nick Clifton March 18, 2016, 5:10 p.m. UTC | #2
Hi Andreas,

>>   #define GET_VEC_ELEMENT(REG, ELEMENT, FIELD)	   \
>>     do						   \
>>       {						   \
>> +      if (element >= ARRAY_SIZE (cpu->fr[0].FIELD)) \
> 
> s/element/ELEMENT/

Doh!  Obvious fix checked in.  Thanks for spotting this.

Cheers
  Nick
diff mbox

Patch

diff --git a/sim/aarch64/cpustate.c b/sim/aarch64/cpustate.c
index 86b1b15..19f485e 100644
--- a/sim/aarch64/cpustate.c
+++ b/sim/aarch64/cpustate.c
@@ -345,7 +345,7 @@  aarch64_set_FP_long_double (sim_cpu *cpu, VReg reg, FRegister a)
 #define GET_VEC_ELEMENT(REG, ELEMENT, FIELD)	   \
   do						   \
     {						   \
-      if (element > ARRAY_SIZE (cpu->fr[0].FIELD)) \
+      if (element >= ARRAY_SIZE (cpu->fr[0].FIELD)) \
 	{								\
 	  TRACE_REGISTER (cpu, \
 			  "Internal SIM error: invalid element number: %d ",\
@@ -421,7 +421,7 @@  aarch64_get_vec_double (sim_cpu *cpu, VReg reg, unsigned element)
 #define SET_VEC_ELEMENT(REG, ELEMENT, VAL, FIELD, PRINTER)	\
   do						   		\
     {								\
-      if (ELEMENT > ARRAY_SIZE (cpu->fr[0].FIELD))			\
+      if (ELEMENT >= ARRAY_SIZE (cpu->fr[0].FIELD))			\
 	{								\
 	  TRACE_REGISTER (cpu, \
 			  "Internal SIM error: invalid element number: %d ",\