Re: Pointer subtraction with a null pointer

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: Pointer subtraction with a null pointer
Дата
Msg-id 20220603160117.baernme3kuezkyn7@alap3.anarazel.de
обсуждение исходный текст
Ответ на Re: Pointer subtraction with a null pointer  (Andres Freund <andres@anarazel.de>)
Список pgsql-hackers
On 2022-03-26 11:08:59 -0700, Andres Freund wrote:
> On 2022-03-26 10:49:53 -0700, Andres Freund wrote:
> > > It's hard to see how that isn't a flat-out compiler bug.
> >
> > It only happens if the NULL is directly passed as an argument to the macro,
> > not if there's an intermediary variable. Argh.
> >
> >
> > #include <stddef.h>
> >
> > #define relptr_store(base, rp, val) \
> >      ((rp).relptr_off = ((val) == NULL ? 0 : ((char *) (val)) - (base)))
> >
> > typedef union { struct foo *relptr_type; size_t relptr_off; } relptr;
> >
> > void
> > problem_not_present(relptr *rp, char *base)
> > {
> >     struct foo *val = NULL;
> >
> >     relptr_store(base, *rp, val);
> > }
> >
> > void
> > problem_present(relptr *rp, char *base)
> > {
> >     relptr_store(base, *rp, NULL);
> > }
> >
> >
> > Looks like that warning is uttered whenever there's a subtraction from a
> > pointer with NULL, even if the code isn't reachable. Which I guess makes
> > *some* sense, outside of macros it's not something that'd ever be reasonable.
>
> Reported as https://github.com/llvm/llvm-project/issues/54570

And it now got fixed. Will obviously be a bit till it reaches a compiler near
you...



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [PATCH] fix doc example of bit-reversed MAC address
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Collation version tracking for macOS