From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqLkI-0006j8-Vk for qemu-devel@nongnu.org; Mon, 17 Nov 2014 07:49:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqLkC-0006pr-Ql for qemu-devel@nongnu.org; Mon, 17 Nov 2014 07:49:30 -0500 Received: from relay.parallels.com ([195.214.232.42]:48520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqLkC-0006hd-J7 for qemu-devel@nongnu.org; Mon, 17 Nov 2014 07:49:24 -0500 Message-ID: <5469EE9E.9030908@parallels.com> Date: Mon, 17 Nov 2014 15:48:30 +0300 From: Vladimir Sementsov-Ogievskiy MIME-Version: 1.0 References: 1414639364-4499-5-git-send-email-famz@redhat.com Content-Type: multipart/alternative; boundary="------------020909010202090103040509" Subject: Re: [Qemu-devel] [PATCH v6 04/10] hbitmap: Add hbitmap_copy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: famz@redhat.com Cc: Kevin Wolf , Benoit Canet , John Snow , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , Stefan Hajnoczi , Jd , Paolo Bonzini , Luiz Capitulino --------------020909010202090103040509 Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit > + > +HBitmap *hbitmap_copy(const HBitmap *bitmap) > +{ > + int i; > + int64_t size; > + HBitmap *hb = g_memdup(bitmap, sizeof(struct HBitmap)); > + > + size = bitmap->size; > + for (i = HBITMAP_LEVELS; i-- > 0; ) { > + size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1); > + hb->levels[i] = g_memdup(bitmap->levels[i], > + size * sizeof(unsigned long)); > + } > + > + return hb; > +} "(size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL" - will be zero iff size == 0. Is it really possible in qemu? If not, we doesn't need MAX(..., 1). There is similar construction in older "hbitmap_alloc" function. -- Best regards, Vladimir --------------020909010202090103040509 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: 7bit
+
+HBitmap *hbitmap_copy(const HBitmap *bitmap)
+{
+    int i;
+    int64_t size;
+    HBitmap *hb = g_memdup(bitmap, sizeof(struct HBitmap));
+
+    size = bitmap->size;
+    for (i = HBITMAP_LEVELS; i-- > 0; ) {
+        size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
+        hb->levels[i] = g_memdup(bitmap->levels[i],
+                                 size * sizeof(unsigned long));
+    }
+
+    return hb;
+}

"(size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL" - will be zero iff size == 0. Is it really possible in qemu? If not, we doesn't need MAX(..., 1).
There is similar construction in older "hbitmap_alloc" function.
-- 
Best regards,
Vladimir
--------------020909010202090103040509--