Re: [patch] ext2_fill_super breakage

From: Jos Hulzink (josh@stack.nl)
Date: Thu Mar 28 2002 - 08:50:17 EST


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

-
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/



This archive was generated by hypermail 2b29 : Sun Mar 31 2002 - 22:00:16 EST