]> granicus.if.org Git - handbrake/commitdiff
WinGui: Fix some potential null reference exceptions in EnumHelper #1302
authorsr55 <sr55.hb@outlook.com>
Mon, 23 Apr 2018 21:00:44 +0000 (22:00 +0100)
committersr55 <sr55.hb@outlook.com>
Mon, 23 Apr 2018 21:00:44 +0000 (22:00 +0100)
win/CS/HandBrakeWPF/Utilities/EnumHelper.cs

index 33469f7ba9b6f779b1382cee64fed25c22701588..c4ceaeb9483dfbbe23abf29f44242f1cbde4bb9a 100644 (file)
@@ -38,6 +38,11 @@ namespace HandBrakeWPF.Utilities
         /// </returns>
         public static string GetDescription(T value)
         {
+            if (value == null)
+            {
+                return string.Empty;
+            }
+
             FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
             DescriptionAttribute[] attributes =
                   (DescriptionAttribute[])fieldInfo.GetCustomAttributes(
@@ -52,6 +57,11 @@ namespace HandBrakeWPF.Utilities
         /// <returns>A string name</returns>
         public static string GetDisplay(T value)
         {
+            if (value == null)
+            {
+                return string.Empty;
+            }
+
             FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
             DisplayName[] attributes = (DisplayName[])fieldInfo.GetCustomAttributes(typeof(DisplayName), false);
 
@@ -108,6 +118,11 @@ namespace HandBrakeWPF.Utilities
         /// </returns>
         public static string GetShortName(T value)
         {
+            if (value == null)
+            {
+                return string.Empty;
+            }
+
             FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
             ShortName[] attributes = (ShortName[])fieldInfo.GetCustomAttributes(typeof(ShortName), false);