Re: [patch] ext2_fill_super breakage

Brian Gerst
2002-03-28T13:36:09Z

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); }

yields:

00000b70 <foo1>:
b70: b8 dc 00 00 00 mov $0xdc,%eax
b75: c3 ret

00000b80 <foo2>:
b80: b8 dc 00 00 00 mov $0xdc,%eax
b85: c3 ret

The sizes are the same, so unless it makes a difference with another
version of gcc then this is just a cosmetic change.

--

Brian Gerst