public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] xfs: Silence bounds checking compiler warning
@ 2011-06-23 16:55 Maarten Lankhorst
  0 siblings, 0 replies; 5+ messages in thread
From: Maarten Lankhorst @ 2011-06-23 16:55 UTC (permalink / raw)
  To: Alex Elder; +Cc: xfs-masters, xfs, Linux Kernel Mailing List

gcc with -Warray-bounds generates a false positive on this
since xfs defines the struct with u8 name[1]; to be able to
add a tag at the end.

Signed-off-by: Maarten Lankhorst <m.b.lankhorst@gmail.com>
---
 fs/xfs/xfs_dir2_block.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/xfs/xfs_dir2_block.c b/fs/xfs/xfs_dir2_block.c
index 580d99c..2c5f287 100644
--- a/fs/xfs/xfs_dir2_block.c
+++ b/fs/xfs/xfs_dir2_block.c
@@ -1148,7 +1148,7 @@ xfs_dir2_sf_to_block(
 		((char *)block + XFS_DIR2_DATA_DOTDOT_OFFSET);
 	dep->inumber = cpu_to_be64(xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent));
 	dep->namelen = 2;
-	dep->name[0] = dep->name[1] = '.';
+	memset(dep->name, '.', 2);
 	tagp = xfs_dir2_data_entry_tag_p(dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)block);
 	xfs_dir2_data_log_entry(tp, bp, dep);
-- 
1.7.5.4

v2: memset looks like the cleanest solution, other options rely on ugly casts


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] xfs: Silence bounds checking compiler warning
       [not found] <4E037001.8090306__42924.0493024283$1308849791$gmane$org@gmail.com>
@ 2011-06-23 17:27 ` Andi Kleen
  2011-06-23 17:55   ` Al Viro
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2011-06-23 17:27 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: Alex Elder, xfs-masters, Linux Kernel Mailing List, xfs

Maarten Lankhorst <m.b.lankhorst@gmail.com> writes:

> gcc with -Warray-bounds generates a false positive on this
> since xfs defines the struct with u8 name[1]; to be able to
> add a tag at the end.

A better way would be to define it as name[0]. Then the compiler
would know it's a VLA. You may need to check noone relies on
the one byte though.

-Andi
-- 
ak@linux.intel.com -- Speaking for myself only

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] xfs: Silence bounds checking compiler warning
  2011-06-23 17:27 ` [PATCH v2] xfs: Silence bounds checking compiler warning Andi Kleen
@ 2011-06-23 17:55   ` Al Viro
  2011-06-23 18:13     ` Christoph Hellwig
  2011-06-24  2:15     ` Dave Chinner
  0 siblings, 2 replies; 5+ messages in thread
From: Al Viro @ 2011-06-23 17:55 UTC (permalink / raw)
  To: Andi Kleen
  Cc: Maarten Lankhorst, Alex Elder, xfs-masters,
	Linux Kernel Mailing List, xfs

On Thu, Jun 23, 2011 at 10:27:26AM -0700, Andi Kleen wrote:
> Maarten Lankhorst <m.b.lankhorst@gmail.com> writes:
> 
> > gcc with -Warray-bounds generates a false positive on this
> > since xfs defines the struct with u8 name[1]; to be able to
> > add a tag at the end.
> 
> A better way would be to define it as name[0]. Then the compiler
> would know it's a VLA. You may need to check noone relies on
> the one byte though.

... and even better is to write in real C and have u8 name[]; in the
end of your structure.  That's the standard C99 for this kind of thing
(see 6.7.2.1p2, p16).  Zero-sized array is a gccism predating standard
flexible array members and since the standard syntax is accepted by
any gcc version that might be recent enough to build the kernel...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] xfs: Silence bounds checking compiler warning
  2011-06-23 17:55   ` Al Viro
@ 2011-06-23 18:13     ` Christoph Hellwig
  2011-06-24  2:15     ` Dave Chinner
  1 sibling, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2011-06-23 18:13 UTC (permalink / raw)
  To: Al Viro
  Cc: Andi Kleen, Maarten Lankhorst, Alex Elder, xfs-masters,
	Linux Kernel Mailing List, xfs

On Thu, Jun 23, 2011 at 06:55:33PM +0100, Al Viro wrote:
> ... and even better is to write in real C and have u8 name[]; in the
> end of your structure.  That's the standard C99 for this kind of thing
> (see 6.7.2.1p2, p16).  Zero-sized array is a gccism predating standard
> flexible array members and since the standard syntax is accepted by
> any gcc version that might be recent enough to build the kernel...

The situation is even more nasty - the one sized fake flex-array
actually is in the middle of the structure.  Besides sizeof-expressions
taking the one member array into account only members before the
variable sized array are used.  I've started a series cleaning up the
few structures that were done that way (for whatever reason), but it's
pretty intrusive.  I don't think papering over these warnings at this
point is a good idea.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] xfs: Silence bounds checking compiler warning
  2011-06-23 17:55   ` Al Viro
  2011-06-23 18:13     ` Christoph Hellwig
@ 2011-06-24  2:15     ` Dave Chinner
  1 sibling, 0 replies; 5+ messages in thread
From: Dave Chinner @ 2011-06-24  2:15 UTC (permalink / raw)
  To: Al Viro
  Cc: Andi Kleen, Maarten Lankhorst, Alex Elder, xfs-masters,
	Linux Kernel Mailing List, xfs

On Thu, Jun 23, 2011 at 06:55:33PM +0100, Al Viro wrote:
> On Thu, Jun 23, 2011 at 10:27:26AM -0700, Andi Kleen wrote:
> > Maarten Lankhorst <m.b.lankhorst@gmail.com> writes:
> > 
> > > gcc with -Warray-bounds generates a false positive on this
> > > since xfs defines the struct with u8 name[1]; to be able to
> > > add a tag at the end.
> > 
> > A better way would be to define it as name[0]. Then the compiler
> > would know it's a VLA. You may need to check noone relies on
> > the one byte though.
> 
> ... and even better is to write in real C and have u8 name[]; in the
> end of your structure.

Hard to do when the structure is effectively the definition of the
on-disk format. Hence it can't just be changed around and the kernel
recompiled to fix the problem.

> That's the standard C99 for this kind of thing
> (see 6.7.2.1p2, p16).  Zero-sized array is a gccism predating standard
> flexible array members and since the standard syntax is accepted by
> any gcc version that might be recent enough to build the kernel...

This code came from Irix, which means it predates both the gccism
and the C99 standard methods of using flexible array sizes. The code
works so it's never been modified because stuffing about with
structures that define disk formats is not done just for the hell of
it... ;)

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-06-24  2:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <4E037001.8090306__42924.0493024283$1308849791$gmane$org@gmail.com>
2011-06-23 17:27 ` [PATCH v2] xfs: Silence bounds checking compiler warning Andi Kleen
2011-06-23 17:55   ` Al Viro
2011-06-23 18:13     ` Christoph Hellwig
2011-06-24  2:15     ` Dave Chinner
2011-06-23 16:55 Maarten Lankhorst

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox