public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Fix generating array's size is incorrect in AutoGen.c
@ 2018-05-09  7:41 Yonghong Zhu
  2018-05-10  0:34 ` Zhu, Yonghong
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Zhu @ 2018-05-09  7:41 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yunhua Feng, Liming Gao

From: Yunhua Feng <yunhuax.feng@intel.com>

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 <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>
---
 BaseTools/Source/Python/AutoGen/GenC.py | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py
index d062588..35ebd60 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1055,42 +1055,43 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                                     "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
                                     ExtraData="[%s]" % str(Info))
                 if not Value.endswith('U'):
                     Value += 'U'
         if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
-            if Pcd.MaxDatumSize is 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))
 
             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:
                         NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '
                     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 = Pcd.GetPcdSize()
-                        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.
         # Long term we need PCD macros that work in assembly
         #
-- 
2.6.1.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch] BaseTools: Fix generating array's size is incorrect in AutoGen.c
  2018-05-09  7:41 [Patch] BaseTools: Fix generating array's size is incorrect in AutoGen.c Yonghong Zhu
@ 2018-05-10  0:34 ` Zhu, Yonghong
  0 siblings, 0 replies; 2+ messages in thread
From: Zhu, Yonghong @ 2018-05-10  0:34 UTC (permalink / raw)
  To: Zhu, Yonghong, edk2-devel@lists.01.org
  Cc: Feng, YunhuaX, Gao, Liming, Zhu, Yonghong

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yonghong Zhu
Sent: Wednesday, May 09, 2018 3:41 PM
To: edk2-devel@lists.01.org
Cc: Feng, YunhuaX <yunhuax.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2] [Patch] BaseTools: Fix generating array's size is incorrect in AutoGen.c

From: Yunhua Feng <yunhuax.feng@intel.com>

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 <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>
---
 BaseTools/Source/Python/AutoGen/GenC.py | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py
index d062588..35ebd60 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1055,42 +1055,43 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                                     "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
                                     ExtraData="[%s]" % str(Info))
                 if not Value.endswith('U'):
                     Value += 'U'
         if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
-            if Pcd.MaxDatumSize is 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))
 
             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:
                         NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '
                     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 = Pcd.GetPcdSize()
-                        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.
         # Long term we need PCD macros that work in assembly
         #
--
2.6.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-10  0:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-09  7:41 [Patch] BaseTools: Fix generating array's size is incorrect in AutoGen.c Yonghong Zhu
2018-05-10  0:34 ` Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox