提交 3a13e4f1 编写于 作者: M Martin Kletzander

util: Make sure the comment about virBufferAddBuffer is true

Change it so it really *always* eats the @toadd buffer.
Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 57f726a5
/* /*
* virbuffer.c: buffers for libvirt * 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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -188,23 +188,27 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd) ...@@ -188,23 +188,27 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd)
{ {
unsigned int needSize; unsigned int needSize;
if (!buf || !toadd) if (!toadd)
return; return;
if (!buf)
goto done;
if (buf->error || toadd->error) { if (buf->error || toadd->error) {
if (!buf->error) if (!buf->error)
buf->error = toadd->error; buf->error = toadd->error;
virBufferFreeAndReset(toadd); goto done;
return;
} }
needSize = buf->use + toadd->use; needSize = buf->use + toadd->use;
if (virBufferGrow(buf, needSize - buf->use) < 0) if (virBufferGrow(buf, needSize - buf->use) < 0)
return; goto done;
memcpy(&buf->content[buf->use], toadd->content, toadd->use); memcpy(&buf->content[buf->use], toadd->content, toadd->use);
buf->use += toadd->use; buf->use += toadd->use;
buf->content[buf->use] = '\0'; buf->content[buf->use] = '\0';
done:
virBufferFreeAndReset(toadd); virBufferFreeAndReset(toadd);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册