From 55d2f437ccd94a1e1cac1eb3f3ec4cf5d8bc882f Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 20 Nov 2017 17:18:31 -0500 Subject: [PATCH] Potential fix for reading null IPIDs from configs --- ICD.Common.Utils/StringUtils.cs | 13 +++++++++++-- ICD.Common.Utils/Xml/XmlReaderExtensions.cs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ICD.Common.Utils/StringUtils.cs b/ICD.Common.Utils/StringUtils.cs index 325a55e..5743312 100644 --- a/ICD.Common.Utils/StringUtils.cs +++ b/ICD.Common.Utils/StringUtils.cs @@ -452,8 +452,17 @@ namespace ICD.Common.Utils /// public static byte FromIpIdString(string value) { - value = value.Replace("0x", ""); - return Convert.ToByte(value, 16); + if (value == null) + throw new ArgumentNullException("value"); + + try + { + return (byte)Convert.ToInt64(value, 16); + } + catch (ArgumentOutOfRangeException e) + { + throw new FormatException(e.Message, e); + } } /// diff --git a/ICD.Common.Utils/Xml/XmlReaderExtensions.cs b/ICD.Common.Utils/Xml/XmlReaderExtensions.cs index 87b8617..f1d9510 100644 --- a/ICD.Common.Utils/Xml/XmlReaderExtensions.cs +++ b/ICD.Common.Utils/Xml/XmlReaderExtensions.cs @@ -246,7 +246,7 @@ namespace ICD.Common.Utils.Xml throw new ArgumentNullException("extends"); string content = extends.ReadElementContentAsString(); - return (byte)Convert.ToInt64(content, 16); + return StringUtils.FromIpIdString(content); } ///