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

Re: [Xen-devel] [PATCH 24/29] libxl: Introduce FILLZERO



Ian Campbell writes ("Re: [Xen-devel] [PATCH 24/29] libxl: Introduce FILLZERO"):
> On Tue, 2015-02-10 at 20:10 +0000, Ian Jackson wrote:
> > FILLZERO is a macro for memset(&foo,0,sizeof(foo)).  It eliminates the
> > possiblity to make the error memset(&foo,0,sizeof(&foo)).
> 
> but not:
>         foo *p = allocate_a_foo()
>      memset(p, 0, sizeof(p))
> although that's probably less likely to go wrong and I don't think it
> can be avoided by the sorts of tricks used here.

Well, we could make a macro that you _have_ to pass the pointer to.
The result is that passing a non-pointer object gets you an error.

> > No callers yet, but document it in CODING_STYLE.  (In accordance with
> > existing libxl policy, I haven't gone through all existing possible
> > call sites.)
> 
> We don't usually expose such helpers in the public API, but I suppose
> you have a good reason to do so here, could you mention it in the commit
> log please.

It should be in the public API because xl*.c is full of uses of memset
which ought to be replaced with FILLZERO.  Do you really think I need
to mention this in the commit message ?

> > +#define LIBXL_FILLZERO(object) (memset(&(object), 0, sizeof((object))))
> 
> Evaluates object twice, so LIBXL_FILEZERO(*(p++)), would behave
> surprisingly. I'm not sure if this can be resolved though, so this might
> be a Don't Do That Then situation.

sizeof() does not evaluate its argument.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.