BaseTools: Fix generating array's size is incorrect in AutoGen.c

case example:
DSC:
 [PcdsFixedAtBuild]
  PcdToken.PcdName | "A"
 [Components]
 TestPkg/TestDriver.inf {
  PcdToken.PcdName | {0x41,0x42,0x43,0x44}
 }

Generating the size of array is incorrect in AutoGen.c
 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8
 _gPcd_FixedAtBuild_PcdName[2] = {0x41,0x42,0x43,0x44};

Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=950
Cc: Liming Gao <[email protected]>
Cc: Yonghong Zhu <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <[email protected]>
Reviewed-by: Yonghong Zhu <[email protected]>
(cherry picked from commit 6b285ca366)
This commit is contained in:
Yunhua Feng authored and Yonghong Zhu committed 2018-06-13 13:46:29 +08:00
1 parent b2f88d18a3
commit 5d10602df7
1 file changed
+13 -12
+13 -12
View File
@@ -1087,7 +1087,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
if not Value.endswith('U'):
Value += 'U'
if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':
if not Pcd.MaxDatumSize:
EdkLogger.error("build", AUTOGEN_ERROR,
"Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),
ExtraData="[%s]" % str(Info))
@@ -1095,11 +1095,13 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
ArraySize = int(Pcd.MaxDatumSize, 0)
if Value[0] == '{':
Type = '(VOID *)'
ValueSize = len(Value.split(','))
else:
if Value[0] == 'L':
Unicode = True
Value = Value.lstrip('L') #.strip('"')
Value = eval(Value) # translate escape character
ValueSize = len(Value) + 1
NewValue = '{'
for Index in range(0,len(Value)):
if Unicode:
@@ -1107,18 +1109,17 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
else:
NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '
if Unicode:
ArraySize = ArraySize / 2;
if ArraySize < (len(Value) + 1):
if Pcd.MaxSizeUserSet:
EdkLogger.error("build", AUTOGEN_ERROR,
"The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),
ExtraData="[%s]" % str(Info))
else:
ArraySize = GetPcdSize(Pcd)
if Unicode:
ArraySize = ArraySize / 2
ArraySize = ArraySize / 2
Value = NewValue + '0 }'
if ArraySize < ValueSize:
if Pcd.MaxSizeUserSet:
EdkLogger.error("build", AUTOGEN_ERROR,
"The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),
ExtraData="[%s]" % str(Info))
else:
ArraySize = Pcd.GetPcdSize()
if Unicode:
ArraySize = ArraySize / 2
Array = '[%d]' % ArraySize
#
# skip casting for fixed at build since it breaks ARM assembly.