|
From: | Paolo Bonzini |
Subject: | Re: [Qemu-devel] [PATCH v2 5/9] hbitmap: Add hbitmap_copy |
Date: | Thu, 20 Mar 2014 11:22:48 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
Il 12/03/2014 07:31, Fam Zheng ha scritto:
+HBitmap *hbitmap_copy(const HBitmap *bitmap) +{ + int i; + HBitmap *hb = g_memdup(bitmap, sizeof(struct HBitmap)); + + for (i = HBITMAP_LEVELS; i-- > 0; ) { + hb->levels[i] = g_memdup(bitmap->levels[i], + bitmap->size * sizeof(unsigned long)); + } + + return hb;
Not quite... the bitmap->size is in bits, so you need to scale it down by size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1); before each memdup. Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |