[Spice-devel] [PATCH 09/22] memslot: change some spice_assert to spice_return_if_fail
Frediano Ziglio
fziglio at redhat.com
Wed Dec 2 09:09:56 PST 2015
>
> ---
> server/red_memslots.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/server/red_memslots.c b/server/red_memslots.c
> index 2fd939e..0d2d963 100644
> --- a/server/red_memslots.c
> +++ b/server/red_memslots.c
> @@ -130,8 +130,8 @@ void memslot_info_init(RedMemSlotInfo *info,
> {
> uint32_t i;
>
> - spice_assert(num_slots > 0);
> - spice_assert(num_groups > 0);
> + spice_return_if_fail(num_slots > 0);
> + spice_return_if_fail(num_groups > 0);
>
> info->num_memslots_groups = num_groups;
> info->num_memslots = num_slots;
Here the caller have no possibility to fix the issue and have to
believe that everything went fine.
I would prefer the assert.
> @@ -157,8 +157,8 @@ void memslot_info_add_slot(RedMemSlotInfo *info, uint32_t
> slot_group_id, uint32_
> uint64_t addr_delta, unsigned long virt_start,
> unsigned long virt_end,
> uint32_t generation)
> {
> - spice_assert(info->num_memslots_groups > slot_group_id);
> - spice_assert(info->num_memslots > slot_id);
> + spice_return_if_fail(info->num_memslots_groups > slot_group_id);
> + spice_return_if_fail(info->num_memslots > slot_id);
>
> info->mem_slots[slot_group_id][slot_id].address_delta = addr_delta;
> info->mem_slots[slot_group_id][slot_id].virt_start_addr = virt_start;
Same
> @@ -168,8 +168,8 @@ void memslot_info_add_slot(RedMemSlotInfo *info, uint32_t
> slot_group_id, uint32_
>
> void memslot_info_del_slot(RedMemSlotInfo *info, uint32_t slot_group_id,
> uint32_t slot_id)
> {
> - spice_assert(info->num_memslots_groups > slot_group_id);
> - spice_assert(info->num_memslots > slot_id);
> + spice_return_if_fail(info->num_memslots_groups > slot_group_id);
> + spice_return_if_fail(info->num_memslots > slot_id);
>
> info->mem_slots[slot_group_id][slot_id].virt_start_addr = 0;
> info->mem_slots[slot_group_id][slot_id].virt_end_addr = 0;
Here I can survive, caller is just trying to delete a missing item.
Frediano
More information about the Spice-devel
mailing list