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.29417.1628543006071020729 for ; Mon, 09 Aug 2021 14:03:27 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@posteo.de header.s=2017 header.b=E/YNtkYS; 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 2E23024002B for ; Mon, 9 Aug 2021 23:03:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1628543003; bh=bVQj1ncseme9TT1QE76wq3/bxqvrlI5o6N1DuU1lbGk=; h=From:To:Cc:Subject:Date:From; b=E/YNtkYSnimE6EDwiiFSnLzk3SjvUqxn3GnhnUVyOtx/3wC3f7W8o8LmfRw/8eLnC 7cggENIfqVyMl8xtnAgqKqgIvvX3QWTAR3sd5Y2f8Dppn22E5AVu60QWNUVLuE9Z1G Jb8FsJn3xp2UJSGZTrKoEYXjc9V4l9a6rjQ+9zFxwEc7Kpy3Xqbcqj30yLLQs0VcvT c40+n75WFmQrDuwFisS+n1PHGhJcSA7H56I3bzLQcjOKbcoZIxYVCvs1yBfNIHTV4W U9ACN09Bs2gx4/51evj6MaJoFJBqYGvemQ46EROrOcnYwSQRedVaREa/+AU+Y5KdZz 2JBuEOPIfYI5g== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Gk7pf4jHGz6tmF; Mon, 9 Aug 2021 23:03:22 +0200 (CEST) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao , Yuwei Chen , Vitaly Cheptsov Subject: [PATCH v3 2/2] BaseTools/CommonLib: Fix unaligned API prototypes Date: Mon, 9 Aug 2021 21:02:36 +0000 Message-Id: In-Reply-To: <0b11ac52ace7b6fd5c676c2d51214f52be740496.1628542707.git.mhaeuser@posteo.de> References: <0b11ac52ace7b6fd5c676c2d51214f52be740496.1628542707.git.mhaeuser@posteo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3542 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