* [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF().
[not found] <cover.1541016342.git.Marvin.Haeuser@outlook.com>
@ 2018-10-31 20:08 ` Marvin Häuser
2018-11-02 1:32 ` Gao, Liming
0 siblings, 1 reply; 4+ messages in thread
From: Marvin Häuser @ 2018-10-31 20:08 UTC (permalink / raw)
To: edk2-devel@lists.01.org; +Cc: michael.d.kinney@intel.com, liming.gao@intel.com
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 <Marvin.Haeuser@outlook.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF().
2018-10-31 20:08 ` [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF() Marvin Häuser
@ 2018-11-02 1:32 ` Gao, Liming
2018-11-02 17:28 ` Kinney, Michael D
0 siblings, 1 reply; 4+ messages in thread
From: Gao, Liming @ 2018-11-02 1:32 UTC (permalink / raw)
To: Marvin.Haeuser@outlook.com, edk2-devel@lists.01.org; +Cc: Kinney, Michael D
The change is good. Reviewed-by: Liming Gao <liming.gao@intel.com>
>-----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 <michael.d.kinney@intel.com>; Gao, Liming
><liming.gao@intel.com>
>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 <Marvin.Haeuser@outlook.com>
>---
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF().
2018-11-02 1:32 ` Gao, Liming
@ 2018-11-02 17:28 ` Kinney, Michael D
2018-11-02 17:30 ` Andrew Fish
0 siblings, 1 reply; 4+ messages in thread
From: Kinney, Michael D @ 2018-11-02 17:28 UTC (permalink / raw)
To: Gao, Liming, Marvin.Haeuser@outlook.com, edk2-devel@lists.01.org,
Kinney, Michael D
Marvin,
Thanks. This is a good improvement.
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Mike
> -----Original Message-----
> From: Gao, Liming
> Sent: Thursday, November 1, 2018 6:33 PM
> To: Marvin.Haeuser@outlook.com; edk2-devel@lists.01.org
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>
> Subject: RE: [PATCH 1/1] MdePkg/Base.h: Implement
> BASE_CR() via OFFSET_OF().
>
> The change is good. Reviewed-by: Liming Gao
> <liming.gao@intel.com>
>
> >-----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 <michael.d.kinney@intel.com>;
> Gao, Liming
> ><liming.gao@intel.com>
> >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
> <Marvin.Haeuser@outlook.com>
> >---
> > 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF().
2018-11-02 17:28 ` Kinney, Michael D
@ 2018-11-02 17:30 ` Andrew Fish
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Fish @ 2018-11-02 17:30 UTC (permalink / raw)
To: Mike Kinney
Cc: Gao, Liming, Marvin.Haeuser@outlook.com, edk2-devel@lists.01.org
+1
Reviewed-by: Andrew Fish <afish@apple.com>
> On Nov 2, 2018, at 10:28 AM, Kinney, Michael D <michael.d.kinney@intel.com> wrote:
>
> Marvin,
>
> Thanks. This is a good improvement.
>
> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
>
> Mike
>
>> -----Original Message-----
>> From: Gao, Liming
>> Sent: Thursday, November 1, 2018 6:33 PM
>> To: Marvin.Haeuser@outlook.com; edk2-devel@lists.01.org
>> Cc: Kinney, Michael D <michael.d.kinney@intel.com>
>> Subject: RE: [PATCH 1/1] MdePkg/Base.h: Implement
>> BASE_CR() via OFFSET_OF().
>>
>> The change is good. Reviewed-by: Liming Gao
>> <liming.gao@intel.com>
>>
>>> -----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 <michael.d.kinney@intel.com>;
>> Gao, Liming
>>> <liming.gao@intel.com>
>>> 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
>> <Marvin.Haeuser@outlook.com>
>>> ---
>>> 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
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-11-02 17:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1541016342.git.Marvin.Haeuser@outlook.com>
2018-10-31 20:08 ` [PATCH 1/1] MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF() Marvin Häuser
2018-11-02 1:32 ` Gao, Liming
2018-11-02 17:28 ` Kinney, Michael D
2018-11-02 17:30 ` Andrew Fish
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox