From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQa7q-0003J1-Bd for qemu-devel@nongnu.org; Thu, 20 Mar 2014 06:23:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQa7h-0007rZ-TN for qemu-devel@nongnu.org; Thu, 20 Mar 2014 06:23:02 -0400 Received: from mail-ee0-x232.google.com ([2a00:1450:4013:c00::232]:51963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQa7h-0007rV-Lq for qemu-devel@nongnu.org; Thu, 20 Mar 2014 06:22:53 -0400 Received: by mail-ee0-f50.google.com with SMTP id c13so474655eek.9 for ; Thu, 20 Mar 2014 03:22:52 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <532AC178.3030002@redhat.com> Date: Thu, 20 Mar 2014 11:22:48 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1394605864-32237-1-git-send-email-famz@redhat.com> <1394605864-32237-6-git-send-email-famz@redhat.com> In-Reply-To: <1394605864-32237-6-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 5/9] hbitmap: Add hbitmap_copy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com 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