From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLH4m-0007bn-Sx for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:20:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLH4l-0000tb-Q4 for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:20:36 -0400 Received: from mail-qy0-f180.google.com ([209.85.216.180]:41878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLH4l-0000t8-LH for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:20:35 -0400 Received: by qyl38 with SMTP id 38so830601qyl.4 for ; Tue, 01 Nov 2011 09:20:34 -0700 (PDT) Message-ID: <4EB01C4E.6020008@codemonkey.ws> Date: Tue, 01 Nov 2011 11:20:30 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <20111031145311.13723.63607.stgit@s20.home> In-Reply-To: <20111031145311.13723.63607.stgit@s20.home> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] Error check find_ram_offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: qemu-devel@nongnu.org, armbru@redhat.com On 10/31/2011 09:54 AM, Alex Williamson wrote: > Spotted via code review, we initialize offset to 0 to avoid a > compiler warning, but in the unlikely case that offset is > never set to something else, we should abort instead of return > a value that will almost certainly cause problems. > > Signed-off-by: Alex Williamson Applied. Thanks. Regards, Anthony Liguori > --- > > exec.c | 11 +++++++++-- > 1 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/exec.c b/exec.c > index 9dc4edb..70f6fb8 100644 > --- a/exec.c > +++ b/exec.c > @@ -2874,7 +2874,7 @@ static void *file_ram_alloc(RAMBlock *block, > static ram_addr_t find_ram_offset(ram_addr_t size) > { > RAMBlock *block, *next_block; > - ram_addr_t offset = 0, mingap = RAM_ADDR_MAX; > + ram_addr_t offset = RAM_ADDR_MAX, mingap = RAM_ADDR_MAX; > > if (QLIST_EMPTY(&ram_list.blocks)) > return 0; > @@ -2890,10 +2890,17 @@ static ram_addr_t find_ram_offset(ram_addr_t size) > } > } > if (next - end>= size&& next - end< mingap) { > - offset = end; > + offset = end; > mingap = next - end; > } > } > + > + if (offset == RAM_ADDR_MAX) { > + fprintf(stderr, "Failed to find gap of requested size: %" PRIu64 "\n", > + (uint64_t)size); > + abort(); > + } > + > return offset; > } > > > >