public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Metcalf <cmetcalf@tilera.com>
To: linux-kernel@vger.kernel.org
Subject: PROBLEM: compiler warning from cryptic pointer math
Date: Fri, 23 Jun 2006 15:43:40 -0400	[thread overview]
Message-ID: <449C446C.3020605@tilera.com> (raw)

(Using the format from REPORTING-BUGS...)

[1.] compiler warning from cryptic pointer math

[2.] This change simplifies a cryptic macro in fs/readdir.c.  Rather
than subtracting an uninitialized pointer's d_name field address from
the uninitialized pointer base to get the field offset, we just use the
normal "offsetof" idiom to directly get the d_name field address from a
pointer to zero.  We can't use offsetof directly since the variable type
we have handy is a pointer, not the structure type itself.

(Our compiler is a gcc-alike that can figure out that it doesn't need to 
warn about things like "foo - foo" for an uninitialized pointer foo, but 
the field reference makes it think the pointer is truly being used; the 
warning made me look more closely at this piece of code.)

[4.] The kernel version is 2.6.17.1.

[X.]

--- /tmp/tmp.3955.0     2006-06-23 10:10:54.000000000 -0400
+++ /u/cmetcalf/linux/fs/readdir.c  2006-06-23 10:09:07.000000000 -0400
@@ -51,7 +51,7 @@
  * anyway. Thus the special "fillonedir()" function for that
  * case (the low-level handlers don't need to care about this).
  */
-#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
+#define NAME_OFFSET(de) ((int) ((typeof(de))0)->d_name)
#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))

#ifdef __ARCH_WANT_OLD_READDIR

-- 
Chris Metcalf, Tilera Corp.
http://www.tilera.com



                 reply	other threads:[~2006-06-23 19:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=449C446C.3020605@tilera.com \
    --to=cmetcalf@tilera.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