From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by mx.groups.io with SMTP id smtpd.web12.20843.1628502713852478813 for ; Mon, 09 Aug 2021 02:51:54 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@posteo.de header.s=2017 header.b=e33osSvd; spf=pass (domain: posteo.de, ip: 185.67.36.65, mailfrom: mhaeuser@posteo.de) Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 63EE5240026 for ; Mon, 9 Aug 2021 11:51:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1628502711; bh=EKtlqSC06HbbVBC7JAteFl0RWi+GoeguV4PhR61dkb8=; h=From:To:Cc:Subject:Date:From; b=e33osSvdsWNGbxBuDfV51PVDlyj7SlMnXth2oJf0bziqV8jw0u1s8PLGRYuiiP5hn PBplGR9DiI64QybcovmaG4rvzOJ/12zEJeSlC979plNAzfWjFFWmf9MumPNPvmBmCl TWb3yg1JpZdVyZVKPKYhfTpykaDJ+M/B2DBm3j6sqY/ICVP0xQJHa0SIT/xHtTkXfw IbVtvZ3SpW4SAK5AZ0NuMI0LNQb+ZgvCfpjXxfZVnWEGeO3rPNOVYn6PCKF03QDJw8 jBaouyDhpD5JqsuHfu0CUnLCy3oDtSXmZGxdW9t/edoqWWGSD8vQgN+OsflVC4zDGf mu+0bxcWwZBCw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Gjrvp6tvJz6tmP; Mon, 9 Aug 2021 11:51:50 +0200 (CEST) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao , Yuwei Chen , Vitaly Cheptsov Subject: [PATCH v2 2/2] BaseTools/CommonLib: Fix unaligned API prototypes Date: Mon, 9 Aug 2021 09:51:24 +0000 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 Cc: Liming Gao Cc: Yuwei Chen Cc: Vitaly Cheptsov Signed-off-by: Marvin H=C3=A4user --- 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/Com= mon/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 ( =0D UINT64=0D ReadUnaligned64 (=0D - CONST UINT64 *Buffer=0D + CONST VOID *Buffer=0D )=0D {=0D ASSERT (Buffer !=3D NULL);=0D =0D - return *Buffer;=0D + return *(CONST UINT64 *) Buffer;=0D }=0D =0D UINT64=0D WriteUnaligned64 (=0D - UINT64 *Buffer,=0D + VOID *Buffer,=0D UINT64 Value=0D )=0D {=0D ASSERT (Buffer !=3D NULL);=0D =0D - return *Buffer =3D Value;=0D + return *(UINT64 *) Buffer =3D Value;=0D }=0D =0D =0D @@ -2018,23 +2018,23 @@ AllocatePool ( =0D UINT16=0D WriteUnaligned16 (=0D - UINT16 *Buffer,=0D + VOID *Buffer,=0D UINT16 Value=0D )=0D {=0D ASSERT (Buffer !=3D NULL);=0D =0D - return *Buffer =3D Value;=0D + return *(UINT16 *) Buffer =3D Value;=0D }=0D =0D UINT16=0D ReadUnaligned16 (=0D - CONST UINT16 *Buffer=0D + CONST VOID *Buffer=0D )=0D {=0D ASSERT (Buffer !=3D NULL);=0D =0D - return *Buffer;=0D + return *(CONST UINT16 *) Buffer;=0D }=0D /**=0D Return whether the integer string is a hex string.=0D diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Com= mon/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 ( =0D UINT64=0D WriteUnaligned64 (=0D - UINT64 *Buffer,=0D + VOID *Buffer,=0D UINT64 Value=0D );=0D =0D UINT64=0D ReadUnaligned64 (=0D - CONST UINT64 *Buffer=0D + CONST VOID *Buffer=0D );=0D =0D UINTN=0D @@ -363,13 +363,13 @@ AllocatePool ( =0D UINT16=0D WriteUnaligned16 (=0D - UINT16 *Buffer,=0D + VOID *Buffer,=0D UINT16 Value=0D );=0D =0D UINT16=0D ReadUnaligned16 (=0D - CONST UINT16 *Buffer=0D + CONST VOID *Buffer=0D );=0D =0D VOID *=0D --=20 2.31.1