Re: memset as memzero

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>
Cc: Arnaldo Carvalho de Melo <acme@...>, Dave Jones <davej@...>, Arjan van de Ven <arjan@...>, Cyrill Gorcunov <gorcunov@...>, LKML <linux-kernel@...>, Andrew Morton <akpm@...>, Ingo Molnar <mingo@...>
Date: Sunday, September 23, 2007 - 2:46 pm

On Sun, Sep 23, 2007 at 10:05:05AM -0700, Linus Torvalds wrote:

I don't like it when macros magically do sizeof(*p), because people often
think that the macro is smarter than it really is, and you commonly end
up with code looking like this :

     char *p;
     ...
     p = kmalloc(n);
     ...
     memclear(p);

This can happen for instance when replacing a stack-allocated buffer
with a malloc because it became too big for the stack. Such a mistake
is *very hard* to detect by human eye, while having "sizeof(*p)" in
the same function as "char *p" will trigger some automatisms in most
readers' brains.


At least current code is still greppable for such usages. Doing too
much magics with macros often harms debugging. I could agree with
having a macro to force the pattern to '0', but not to force the size.


I don't think either.

Willy

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
memset as memzero, Cyrill Gorcunov, (Sat Sep 22, 4:33 am)
Re: memset as memzero, Arjan van de Ven, (Sat Sep 22, 3:46 pm)
Re: memset as memzero, Cyrill Gorcunov, (Sat Sep 22, 3:32 pm)
Re: memset as memzero, Bernd Eckenfels, (Sat Sep 22, 3:25 pm)
Re: memset as memzero, Linus Torvalds, (Sat Sep 22, 2:53 pm)
Re: memset as memzero, Dave Jones, (Sun Sep 23, 11:32 am)
Re: memset as memzero, Robert P. J. Day, (Sun Sep 23, 12:33 pm)
Re: memset as memzero, Arnaldo Carvalho de Melo, (Sun Sep 23, 12:46 pm)
Re: memset as memzero, Arnaldo Carvalho de Melo, (Sun Sep 23, 12:07 pm)
Re: memset as memzero, Linus Torvalds, (Sun Sep 23, 1:05 pm)
Re: memset as memzero, Willy Tarreau, (Sun Sep 23, 2:46 pm)
Re: memset as memzero, Robert P. J. Day, (Sat Sep 22, 4:48 am)
Re: memset as memzero, Cyrill Gorcunov, (Sat Sep 22, 5:35 am)
Re: memset as memzero, Robert P. J. Day, (Sat Sep 22, 5:55 am)
Re: memset as memzero, Cyrill Gorcunov, (Sat Sep 22, 6:15 am)