Skip to content

Commit 6d7c45d

Browse files
author
ChengNan
committed
Fix more klockwork issues
1 parent c69461d commit 6d7c45d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ViveRole/ViveRoleEnum.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public Info(Type roleEnumType)
6767
m_info = EnumUtils.GetDisplayInfo(roleEnumType);
6868

6969
var attrs = roleEnumType.GetCustomAttributes(typeof(ViveRoleEnumAttribute), false) as ViveRoleEnumAttribute[];
70+
if (attrs == null) return;
7071
m_invalidRoleValue = attrs[0].InvalidRoleValue;
7172

7273
m_minValidRoleValue = int.MaxValue;
@@ -172,6 +173,7 @@ public GenericInfo()
172173
{
173174
m_info = GetInfo(typeof(TRole));
174175
var roleEnums = m_info.RoleValues as TRole[];
176+
if (roleEnums == null) { return; }
175177

176178
m_nameTable = new IndexedTable<string, TRole>(roleEnums.Length);
177179
m_roles = new TRole[ValidRoleLength];
@@ -183,8 +185,6 @@ public GenericInfo()
183185

184186
for (int i = 0; i < roleEnums.Length; ++i)
185187
{
186-
if (roleEnums[i] == null) continue;
187-
188188
var roleValue = ToRoleValue(roleEnums[i]);
189189

190190
m_nameTable.Add(GetNameByElementIndex(i), roleEnums[i]);
@@ -352,13 +352,14 @@ public static ViveRoleEnumValidateResult ValidateViveRoleEnum(Type roleEnumType)
352352
}
353353

354354
var attrs = roleEnumType.GetCustomAttributes(typeof(ViveRoleEnumAttribute), false) as ViveRoleEnumAttribute[];
355-
if (attrs.Length <= 0)
355+
if (attrs == null || attrs.Length <= 0)
356356
{
357357
return ViveRoleEnumValidateResult.ViveRoleEnumAttributeNotFound;
358358
}
359359

360360
var invalidRoleValue = attrs[0].InvalidRoleValue;
361361
var values = Enum.GetValues(roleEnumType) as int[];
362+
if (values == null) return ViveRoleEnumValidateResult.IsNotEnumType;
362363
var invalidRoleFound = false;
363364
foreach (var value in values)
364365
{

0 commit comments

Comments
 (0)