From 7a49ab6e54a1fe6f33cf1e1ccbf46c8dd59015d1 Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 23 Apr 2018 22:00:44 +0100 Subject: [PATCH] WinGui: Fix some potential null reference exceptions in EnumHelper #1302 --- win/CS/HandBrakeWPF/Utilities/EnumHelper.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs index 33469f7ba..c4ceaeb94 100644 --- a/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs +++ b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs @@ -38,6 +38,11 @@ namespace HandBrakeWPF.Utilities /// 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 /// A string name 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 /// 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); -- 2.40.0