From: Ian Jackson Subject: Re: [PATCH] libxl: correct allocation size in libxl_list_vm Date: Wed, 28 Sep 2011 16:34:55 +0100 Message-ID: <20099.16031.124516.403982@mariner.uk.xensource.com> References: <4a6d34dffcf9d568a783.1316613329@cosworth.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4a6d34dffcf9d568a783.1316613329@cosworth.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Campbell Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("[Xen-devel] [PATCH] libxl: correct allocation size in libxl_list_vm"): > libxl: correct allocation size in libxl_list_vm Acked-by: Ian Jackson Committed-by: Ian Jackson > *ptr has type libxl_vminfo not libxl_domid, so correct calloc call. > > This the second instance of this bug I've noticed recently, I did a > quick audit of other similar uses of sizeof(...) and all I spotted > were a couple of harmlessly reversed calloc arguments. It's a pretty > strong argument for "foo = ..alloc(sizeof(*foo))" rather than > "alloc(sizeof(foos_type))" though... The correct approach to this is to make a macro along these lines: #define OUR_CALLOC(foo) ((foo)=calloc(sizeof(*(foo)))) I think we may have some of these but we should have a complete set. Ian.