From: Michael Kinney Date: Thu, 18 Aug 2016 06:41:20 +0000 (-0700) Subject: MdePkg/Include: Add enumeration size checks to Base.h X-Git-Tag: edk2-stable201903~5421 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=6440385b17def888544c2454ffba58384b929a22;ds=sidebyside 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. 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 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney Reviewed-by: Liming Gao --- diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h index 82a773ae74..22170581a0 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