qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] qcow2: Replace align_offset() with ROUND_UP()


From: Alberto Garcia
Subject: Re: [Qemu-devel] [PATCH] qcow2: Replace align_offset() with ROUND_UP()
Date: Wed, 31 Jan 2018 11:55:32 +0100
User-agent: Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (i586-pc-linux-gnu)

On Tue 30 Jan 2018 05:17:47 PM CET, Eric Blake wrote:

>>>> -    virtual_size = align_offset(qemu_opt_get_size_del(opts, 
>>>> BLOCK_OPT_SIZE, 0),
>>>> +    virtual_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 
>>>> 0),
>>>>                                  cluster_size);
>> 
>> I just realized that the first parameter here is a function call with
>> side effects, it it safe to use ROUND_UP() in this case?
>> 
>> #define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d)))
>
> Oh, good catch.  No, we need a temporary variable to hold the result
> of the function call (or we could rewrite ROUND_UP to have
> evaluate-once semantics using gcc/clang extensions).

It was actually not a problem since C guarantees that the (n) in the
conditional expression is only evaluated if the first operand is != 0.
So (n) is only evaluated once.

Anyway, I rewrote it in the new patch as you suggested since it looks a
bit more readable.

Berto



reply via email to

[Prev in Thread] Current Thread [Next in Thread]