Skip to content

Commit 079ca96

Browse files
committed
Updating array validation in helper functions
Change-Id: I9dd753d27af6041f96792ad2958a5cc4f0093ca4
1 parent b6e35d0 commit 079ca96

File tree

1 file changed

+36
-12
lines changed
  • src/tests/JIT/HardwareIntrinsics/Arm/Shared

1 file changed

+36
-12
lines changed

src/tests/JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,21 +2299,27 @@ public static uint AddCarryWideningEven(uint[] op1, uint[] op2, uint[] op3, int
22992299
ulong res;
23002300

23012301
if (i < 0 || i >= op1.Length || i >= op2.Length || i >= op3.Length)
2302+
{
23022303
throw new ArgumentOutOfRangeException(nameof(i), "Index i is out of range");
2304+
}
23032305

23042306
if (i % 2 == 0)
23052307
{
2306-
if (i + 1 >= op3.Length)
2307-
throw new ArgumentOutOfRangeException(nameof(i), "Index i + 1 is out of range for op3.");
2308+
if (i + 1 >= op2.Length)
2309+
{
2310+
throw new ArgumentOutOfRangeException(nameof(i), "Index i + 1 is out of range.");
2311+
}
23082312

23092313
lsb = op2[i + 1] & 1u;
23102314
res = (ulong)op1[i] + op3[i] + lsb;
23112315
return (uint)res;
23122316
}
23132317
else
23142318
{
2315-
if (i - 1 < 0)
2319+
if (i - 1 < 0 || i - 1 >= op1.Length || i - 1 >= op3.Length)
2320+
{
23162321
throw new ArgumentOutOfRangeException(nameof(i), "Index i - 1 is out of range.");
2322+
}
23172323

23182324
lsb = op2[i] & 1u;
23192325
res = (ulong)op1[i - 1] + op3[i - 1] + lsb;
@@ -2329,21 +2335,27 @@ public static uint AddCarryWideningOdd(uint[] op1, uint[] op2, uint[] op3, int i
23292335
ulong res;
23302336

23312337
if (i < 0 || i >= op1.Length || i >= op2.Length || i >= op3.Length)
2338+
{
23322339
throw new ArgumentOutOfRangeException(nameof(i), "Index i is out of range");
2340+
}
23332341

23342342
if (i % 2 == 0)
23352343
{
2336-
if (i + 1 >= op3.Length)
2337-
throw new ArgumentOutOfRangeException(nameof(i), "Index i + 1 is out of range for op3.");
2344+
if (i + 1 >= op1.Length || i + 1 >= op2.Length)
2345+
{
2346+
throw new ArgumentOutOfRangeException(nameof(i), "Index i + 1 is out of range.");
2347+
}
23382348

23392349
lsb = op2[i + 1] & 1u;
2340-
res = (ulong)op1[i + 1] + op3[i] + lsb;
2350+
res = (ulong)op1[i + 1] + op3[i] + lsb;
23412351
return (uint)res;
23422352
}
23432353
else
23442354
{
2345-
if (i - 1 < 0)
2355+
if (i - 1 < 0 || i - 1 >= op3.Length)
2356+
{
23462357
throw new ArgumentOutOfRangeException(nameof(i), "Index i - 1 is out of range.");
2358+
}
23472359

23482360
lsb = op2[i] & 1u;
23492361
res = (ulong)op1[i] + op3[i - 1] + lsb;
@@ -2482,21 +2494,27 @@ public static ulong AddCarryWideningEven(ulong[] op1, ulong[] op2, ulong[] op3,
24822494
ulong res;
24832495

24842496
if (i < 0 || i >= op1.Length || i >= op2.Length || i >= op3.Length)
2497+
{
24852498
throw new ArgumentOutOfRangeException(nameof(i), "Index i is out of range");
2499+
}
24862500

24872501
if (i % 2 == 0)
24882502
{
2489-
if (i + 1 >= op3.Length)
2503+
if (i + 1 >= op2.Length)
2504+
{
24902505
throw new ArgumentOutOfRangeException(nameof(i), "Index i + 1 is out of range for op3.");
2506+
}
24912507

24922508
lsb = op2[i + 1] & 1UL;
24932509
res = op1[i] + op3[i] + lsb;
24942510
return res;
24952511
}
24962512
else
24972513
{
2498-
if (i - 1 < 0)
2514+
if (i - 1 < 0 || i - 1 >= op1.Length || i - 1 >= op3.Length)
2515+
{
24992516
throw new ArgumentOutOfRangeException(nameof(i), "Index i - 1 is out of range.");
2517+
}
25002518

25012519
lsb = op2[i] & 1UL;
25022520

@@ -2517,21 +2535,27 @@ public static ulong AddCarryWideningOdd(ulong[] op1, ulong[] op2, ulong[] op3, i
25172535
ulong res;
25182536

25192537
if (i < 0 || i >= op1.Length || i >= op2.Length || i >= op3.Length)
2538+
{
25202539
throw new ArgumentOutOfRangeException(nameof(i), "Index i is out of range");
2540+
}
25212541

25222542
if (i % 2 == 0)
25232543
{
2524-
if (i + 1 >= op3.Length)
2525-
throw new ArgumentOutOfRangeException(nameof(i), "Index i + 1 is out of range for op3.");
2544+
if (i + 1 >= op1.Length || i + 1 >= op2.Length)
2545+
{
2546+
throw new ArgumentOutOfRangeException(nameof(i), "Index i + 1 is out of range.");
2547+
}
25262548

25272549
lsb = op2[i + 1] & 1UL;
25282550
res = op1[i + 1] + op3[i] + lsb;
25292551
return res;
25302552
}
25312553
else
25322554
{
2533-
if (i - 1 < 0)
2555+
if (i - 1 < 0 || i - 1 >= op3.Length)
2556+
{
25342557
throw new ArgumentOutOfRangeException(nameof(i), "Index i - 1 is out of range.");
2558+
}
25352559

25362560
lsb = op2[i] & 1UL;
25372561

0 commit comments

Comments
 (0)