Reviewed-by: Liming Gao <liming....@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
>Feng, Bob C
>Sent: Saturday, February 16, 2019 1:54 PM
>To: edk2-devel@lists.01.org
>Cc: Gao, Liming <liming....@intel.com>
>Subject: [edk2] [Patch] BaseTools: Fixed a code bug for Pcd Array.
>
>For example, PCD gUefiOvmfPkgTokenSpaceGuid.Test001 datatype is Array:
>TEST1[2]
>and the filed TEST1UINT64ARRAY in TEST1 is also an array:
>UINT64 TEST1UINT64ARRAY[2];
>
>Then the following filed assignment in DSC will cause build failure.
>gUefiOvmfPkgTokenSpaceGuid.Test001[0].TEST1UINT64ARRAY|{'A','B'}
>
>The root cause is build tool generate incorrect PcdValueInit.c File.
>
>This patch is going to fix this issue.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Bob Feng <bob.c.f...@intel.com>
>Cc: Liming Gao <liming....@intel.com>
>---
> BaseTools/Source/Python/Workspace/DscBuildData.py | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index 1fd1639ab6..e45beb3924 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -2015,14 +2015,13 @@ class DscBuildData(PlatformBuildClassObject):
>                 indicator = self.GetIndicator(index, FieldName,Pcd)
>                 if IsArray:
>                     #
>                     # Use memcpy() to copy value into field
>                     #
>-                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.DatumType, FieldName)
>+                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.BaseDatumType, FieldName)
>                     CApp = CApp + '  Value     = %s; // From %s Line %d Value 
> %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= 
>%d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>-                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 
>&&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= 
>%d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                     CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 && 
> FieldSize
>< %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)
>                 elif isinstance(Value, str):
>                     CApp = CApp + '  %s = %s; // From %s Line %d Value %s\n' %
>(indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>                 else:
>                     if '[' in FieldName and ']' in FieldName:
>@@ -2130,12 +2129,11 @@ class DscBuildData(PlatformBuildClassObject):
>                     #
>                     # Use memcpy() to copy value into field
>                     #
>                         CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' 
> %
>(Pcd.BaseDatumType, FieldName)
>                         CApp = CApp + '  Value     = %s; // From %s Line %d 
> Value %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                        CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, 
>%s) >= %d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>-                        CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize 
>> 0 &&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>+                        CApp = CApp + '
>__STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s)
>== 0), "Input buffer exceeds the buffer array"); // From %s Line %d
>Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                         CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 
> && FieldSize
>< %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)
>                     else:
>                         if '[' in FieldName and ']' in FieldName:
>                             Index = int(FieldName.split('[')[1].split(']')[0])
>                             CApp = CApp + '  __STATIC_ASSERT((%d < 
> __ARRAY_SIZE(Pcd-
>>%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array
>number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0],
>FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2],
>FieldName)
>@@ -2200,11 +2198,11 @@ class DscBuildData(PlatformBuildClassObject):
>                 #
>                 # Use memcpy() to copy value into field
>                 #
>                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.BaseDatumType, FieldName)
>                     CApp = CApp + '  Value     = %s; // From %s Line %d Value 
> %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= 
>%d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= 
>%d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 
> &&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>                 else:
>                     if '[' in FieldName and ']' in FieldName:
>                         Index = int(FieldName.split('[')[1].split(']')[0])
>                         CApp = CApp + '  __STATIC_ASSERT((%d < 
> __ARRAY_SIZE(Pcd-
>>%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array
>number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0],
>FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2],
>FieldName)
>@@ -2268,11 +2266,11 @@ class DscBuildData(PlatformBuildClassObject):
>                 #
>                 # Use memcpy() to copy value into field
>                 #
>                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' %
>(Pcd.BaseDatumType, FieldName)
>                     CApp = CApp + '  Value     = %s; // From %s Line %d Value 
> %s\n' %
>(DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= 
>%d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize,
>Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= 
>%d)
>|| (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); //
>From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize,
>Pcd.BaseDatumType, FieldName, FieldList[FieldName][1],
>FieldList[FieldName][2], FieldList[FieldName][0])
>                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 
> &&
>FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
>                 else:
>                     if '[' in FieldName and ']' in FieldName:
>                         Index = int(FieldName.split('[')[1].split(']')[0])
>                         CApp = CApp + '  __STATIC_ASSERT((%d < 
> __ARRAY_SIZE(Pcd-
>>%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array
>number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0],
>FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2],
>FieldName)
>--
>2.18.0.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to