
On 05/20/2010 02:45 PM, Jim Fehlig wrote:
+virBitmapPtr virBitmapAlloc(size_t size) +{ + virBitmapPtr bitmap; + size_t sz = (size + VIR_BITMAP_BITS_PER_UNIT - 1) / + VIR_BITMAP_BITS_PER_UNIT;
Check for overflow: if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size) return NULL;
+ + if (VIR_ALLOC_N(bitmap, sizeof(virBitmap)) < 0)
Use VIR_ALLOC(bitmap) - you want to allocate one bitmap object, not an array of bitmaps of length 'sizeof(virBitmap)'. But VIR_ALLOC_N is correct for bitmap->map.
+ +/** + * virBitmapSetBit: + * @bitmap: Pointer to bitmap + * @b: bit position to set + * + * Set bit position @b in @bitmap + * + * Returns 0 on if bit is successfully set, -1 on error. + */ +int virBitmapSetBit(virBitmapPtr bitmap, unsigned int b)
size_t, not unsigned int, to avoid type mismatch when comparing against _virBitmap.size.
+ +/* + * Set bit position @b in @bitmap + */ +int virBitmapSetBit(virBitmapPtr bitmap, unsigned int b);
Add ATTRIBUTE_NONNULL(1) here, and on all subsequent prototypes that take virBitmapPtr, and you can get rid of the bitmap==NULL check in the implementations (but keep the virBitmapFree semantics of allowing NULL, as it simplifies cleanup paths). s/unsigned int/size_t/.
+ +/* + * Clear bit position @b in @bitmap + */ +int virBitmapClearBit(virBitmapPtr bitmap, unsigned int b);
s/unsigned int/size_t/
+ +/* + * Get setting of bit position @b in @bitmap and store in @result + */ +int virBitmapGetBit(virBitmapPtr bitmap, unsigned int b, bool *result);
s/unsigned int/size_t/. ATTRIBUTE_NONNULL(3) as well. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org