BaseTools: check before accessing members in __eq__

minimize risk for exceptions.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Carsey, Jaben 2018-04-28 06:32:17 +08:00 committed by Yonghong Zhu
parent a7360838d7
commit b7b51025b9
2 changed files with 3 additions and 5 deletions

View File

@ -259,10 +259,7 @@ class VAR_CHECK_PCD_VALID_OBJ(object):
self.ValidData = False self.ValidData = False
def __eq__(self, validObj): def __eq__(self, validObj):
if self.VarOffset == validObj.VarOffset: return validObj and self.VarOffset == validObj.VarOffset
return True
else:
return False
class VAR_CHECK_PCD_VALID_LIST(VAR_CHECK_PCD_VALID_OBJ): class VAR_CHECK_PCD_VALID_LIST(VAR_CHECK_PCD_VALID_OBJ):
def __init__(self, VarOffset, validlist, PcdDataType): def __init__(self, VarOffset, validlist, PcdDataType):

View File

@ -377,7 +377,8 @@ class BuildUnit:
# @param Other The other BuildUnit object compared to # @param Other The other BuildUnit object compared to
# #
def __eq__(self, Other): def __eq__(self, Other):
return Other is not None and self.BuildObject == Other.BuildObject \ return Other and self.BuildObject == Other.BuildObject \
and Other.BuildObject \
and self.BuildObject.Arch == Other.BuildObject.Arch and self.BuildObject.Arch == Other.BuildObject.Arch
## hash() method ## hash() method