[libvirt] [PATCH v2 1/4] util: Make sure the comment about virBufferAddBuffer is true

Erik Skultety eskultet at redhat.com
Mon Mar 16 13:10:14 UTC 2015



On 03/13/2015 05:17 PM, Martin Kletzander wrote:
> Change it so it really *always* eats the @toadd buffer.
> 
> Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
> ---
>  src/util/virbuffer.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
> index 96a0f16..0089d1b 100644
> --- a/src/util/virbuffer.c
> +++ b/src/util/virbuffer.c
> @@ -1,7 +1,7 @@
>  /*
>   * virbuffer.c: buffers for libvirt
>   *
> - * Copyright (C) 2005-2008, 2010-2014 Red Hat, Inc.
> + * Copyright (C) 2005-2008, 2010-2015 Red Hat, Inc.
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Lesser General Public
> @@ -188,23 +188,27 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd)
>  {
>      unsigned int needSize;
> 
> -    if (!buf || !toadd)
> +    if (!toadd)
>          return;
> 
> +    if (!buf)
> +        goto done;
> +
>      if (buf->error || toadd->error) {
>          if (!buf->error)
>              buf->error = toadd->error;
> -        virBufferFreeAndReset(toadd);
> -        return;
> +        goto done;
>      }
> 
>      needSize = buf->use + toadd->use;
>      if (virBufferGrow(buf, needSize - buf->use) < 0)
> -        return;
> +        goto done;
> 
>      memcpy(&buf->content[buf->use], toadd->content, toadd->use);
>      buf->use += toadd->use;
>      buf->content[buf->use] = '\0';
> +
> + done:
>      virBufferFreeAndReset(toadd);
>  }
> 
> --
> 2.3.2
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
> 
ACK,
Erik




More information about the libvir-list mailing list