diff mbox series

[edk2,v2] BaseTools: align ENCODE_ERROR macro with MdePkg version

Message ID 20171205161016.12879-1-leif.lindholm@linaro.org
State New
Headers show
Series [edk2,v2] BaseTools: align ENCODE_ERROR macro with MdePkg version | expand

Commit Message

Leif Lindholm Dec. 5, 2017, 4:10 p.m. UTC
BaseTools' BaseTypes.h defined the ENCODE_ERROR macro as
 #define ENCODE_ERROR(a)              ((RETURN_STATUS)(MAX_BIT | (a)))
whereas MdePkg defines it as
 #define ENCODE_ERROR(StatusCode)     ((RETURN_STATUS)(MAX_BIT | (StatusCode)))

When building with GCC 6.3 (at least) the former triggers
"error: overflow in implicit constant conversion [-Werror=overflow]"
Resolve this by aligning it with the latter one.

This also requires aligning the BaseTools typedef of RETURN_STATUS with
the MdePkg one: INTN -> UINTN.

Add an explicit initialization of *Alignment to 0 in GenFfs.c
GetAlignmentFromFile to get rid of a warning occuring with GCC after
this change (-Werror=maybe-uninitialized).

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>

---

Sending out a v2 because I got cought out by the leading # in the commit
message...

 BaseTools/Source/C/GenFfs/GenFfs.c            | 1 +
 BaseTools/Source/C/Include/Common/BaseTypes.h | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

-- 
2.11.0

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

Comments

Gao, Liming Dec. 7, 2017, 2:41 a.m. UTC | #1
Leif:
  Could you also update ENCODE_WARNING() and RETURN_ERROR() to align to MdePkg?

Thanks
Liming
>-----Original Message-----

>From: Leif Lindholm [mailto:leif.lindholm@linaro.org]

>Sent: Wednesday, December 06, 2017 12:10 AM

>To: edk2-devel@lists.01.org

>Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Gao, Liming

><liming.gao@intel.com>

>Subject: [PATCH v2] BaseTools: align ENCODE_ERROR macro with MdePkg

>version

>

>BaseTools' BaseTypes.h defined the ENCODE_ERROR macro as

> #define ENCODE_ERROR(a)              ((RETURN_STATUS)(MAX_BIT | (a)))

>whereas MdePkg defines it as

> #define ENCODE_ERROR(StatusCode)     ((RETURN_STATUS)(MAX_BIT |

>(StatusCode)))

>

>When building with GCC 6.3 (at least) the former triggers

>"error: overflow in implicit constant conversion [-Werror=overflow]"

>Resolve this by aligning it with the latter one.

>

>This also requires aligning the BaseTools typedef of RETURN_STATUS with

>the MdePkg one: INTN -> UINTN.

>

>Add an explicit initialization of *Alignment to 0 in GenFfs.c

>GetAlignmentFromFile to get rid of a warning occuring with GCC after

>this change (-Werror=maybe-uninitialized).

>

>Contributed-under: TianoCore Contribution Agreement 1.1

>Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>

>---

>

>Sending out a v2 because I got cought out by the leading # in the commit

>message...

>

> BaseTools/Source/C/GenFfs/GenFfs.c            | 1 +

> BaseTools/Source/C/Include/Common/BaseTypes.h | 4 ++--

> 2 files changed, 3 insertions(+), 2 deletions(-)

>

>diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c

>b/BaseTools/Source/C/GenFfs/GenFfs.c

>index e2fb3e0d1e..3b4a9b7761 100644

>--- a/BaseTools/Source/C/GenFfs/GenFfs.c

>+++ b/BaseTools/Source/C/GenFfs/GenFfs.c

>@@ -529,6 +529,7 @@ GetAlignmentFromFile(char *InFile, UINT32

>*Alignment)

>

>   InFileHandle        = NULL;

>   PeFileBuffer        = NULL;

>+  *Alignment          = 0;

>

>   memset (&ImageContext, 0, sizeof (ImageContext));

>

>diff --git a/BaseTools/Source/C/Include/Common/BaseTypes.h

>b/BaseTools/Source/C/Include/Common/BaseTypes.h

>index 198647ab95..5fa4e560d8 100644

>--- a/BaseTools/Source/C/Include/Common/BaseTypes.h

>+++ b/BaseTools/Source/C/Include/Common/BaseTypes.h

>@@ -170,12 +170,12 @@

> // EFI Error Codes common to all execution phases

> //

>

>-typedef INTN RETURN_STATUS;

>+typedef UINTN RETURN_STATUS;

>

> ///

> /// Set the upper bit to indicate EFI Error.

> ///

>-#define ENCODE_ERROR(a)              (MAX_BIT | (a))

>+#define ENCODE_ERROR(a)              ((RETURN_STATUS)(MAX_BIT | (a)))

>

> #define ENCODE_WARNING(a)            (a)

> #define RETURN_ERROR(a)              ((a) < 0)

>--

>2.11.0


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

Patch

diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c
index e2fb3e0d1e..3b4a9b7761 100644
--- a/BaseTools/Source/C/GenFfs/GenFfs.c
+++ b/BaseTools/Source/C/GenFfs/GenFfs.c
@@ -529,6 +529,7 @@  GetAlignmentFromFile(char *InFile, UINT32 *Alignment)
 
   InFileHandle        = NULL;
   PeFileBuffer        = NULL;
+  *Alignment          = 0;
 
   memset (&ImageContext, 0, sizeof (ImageContext));
 
diff --git a/BaseTools/Source/C/Include/Common/BaseTypes.h b/BaseTools/Source/C/Include/Common/BaseTypes.h
index 198647ab95..5fa4e560d8 100644
--- a/BaseTools/Source/C/Include/Common/BaseTypes.h
+++ b/BaseTools/Source/C/Include/Common/BaseTypes.h
@@ -170,12 +170,12 @@ 
 // EFI Error Codes common to all execution phases
 //
 
-typedef INTN RETURN_STATUS;
+typedef UINTN RETURN_STATUS;
 
 ///
 /// Set the upper bit to indicate EFI Error.
 ///
-#define ENCODE_ERROR(a)              (MAX_BIT | (a))
+#define ENCODE_ERROR(a)              ((RETURN_STATUS)(MAX_BIT | (a)))
 
 #define ENCODE_WARNING(a)            (a)
 #define RETURN_ERROR(a)              ((a) < 0)