Re: Performing pointer arithmetic on a null pointer?

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

 



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@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]

  Powered by Linux