Re: [PATCH 1/3] include: Define FIELD_OFFSET to the standard offsetof macro
On 12/11/2012 10:20 AM, Dmitry Timoshkov wrote: > Michael Stefaniuc wrote: > >> On 12/10/2012 07:37 PM, Amine Khaldi wrote: >>> This prevents the undefined behavior (null pointer dereference) >>> diagnostics (clang with ubsan checks for example). >> This is a bug in clang. There is no null pointer dereference. >> Afair gcc tried to pull this trick too but got educated about their error. > > What's an advantage of these patches except of catering broken compilers/ > checkers? I figure you mean the 2nd try which uses offsetof unconditionally. The advantage is that it replaces the cast orgy with the C89 standard construct thus it easier to read. Appeasing the still wrong clang check is just a side effect. bye michael
Re: [PATCH 1/3] include: Define FIELD_OFFSET to the standard offsetof macro
Michael Stefaniuc wrote: > On 12/10/2012 07:37 PM, Amine Khaldi wrote: > > This prevents the undefined behavior (null pointer dereference) > > diagnostics (clang with ubsan checks for example). > This is a bug in clang. There is no null pointer dereference. > Afair gcc tried to pull this trick too but got educated about their error. What's an advantage of these patches except of catering broken compilers/ checkers? -- Dmitry.
Re: [PATCH 1/3] include: Define FIELD_OFFSET to the standard offsetof macro
On 12/10/2012 07:37 PM, Amine Khaldi wrote: > This prevents the undefined behavior (null pointer dereference) > diagnostics (clang with ubsan checks for example). This is a bug in clang. There is no null pointer dereference. Afair gcc tried to pull this trick too but got educated about their error. > > --- > include/winnt.h | 4 > 1 file changed, 4 insertions(+) > > diff --git a/include/winnt.h b/include/winnt.h > index 207adaa..a3b996a 100644 > --- a/include/winnt.h > +++ b/include/winnt.h > @@ -746,8 +746,12 @@ typedef struct _MEMORY_BASIC_INFORMATION > > #define UNICODE_STRING_MAX_CHARS 32767 > > +#if defined(__GNUC__) || defined(__clang__) > +#define FIELD_OFFSET(type, field) offsetof(type, field) > +#else > #define FIELD_OFFSET(type, field) \ >((LONG)(INT_PTR)&(((type *)0)->field)) > +#endif > > #define CONTAINING_RECORD(address, type, field) \ >((type *)((PCHAR)(address) - (PCHAR)(&((type *)0)->field))) bye michael