Received: from eggs.gnu.org ([208.118.235.92]:49935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEyuK-0002Xh-2e for qemu-devel@nongnu.org; Mon, 11 Mar 2013 05:20:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UEyuF-0001uR-Ct for qemu-devel@nongnu.org; Mon, 11 Mar 2013 05:20:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEyuF-0001u9-4R for qemu-devel@nongnu.org; Mon, 11 Mar 2013 05:20:31 -0400 From: Stefan Hajnoczi Date: Mon, 11 Mar 2013 10:20:21 +0100 Message-Id: <1362993621-30993-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1362993621-30993-1-git-send-email-stefanha@redhat.com> References: <1362993621-30993-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] exec: assert that RAMBlock size is non-zero List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Stefan Hajnoczi , "Michael S. Tsirkin" find_ram_offset() does not handle size=0 gracefully. It hands out the same RAMBlock offset multiple times, leading to obscure failures later on. Add an assert to warn early if something is incorrectly allocating a zero size RAMBlock. Signed-off-by: Stefan Hajnoczi --- exec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exec.c b/exec.c index 46a2830..a9aa703 100644 --- a/exec.c +++ b/exec.c @@ -912,6 +912,8 @@ static ram_addr_t find_ram_offset(ram_addr_t size) RAMBlock *block, *next_block; ram_addr_t offset = RAM_ADDR_MAX, mingap = RAM_ADDR_MAX; + assert(size != 0); /* it would hand out same offset multiple times */ + if (QTAILQ_EMPTY(&ram_list.blocks)) return 0; -- 1.8.1.4