BaseTools: report error if flag in LABEL() invalid

Flag in LABEL() is not valid C variable name, will report error.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Feng, YunhuaX 2018-03-01 16:22:08 +08:00 committed by Yonghong Zhu
parent 6ee9c68912
commit 5ac0a5450b
1 changed files with 10 additions and 4 deletions

View File

@ -119,6 +119,12 @@ def SplitPcdValueString(String):
RetList.append(Item) RetList.append(Item)
return RetList return RetList
def IsValidCString(Str):
ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
if not ValidString.match(Str):
return False
return True
## ReplaceExprMacro ## ReplaceExprMacro
# #
def ReplaceExprMacro(String, Macros, ExceptionList = None): def ReplaceExprMacro(String, Macros, ExceptionList = None):
@ -885,13 +891,13 @@ class ValueExpressionEx(ValueExpression):
for Index, Item in enumerate(PcdValueList): for Index, Item in enumerate(PcdValueList):
# compute byte offset of every LABEL # compute byte offset of every LABEL
Item = Item.strip() Item = Item.strip()
try: LabelList = ReLabel.findall(Item)
LabelList = ReLabel.findall(Item) if LabelList:
for Label in LabelList: for Label in LabelList:
if not IsValidCString(Label):
raise BadExpression('%s is not a valid c variable name' % Label)
if Label not in LabelDict.keys(): if Label not in LabelDict.keys():
LabelDict[Label] = str(LabelOffset) LabelDict[Label] = str(LabelOffset)
except:
pass
if Item.startswith('UINT8'): if Item.startswith('UINT8'):
LabelOffset = LabelOffset + 1 LabelOffset = LabelOffset + 1
elif Item.startswith('UINT16'): elif Item.startswith('UINT16'):