From 5a678f96d81ff0e456f3c8d09becdab99e0b10ac Mon Sep 17 00:00:00 2001 From: brandman211 Date: Thu, 7 Jun 2012 18:41:39 +0000 Subject: [PATCH] Fixed Issue 69 by properly chucking the invalid lines out of watch files instead of trying to get out of range substrings and parsing non-numbers as integers. Also, as the newly stored SystemID has yet to be accounted for in any way, I made the parser skip those lines. Not sure if there's something Ram Watch should do with this data as it seems like the SystemID is more accurately defined by the core currently running. --- BizHawk.MultiClient/tools/WatchCommon.cs | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/BizHawk.MultiClient/tools/WatchCommon.cs b/BizHawk.MultiClient/tools/WatchCommon.cs index def9ddc9f8..2e9143b499 100644 --- a/BizHawk.MultiClient/tools/WatchCommon.cs +++ b/BizHawk.MultiClient/tools/WatchCommon.cs @@ -66,9 +66,12 @@ namespace BizHawk.MultiClient //Any properly formatted line couldn't possibly be this short anyway, this also takes care of any garbage lines that might be in a file if (s.Length < 5) continue; - if (s.Substring(0, 6) == "Domain") + if (s.Length >= 6 && s.Substring(0, 6) == "Domain") domain = s.Substring(7, s.Length - 7); + if (s.Length >= 8 && s.Substring(0, 8) == "SystemID") + continue; + z = HowMany(s, '\t'); if (z == 5) { @@ -82,19 +85,34 @@ namespace BizHawk.MultiClient Watch w = new Watch(); temp = s.Substring(0, s.IndexOf('\t')); - w.address = int.Parse(temp, NumberStyles.HexNumber); + try + { + w.address = int.Parse(temp, NumberStyles.HexNumber); + } + catch + { + continue; + } y = s.IndexOf('\t') + 1; s = s.Substring(y, s.Length - y); //Type - w.SetTypeByChar(s[0]); + if (!w.SetTypeByChar(s[0])) + continue; y = s.IndexOf('\t') + 1; s = s.Substring(y, s.Length - y); //Signed - w.SetSignedByChar(s[0]); + if (!w.SetSignedByChar(s[0])) + continue; y = s.IndexOf('\t') + 1; s = s.Substring(y, s.Length - y); //Endian - y = Int16.Parse(s[0].ToString()); + try { + y = Int16.Parse(s[0].ToString()); + } + catch + { + continue; + } if (y == 0) w.bigendian = false; else