Re: [cocci] Reconsidering pointer dereferences before null pointer checks (with SmPL)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 11, 2023 at 09:40:23AM +0200, Julia Lawall wrote:
> 
> 
> On Tue, 11 Apr 2023, Markus Elfring wrote:
> 
> > >>>> https://stackoverflow.com/questions/25725286/does-taking-address-of-member-variable-through-a-null-pointer-yield-undefined-be
> > >>>> https://en.cppreference.com/w/c/language/behavior
> > >>>
> > >>> The statement:
> > >>>
> > >>> "... &((*ptr).second) which dereferences an object instance pointer"
> > >>>
> > >>> is not correct.  &((*ptr).second) does not dereference *ptr any more than
> > >>> &x deferences x.  The semantics of & doesn't work like that.
> > >>
> > >> Does the usage of the operator “member access through pointer” (arrow) mean also
> > >> a dereference in comparison to the asterisk operator in the C programming language?
> > >
> > > Not when there is a & in front.  you can just look at the generated
> > > assembly code to see that.  The goal of & is to take the address of
> > > something, not to evaluate the thing.
> >
> > Would you like to take another look at recent responses by David Svoboda?
> > https://wiki.sei.cmu.edu/confluence/display/c/EXP34-C.+Do+not+dereference+null+pointers?focusedCommentId=405504153#comment-405504153
> 
> His previous comment says that the standard doesn't mention &a->b so it is
> a problem.  He is surely more of an expert on the C standard than I am.

In the linux-kernel we do a lot of things that are not in the C
standard.  The linux-kernel is written with specific versions of GCC
and Clang in mind.  It's not expected that other compilers will be able
to compile the kernel.

So &a->b is just fine in the linux kernel.

regards,
dan carpenter



[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux