From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 456DA211799F1 for ; Thu, 1 Nov 2018 18:32:36 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2018 18:32:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,454,1534834800"; d="scan'208";a="102735425" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga004.fm.intel.com with ESMTP; 01 Nov 2018 18:32:35 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 1 Nov 2018 18:32:34 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 1 Nov 2018 18:32:34 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.117]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.161]) with mapi id 14.03.0415.000; Fri, 2 Nov 2018 09:32:32 +0800 From: "Gao, Liming" To: "Marvin.Haeuser@outlook.com" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" Thread-Topic: [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF(). Thread-Index: AQHUcVWBgAjGoTO9Pki8gs1UPnuKfaU7tOvw Date: Fri, 2 Nov 2018 01:32:32 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3637F5@SHSMSX104.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF(). X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Nov 2018 01:32:36 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable The change is good. Reviewed-by: Liming Gao >-----Original Message----- >From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of >Marvin H?user >Sent: Thursday, November 01, 2018 4:09 AM >To: edk2-devel@lists.01.org >Cc: Kinney, Michael D ; Gao, Liming > >Subject: [edk2] [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via >OFFSET_OF(). > >Replace the current NULL pointer dereference to retrieve Field's >offset with a call to OFFSET_OF(). This is implemented via >__builtin_offsetof for GCC and Clang, which eliminates UB caught by >Clang UndefinedBehaviorSanitizer. > >Contributed-under: TianoCore Contribution Agreement 1.1 >Signed-off-by: Marvin Haeuser >--- > MdePkg/Include/Base.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h >index 523192fd79fc..bc877d8125a5 100644 >--- a/MdePkg/Include/Base.h >+++ b/MdePkg/Include/Base.h >@@ -869,7 +869,7 @@ typedef UINTN *BASE_LIST; > @return A pointer to the structure from one of it's elements. > > **/ >-#define BASE_CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - >(CHAR8 *) &(((TYPE *) 0)->Field))) >+#define BASE_CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - >OFFSET_OF (TYPE, Field))) > > /** > Rounds a value up to the next boundary using a specified alignment. >-- >2.19.1.windows.1 > >_______________________________________________ >edk2-devel mailing list >edk2-devel@lists.01.org >https://lists.01.org/mailman/listinfo/edk2-devel