Re: [patch] ext2_fill_super breakage

Jos Hulzink
2002-03-28T13:50:32Z

On Thu, 28 Mar 2002, Brian Gerst wrote:

> Andrew Morton wrote:
> > 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'm not sure I follow you here. Compiling this code (gcc 2.96):
....

It is not about what comes out of the compiler, it is about the fact that
in the second case, when some_type becomes another_type, you have to
replace some_type at 3 locations, easy to forget one. In the first case,
your compiler checks what the size of your variable is, the memset will
never fill beyond the end of your allocated memory.

It is about preventing patching again and again for someone forgot to use
:s/something/anotherthing/g. Besides, the code looks much better imho.

Jos