]> git.proxmox.com Git - qemu.git/commitdiff
Error check find_ram_offset
authorAlex Williamson <alex.williamson@redhat.com>
Mon, 31 Oct 2011 14:54:09 +0000 (08:54 -0600)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 1 Nov 2011 15:58:08 +0000 (10:58 -0500)
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 <alex.williamson@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
exec.c

diff --git a/exec.c b/exec.c
index 2f3c6a0ce3bb8ab07e4067b2efd51d7489a6ee44..54ecbe7e3636cdc24bdeca299e4d90aa82f5dcf4 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -2873,7 +2873,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;
@@ -2889,10 +2889,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;
 }