From: Arnaldo Carvalho de Melo <acme@redhat.com>
To: "J.A. Magallón" <jamagallon@ono.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: void* arithmnetic
Date: Wed, 28 Nov 2007 22:22:47 -0200 [thread overview]
Message-ID: <20071129002247.GA12069@ghostprotocols.net> (raw)
In-Reply-To: <20071129010531.22b3a71f@werewolf>
Em Thu, Nov 29, 2007 at 01:05:31AM +0100, J.A. Magallón escreveu:
> Hi all...
>
> Since begin of the ages the build of the nvidia driver says things like
> this:
>
> include/asm/compat.h:210: warning: pointer of type 'void *' used in arithmetic
>
> There are several of this warnings. The code in question for this example
> is:
>
> static __inline__ void __user *compat_alloc_user_space(long len)
> {
> struct pt_regs *regs = task_pt_regs(current);
> return (void __user *)regs->rsp - len;
> }
>
> As this is dealing with mem blocks, I suppose it's counting in bytes, so
> we could do something like:
>
> return (void __user *)((u8*)regs->rsp - len);
>
> so the arithmetic knows how to inc/dec for each unity...
> I think the warning is correct and that void* arithmetic is undefined in C,
> isn't it ?
Yes, but not in gcc, the language the kernel is written 8)
It is allowed and the size of a void is 1. -Wpointer-arith disables
this.
[acme@doppio ~]$ cat voidptr.c
#include <stdio.h>
int main(int argc, char *argv[])
{
void *ptr = argv[argc - 1];
puts(ptr + 4);
return 0;
}
[acme@doppio ~]$ gcc -Wall voidptr.c -o voidptr
[acme@doppio ~]$ ./a Magallón
llón
[acme@doppio ~]$ gcc -Wall -Wpointer-arith voidptr.c -o voidptr
voidptr.c: In function ‘main’:
voidptr.c:7: warning: pointer of type ‘void *’ used in arithmetic
[acme@doppio ~]$ ./a Magallón
llón
[acme@doppio ~]$
- Arnaldo
next prev parent reply other threads:[~2007-11-29 0:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-29 0:05 void* arithmnetic J.A. Magallón
2007-11-29 0:22 ` Arnaldo Carvalho de Melo [this message]
2007-11-29 0:39 ` Jan Engelhardt
2007-11-29 1:19 ` Ming Lei
2007-11-29 7:38 ` Benny Halevy
2007-11-29 12:31 ` WANG Cong
2007-11-30 11:38 ` Geert Uytterhoeven
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=20071129002247.GA12069@ghostprotocols.net \
--to=acme@redhat.com \
--cc=jamagallon@ono.com \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox