Re: [PATCH] nss: Simplify move_and_align

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

 



On Thu, Apr 07, 2016 at 09:31:06 +0200, Michal Privoznik wrote:
> What this function does can be written much shorter.
> 
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  tools/nss/libvirt_nss.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
> index de34baf..587b171 100644
> --- a/tools/nss/libvirt_nss.c
> +++ b/tools/nss/libvirt_nss.c
> @@ -263,12 +263,10 @@ move_and_align(void *buf, size_t len, size_t *idx)
>      char *buffer = buf;
>      size_t move = LIBVIRT_ALIGN(len);
>  
> -    if (!idx)
> -        return buffer + move;
> +    if (idx)
> +        *idx += move;
>  
> -    *idx += move;
> -
> -    return buffer + *idx;
> +    return buffer + move;
>  }

But it doesn't seem to be equivalent... The !idx case remains the same,
but in the idx case:

old code:

    *idx += move;
    return buffer + *idx;

new code:

    *idx += move;
    return buffer + move;


I guess you need to do something like

    if (idx) {
        buffer += *idx;
        *idx += move;
    }

    return buffer + move;

Jirka

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]