# HG changeset patch # User moel.mich # Date 1286394610 0 # Node ID b5b076457b686f00e824ed3b9a858b8a37468493 # Parent 79e9a77f6a71840647f7837c2bff763d5dff30e1 Added more error checking to the T-Balancer enumeration code. This hopefully fixes an IndexOutOfRangeException in the TBalancerGroup constructor. diff -r 79e9a77f6a71 -r b5b076457b68 Hardware/TBalancer/TBalancerGroup.cs --- a/Hardware/TBalancer/TBalancerGroup.cs Wed Oct 06 19:18:07 2010 +0000 +++ b/Hardware/TBalancer/TBalancerGroup.cs Wed Oct 06 19:50:10 2010 +0000 @@ -51,14 +51,25 @@ uint numDevices; try { - FTD2XX.FT_CreateDeviceInfoList(out numDevices); + if (FTD2XX.FT_CreateDeviceInfoList(out numDevices) != FT_STATUS.FT_OK) { + report.AppendLine("Status: FT_CreateDeviceInfoList failed"); + return; + } } catch (DllNotFoundException) { return; } catch (ArgumentNullException) { return; } catch (EntryPointNotFoundException) { return; } catch (BadImageFormatException) { return; } FT_DEVICE_INFO_NODE[] info = new FT_DEVICE_INFO_NODE[numDevices]; - FTD2XX.FT_GetDeviceInfoList(info, ref numDevices); + if (FTD2XX.FT_GetDeviceInfoList(info, ref numDevices) != FT_STATUS.FT_OK) + { + report.AppendLine("Status: FT_GetDeviceInfoList failed"); + return; + } + + // make sure numDevices is not larger than the info array + if (numDevices > info.Length) + numDevices = (uint)info.Length; for (int i = 0; i < numDevices; i++) { report.Append("Device Index: ");