Skip to content

Commit

Permalink
exec: assert that RAMBlock size is non-zero
Browse files Browse the repository at this point in the history
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 <stefanha@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
stefanhaRH authored and mstsirkin committed Mar 26, 2013
1 parent 8c7f3dd commit 49cd9ac
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions exec.c
Expand Up @@ -925,6 +925,8 @@ static ram_addr_t find_ram_offset(ram_addr_t size)
RAMBlock *block, *next_block; RAMBlock *block, *next_block;
ram_addr_t offset = RAM_ADDR_MAX, mingap = RAM_ADDR_MAX; 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)) if (QTAILQ_EMPTY(&ram_list.blocks))
return 0; return 0;


Expand Down

0 comments on commit 49cd9ac

Please sign in to comment.