All of lore.kernel.org
 help / color / mirror / Atom feed
* PROBLEM: compiler warning from cryptic pointer math
@ 2006-06-23 19:43 Chris Metcalf
  0 siblings, 0 replies; only message in thread
From: Chris Metcalf @ 2006-06-23 19:43 UTC (permalink / raw)
  To: linux-kernel

(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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-06-23 19:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-23 19:43 PROBLEM: compiler warning from cryptic pointer math Chris Metcalf

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.