-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Description
Consider the following program:
using System;
using System.Collections;
static class Foo
{
static void Main()
{
IList l = new byte[int.MaxValue / 2 + 2];
ArrayList al = ArrayList.Adapter(l);
int result = al.BinarySearch((byte)1);
Console.WriteLine(result);
}
}This will overflow here:
runtime/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs
Line 774 in be04169
| mid = (lo + hi) / 2; |
I would instead expect this to return a value indicating it could not be found.
The GetMedian method on Array is likely the "right" implementation to use for calculating mid.
Reactions are currently unavailable