public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] MdePkg/Include: Add enumeration size checks to Base.h
@ 2016-10-26 21:45 Michael Kinney
  2016-10-27  3:17 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Kinney @ 2016-10-26 21:45 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao

https://bugzilla.tianocore.org/show_bug.cgi?id=181

Add size check for 8-bit, 16-bit, and 32-bit enums
to make sure they follow the UEFI Specification 2.3.1
Data Types.

<Enumerated Type>

Element of a standard ANSI C enum type declaration.
Type INT32.or UINT32.  ANSI C does not define the
size of sign of an enum so they should never be
used in structures. ANSI C integer promotion rules
make INT32 or UINT32 interchangeable when passed as
an argument to a function.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
---
 MdePkg/Include/Base.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index c666148..725d9c9 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -63,6 +63,22 @@ VERIFY_SIZE_OF (UINT64, 8);
 VERIFY_SIZE_OF (CHAR8, 1);
 VERIFY_SIZE_OF (CHAR16, 2);
 
+typedef enum {
+  __VerifyUint8EnumValue = 0xff
+} __VERIFY_UINT8_ENUM_SIZE;
+
+typedef enum {
+  __VerifyUint16EnumValue = 0xffff
+} __VERIFY_UINT16_ENUM_SIZE;
+
+typedef enum {
+  __VerifyUint32EnumValue = 0xffffffff
+} __VERIFY_UINT32_ENUM_SIZE;
+
+VERIFY_SIZE_OF (__VERIFY_UINT8_ENUM_SIZE, 4);
+VERIFY_SIZE_OF (__VERIFY_UINT16_ENUM_SIZE, 4);
+VERIFY_SIZE_OF (__VERIFY_UINT32_ENUM_SIZE, 4);
+
 //
 // The Microsoft* C compiler can removed references to unreferenced data items
 //  if the /OPT:REF linker option is used. We defined a macro as this is a
-- 
2.6.3.windows.1



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

* Re: [Patch] MdePkg/Include: Add enumeration size checks to Base.h
  2016-10-26 21:45 [Patch] MdePkg/Include: Add enumeration size checks to Base.h Michael Kinney
@ 2016-10-27  3:17 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2016-10-27  3:17 UTC (permalink / raw)
  To: Kinney, Michael D, edk2-devel@lists.01.org

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

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Michael Kinney
> Sent: Thursday, October 27, 2016 5:46 AM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>
> Subject: [edk2] [Patch] MdePkg/Include: Add enumeration size checks to
> Base.h
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=181
> 
> Add size check for 8-bit, 16-bit, and 32-bit enums
> to make sure they follow the UEFI Specification 2.3.1
> Data Types.
> 
> <Enumerated Type>
> 
> Element of a standard ANSI C enum type declaration.
> Type INT32.or UINT32.  ANSI C does not define the
> size of sign of an enum so they should never be
> used in structures. ANSI C integer promotion rules
> make INT32 or UINT32 interchangeable when passed as
> an argument to a function.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
> ---
>  MdePkg/Include/Base.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index c666148..725d9c9 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -63,6 +63,22 @@ VERIFY_SIZE_OF (UINT64, 8);
>  VERIFY_SIZE_OF (CHAR8, 1);
>  VERIFY_SIZE_OF (CHAR16, 2);
> 
> +typedef enum {
> +  __VerifyUint8EnumValue = 0xff
> +} __VERIFY_UINT8_ENUM_SIZE;
> +
> +typedef enum {
> +  __VerifyUint16EnumValue = 0xffff
> +} __VERIFY_UINT16_ENUM_SIZE;
> +
> +typedef enum {
> +  __VerifyUint32EnumValue = 0xffffffff
> +} __VERIFY_UINT32_ENUM_SIZE;
> +
> +VERIFY_SIZE_OF (__VERIFY_UINT8_ENUM_SIZE, 4);
> +VERIFY_SIZE_OF (__VERIFY_UINT16_ENUM_SIZE, 4);
> +VERIFY_SIZE_OF (__VERIFY_UINT32_ENUM_SIZE, 4);
> +
>  //
>  // The Microsoft* C compiler can removed references to unreferenced data
> items
>  //  if the /OPT:REF linker option is used. We defined a macro as this is a
> --
> 2.6.3.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


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

end of thread, other threads:[~2016-10-27  3:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-26 21:45 [Patch] MdePkg/Include: Add enumeration size checks to Base.h Michael Kinney
2016-10-27  3:17 ` Gao, Liming

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