[Libguestfs] [PATCH v2 3/4] common: Add isaligned helper module

Nir Soffer nsoffer at redhat.com
Mon Aug 13 21:07:39 UTC 2018


On Mon, Aug 13, 2018 at 8:54 PM Eric Blake <eblake at redhat.com> wrote:

> On 08/03/2018 02:28 PM, Nir Soffer wrote:
>
...

> > +/* Return true if size is a multiple of align. align must be power of 2.
> > + *
> > + * Suggested by Eric Blake.  See:
> > + * https://www.redhat.com/archives/libguestfs/2018-August/msg00036.html
>
> Do we need this comment in the code? I'm fine if it is just in the
> commit message.
>

I tried to match other code in common/includes, but we can remove it.


>
> > + */
> > +static inline bool
> > +is_aligned (unsigned int size, unsigned int align)
> > +{
> > +  return !(size & (align - 1));
> > +}
>
> Should we assert() that align is indeed a power of 2, to make it harder
> for callers to misuse this function?  Otherwise, looks okay to me.
>

Makes sense to use assert.

Nir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20180814/9aff655a/attachment.htm>


More information about the Libguestfs mailing list