Re: [PATCH 7/7] hexdump: use xalloc for memory allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 22, 2010 at 12:50:43PM -0300, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <dave@xxxxxxx>
> Date: Fri, 22 Oct 2010 12:29:42 -0300
> Subject: [PATCH 7/7] hexdump: use xalloc for memory allocation. 
> 
> Continue to use xmalloc/memset combos instead of xcalloc because
> malloc is simply faster, although it shouldn't really matter too
> much for a program like this.

 This is nonsense. The calloc() is always better idea than
 malloc+memset. 
 
 All memory from kernel (allocated by anonymous mmap or brk()) is
 always set to zero (for security reasons) -- in this case sane libc
 does not call memset() for this memory.

> -	t = tbl = emalloc(entries * sizeof(TBL));
> -	cols = emalloc((maxcols = DEFCOLS) * sizeof(wchar_t *));
> -	lens = emalloc(maxcols * sizeof(int));
> +	t = xmalloc(entries * sizeof(TBL));
> +	memset(t, 0, entries * sizeof(TBL));
> +	tbl = xmalloc(entries * sizeof(TBL));
> +	memset(tbl, 0, entries * sizeof(TBL));
> +	cols = xmalloc((maxcols = DEFCOLS) * sizeof(wchar_t *));
> +	memset(cols, 0, (maxcols = DEFCOLS) * sizeof(wchar_t *));
> +	lens = xmalloc(maxcols * sizeof(int));
> +	memset(cols, 0, maxcols * sizeof(wchar_t *));


 Please, use xcalloc() here.

    Karel



-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux