From 3e10baea6346dcf7029d8b3b5cd80db3f38107f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Wed, 6 Oct 2010 19:50:10 +0000 Subject: [PATCH] Added more error checking to the T-Balancer enumeration code. This hopefully fixes an IndexOutOfRangeException in the TBalancerGroup constructor. --- Hardware/TBalancer/TBalancerGroup.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Hardware/TBalancer/TBalancerGroup.cs b/Hardware/TBalancer/TBalancerGroup.cs index 9ba1583..be8ff7a 100644 --- a/Hardware/TBalancer/TBalancerGroup.cs +++ b/Hardware/TBalancer/TBalancerGroup.cs @@ -51,14 +51,25 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { 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: ");