From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH v5 23/24] xl: introduce xcalloc Date: Fri, 13 Feb 2015 10:25:10 +0000 Message-ID: <20150213102510.GK13644@zion.uk.xensource.com> References: <1423770294-9779-1-git-send-email-wei.liu2@citrix.com> <1423770294-9779-24-git-send-email-wei.liu2@citrix.com> <54DD0A66.3070703@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <54DD0A66.3070703@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Wei Liu , ian.campbell@citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, JBeulich@suse.com, ufimtseva@gmail.com List-Id: xen-devel@lists.xenproject.org On Thu, Feb 12, 2015 at 08:17:42PM +0000, Andrew Cooper wrote: > On 12/02/15 19:44, Wei Liu wrote: > > Signed-off-by: Wei Liu > > Cc: Ian Campbell > > Cc: Ian Jackson > > --- > > tools/libxl/xl_cmdimpl.c | 12 ++++++++++++ > > 1 file changed, 12 insertions(+) > > > > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c > > index 440db78..ec7fb2d 100644 > > --- a/tools/libxl/xl_cmdimpl.c > > +++ b/tools/libxl/xl_cmdimpl.c > > @@ -289,6 +289,18 @@ static void *xmalloc(size_t sz) { > > return r; > > } > > > > +static void *xcalloc(size_t n, size_t sz) __attribute__((unused)); > > +static void *xcalloc(size_t n, size_t sz) { > > + void *r; > > + r = calloc(n, sz); > > These two lines can be joined, espcially in a small wrapper like this. > > > + if (!r) { > > + fprintf(stderr,"xl: Unable to calloc %lu bytes.\n", > > + (unsigned long)sz * (unsigned long)n); > > %zu is the correct format identifier for a size_t, and it will allow you > to drop the casts. > Both issues fixed. Thanks for reviewing. Wei. > ~Andrew > > > + exit(-ERROR_FAIL); > > + } > > + return r; > > +} > > + > > static void *xrealloc(void *ptr, size_t sz) { > > void *r; > > if (!sz) { free(ptr); return 0; }