[edk2-devel] [PATCH] BaseTools/CommonLib: Fix unaligned API prototypes

Marvin Häuser posted 1 patch 2 years, 8 months ago
Failed in applying to current master (apply log)
BaseTools/Source/C/Common/CommonLib.c | 16 ++++++++--------
BaseTools/Source/C/Common/CommonLib.h |  8 ++++----
2 files changed, 12 insertions(+), 12 deletions(-)
[edk2-devel] [PATCH] BaseTools/CommonLib: Fix unaligned API prototypes
Posted by Marvin Häuser 2 years, 8 months ago
C prohibits not only dereferencing but also casting to unaligned
pointers. Thus, the current set of unaligned APIs cannot be called
safely. Update their prototypes to take VOID * pointers, which must
be able to represent any valid pointer.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Vitaly Cheptsov <vit9696@protonmail.com>
Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
---
 BaseTools/Source/C/Common/CommonLib.c | 16 ++++++++--------
 BaseTools/Source/C/Common/CommonLib.h |  8 ++++----
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c
index 7fb4ab764fcd..f1223fb2ae0a 100644
--- a/BaseTools/Source/C/Common/CommonLib.c
+++ b/BaseTools/Source/C/Common/CommonLib.c
@@ -1154,23 +1154,23 @@ StrSize (
 

 UINT64

 ReadUnaligned64 (

-   CONST UINT64              *Buffer

+   CONST VOID                *Buffer

   )

 {

   ASSERT (Buffer != NULL);

 

-  return *Buffer;

+  return *(CONST UINT64 *) Buffer;

 }

 

 UINT64

 WriteUnaligned64 (

-   UINT64                    *Buffer,

+   VOID                      *Buffer,

    UINT64                    Value

   )

 {

   ASSERT (Buffer != NULL);

 

-  return *Buffer = Value;

+  return *(UINT64 *) Buffer = Value;

 }

 

 

@@ -2018,23 +2018,23 @@ AllocatePool (
 

 UINT16

 WriteUnaligned16 (

-  UINT16                    *Buffer,

+  VOID                      *Buffer,

   UINT16                    Value

   )

 {

   ASSERT (Buffer != NULL);

 

-  return *Buffer = Value;

+  return *(UINT16 *) Buffer = Value;

 }

 

 UINT16

 ReadUnaligned16 (

-  CONST UINT16              *Buffer

+  CONST VOID                *Buffer

   )

 {

   ASSERT (Buffer != NULL);

 

-  return *Buffer;

+  return *(CONST UINT16 *) Buffer;

 }

 /**

   Return whether the integer string is a hex string.

diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Common/CommonLib.h
index 0f05d88db206..67c42a91765d 100644
--- a/BaseTools/Source/C/Common/CommonLib.h
+++ b/BaseTools/Source/C/Common/CommonLib.h
@@ -238,13 +238,13 @@ CopyGuid (
 

 UINT64

 WriteUnaligned64 (

-   UINT64                    *Buffer,

+   VOID                      *Buffer,

    UINT64                    Value

   );

 

 UINT64

 ReadUnaligned64 (

-   CONST UINT64              *Buffer

+   CONST VOID                *Buffer

   );

 

 UINTN

@@ -363,13 +363,13 @@ AllocatePool (
 

 UINT16

 WriteUnaligned16 (

-  UINT16                    *Buffer,

+  VOID                      *Buffer,

   UINT16                    Value

   );

 

 UINT16

 ReadUnaligned16 (

-  CONST UINT16              *Buffer

+  CONST VOID                *Buffer

   );

 

 VOID *

-- 
2.31.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#78896): https://edk2.groups.io/g/devel/message/78896
Mute This Topic: https://groups.io/mt/84754071/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-