lkml.org 
[lkml]   [2002]   [Mar]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] ext2_fill_super breakage
Andrew Morton wrote:
>
> Brian Gerst wrote:
> >
> > Andrew Morton wrote:
> > > In 2.5.7 there is a thinko in the allocation and initialisation
> > > of the fs-private superblock for ext2. It's passing the wrong type
> > > to the sizeof operator (which of course gives the wrong size)
> > > when allocating and clearing the memory.
> > >
> > > Lesson for the day: this is one of the reasons why this idiom:
> > >
> > > some_type *p;
> > >
> > > p = malloc(sizeof(*p));
> > > ...
> > > memset(p, 0, sizeof(*p));
> > >
> > > is preferable to
> > >
> > > some_type *p;
> > >
> > > p = malloc(sizeof(some_type));
> > > ...
> > > memset(p, 0, sizeof(some_type));
> > >
> > > I checked the other filesystems. They're OK (but idiomatically
> > > impure). I've added a couple of defensive memsets where
> > > they were missing.
> >
> > I'm not sure I follow you here. Compiling this code (gcc 2.96):
> >
> > int foo1(void) { return sizeof(struct ext2_sb_info); }
> > int foo2(struct ext2_sb_info *sbi) { return sizeof(*sbi); }
>
> The current code is using sizeof(ext2_super_block) for
> something which is of type ext2_sb_info.
>
> The stylistic change tends to provide insulation from the
> above bug.

Doh. Point taken.

--

Brian Gerst
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:25    [W:0.065 / U:5.392 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site