All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: Performing pointer arithmetic on a null pointer?
Date: Thu, 27 May 2021 17:32:11 +0200	[thread overview]
Message-ID: <YK+7e3l/pBEViMht@kroah.com> (raw)
In-Reply-To: <20210527151443.GA138263@hyeyoo>

On Fri, May 28, 2021 at 12:14:43AM +0900, Hyeonggon Yoo wrote:
> Hello, I was compiling kernel with make CC=clang-10 W=1 -s
> 
> there are some places that compiler complains about
> pointer arithmetic like below.it says it's undefined behavior.
> 
> is it just OK to use UBs like this (I hope it's not),
> or am I missing something?
> 
> fs/kernfs/file.c:128:15: warning: performing pointer arithmetic on
> 	a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
>                 return NULL + !*ppos;

Should work just fine, what problems have you found with that code?

Also happens in a few other places in the vfs layer.  Tricky code, but
it works as pointer math is valid C code :)

thanks,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  parent reply	other threads:[~2021-05-27 15:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27 15:14 Performing pointer arithmetic on a null pointer? Hyeonggon Yoo
2021-05-27 15:27 ` Lukas Bulwahn
2021-05-27 15:56   ` Hyeonggon Yoo
2021-05-27 15:32 ` Greg KH [this message]
2021-05-27 15:49   ` Hyeonggon Yoo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YK+7e3l/pBEViMht@kroah.com \
    --to=greg@kroah.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.