mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
util: use g_auto() for all virBuffers
Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
0e3dc7c5c5
commit
f2090f362d
@ -345,7 +345,7 @@ virBitmapToString(virBitmapPtr bitmap,
|
||||
bool prefix,
|
||||
bool trim)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t sz;
|
||||
size_t len;
|
||||
size_t diff;
|
||||
@ -404,7 +404,7 @@ virBitmapToString(virBitmapPtr bitmap,
|
||||
char *
|
||||
virBitmapFormat(virBitmapPtr bitmap)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
bool first = true;
|
||||
int start, cur, prev;
|
||||
|
||||
|
@ -2080,7 +2080,7 @@ char *
|
||||
virCommandToString(virCommandPtr cmd, bool linebreaks)
|
||||
{
|
||||
size_t i;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
bool prevopt = false;
|
||||
|
||||
/* Cannot assume virCommandRun will be called; so report the error
|
||||
@ -2101,7 +2101,6 @@ virCommandToString(virCommandPtr cmd, bool linebreaks)
|
||||
char *eq = strchr(cmd->env[i], '=');
|
||||
|
||||
if (!eq) {
|
||||
virBufferFreeAndReset(&buf);
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("invalid use of command API"));
|
||||
return NULL;
|
||||
|
@ -1419,7 +1419,7 @@ int virConfWalk(virConfPtr conf,
|
||||
int
|
||||
virConfWriteFile(const char *filename, virConfPtr conf)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
virConfEntryPtr cur;
|
||||
int ret;
|
||||
int fd;
|
||||
@ -1437,7 +1437,6 @@ virConfWriteFile(const char *filename, virConfPtr conf)
|
||||
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
if (fd < 0) {
|
||||
virBufferFreeAndReset(&buf);
|
||||
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"));
|
||||
return -1;
|
||||
}
|
||||
@ -1471,7 +1470,7 @@ virConfWriteFile(const char *filename, virConfPtr conf)
|
||||
int
|
||||
virConfWriteMem(char *memory, int *len, virConfPtr conf)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
virConfEntryPtr cur;
|
||||
char *content;
|
||||
unsigned int use;
|
||||
|
@ -139,7 +139,7 @@ addnhostsNew(const char *name,
|
||||
const char *config_dir)
|
||||
{
|
||||
dnsmasqAddnHostsfile *addnhostsfile;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
if (VIR_ALLOC(addnhostsfile) < 0)
|
||||
return NULL;
|
||||
@ -157,7 +157,6 @@ addnhostsNew(const char *name,
|
||||
return addnhostsfile;
|
||||
|
||||
error:
|
||||
virBufferFreeAndReset(&buf);
|
||||
addnhostsFree(addnhostsfile);
|
||||
return NULL;
|
||||
}
|
||||
@ -342,7 +341,7 @@ hostsfileNew(const char *name,
|
||||
const char *config_dir)
|
||||
{
|
||||
dnsmasqHostsfile *hostsfile;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
if (VIR_ALLOC(hostsfile) < 0)
|
||||
return NULL;
|
||||
@ -359,7 +358,6 @@ hostsfileNew(const char *name,
|
||||
return hostsfile;
|
||||
|
||||
error:
|
||||
virBufferFreeAndReset(&buf);
|
||||
hostsfileFree(hostsfile);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1303,7 +1303,7 @@ int
|
||||
virBuildPathInternal(char **path, ...)
|
||||
{
|
||||
char *path_component = NULL;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
va_list ap;
|
||||
int ret = 0;
|
||||
|
||||
|
@ -101,7 +101,7 @@ virFileCacheGetFileName(virFileCachePtr cache,
|
||||
const char *name)
|
||||
{
|
||||
g_autofree char *namehash = NULL;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &namehash) < 0)
|
||||
return NULL;
|
||||
|
@ -641,7 +641,7 @@ static char *
|
||||
virFirewallRuleToString(virFirewallRulePtr rule)
|
||||
{
|
||||
const char *bin = virFirewallLayerCommandTypeToString(rule->layer);
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
|
||||
virBufferAdd(&buf, bin, -1);
|
||||
|
@ -1071,7 +1071,7 @@ char *
|
||||
virLogGetFilters(void)
|
||||
{
|
||||
size_t i;
|
||||
virBuffer filterbuf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) filterbuf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
virLogLock();
|
||||
for (i = 0; i < virLogNbFilters; i++) {
|
||||
@ -1098,7 +1098,7 @@ char *
|
||||
virLogGetOutputs(void)
|
||||
{
|
||||
size_t i;
|
||||
virBuffer outputbuf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) outputbuf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
virLogLock();
|
||||
for (i = 0; i < virLogNbOutputs; i++) {
|
||||
@ -1131,7 +1131,6 @@ virLogGetOutputs(void)
|
||||
|
||||
error:
|
||||
virLogUnlock();
|
||||
virBufferFreeAndReset(&outputbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -660,7 +660,7 @@ virNetDevIPCheckIPv6Forwarding(void)
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
for (i = 0; i < data.ndevices; i++) {
|
||||
virBufferAdd(&buf, data.devices[i], -1);
|
||||
if (i < data.ndevices - 1)
|
||||
@ -672,7 +672,6 @@ virNetDevIPCheckIPv6Forwarding(void)
|
||||
"RA routes without accept_ra set to 2 is likely to cause "
|
||||
"routes loss. Interfaces to look at: %s"),
|
||||
virBufferCurrentContent(&buf));
|
||||
virBufferFreeAndReset(&buf);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
@ -42,7 +42,7 @@ VIR_LOG_INIT("util.pidfile");
|
||||
|
||||
char *virPidFileBuildPath(const char *dir, const char* name)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
virBufferAsprintf(&buf, "%s", dir);
|
||||
virBufferEscapeString(&buf, "/%s.pid", name);
|
||||
|
@ -360,7 +360,7 @@ virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
|
||||
char *
|
||||
virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
char *ret = NULL;
|
||||
|
||||
if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, false,
|
||||
@ -370,7 +370,6 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
|
||||
ret = virBufferContentAndReset(&buf);
|
||||
|
||||
cleanup:
|
||||
virBufferFreeAndReset(&buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1587,20 +1587,16 @@ virResctrlAllocFormatCache(virResctrlAllocPtr alloc,
|
||||
char *
|
||||
virResctrlAllocFormat(virResctrlAllocPtr alloc)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
if (!alloc)
|
||||
return NULL;
|
||||
|
||||
if (virResctrlAllocFormatCache(alloc, &buf) < 0) {
|
||||
virBufferFreeAndReset(&buf);
|
||||
if (virResctrlAllocFormatCache(alloc, &buf) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virResctrlAllocMemoryBandwidthFormat(alloc, &buf) < 0) {
|
||||
virBufferFreeAndReset(&buf);
|
||||
if (virResctrlAllocMemoryBandwidthFormat(alloc, &buf) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return virBufferContentAndReset(&buf);
|
||||
}
|
||||
|
@ -1263,7 +1263,7 @@ virSocketAddrPTRDomain(const virSocketAddr *addr,
|
||||
unsigned int prefix,
|
||||
char **ptr)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
@ -1303,7 +1303,6 @@ virSocketAddrPTRDomain(const virSocketAddr *addr,
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virBufferFreeAndReset(&buf);
|
||||
return ret;
|
||||
|
||||
unsupported:
|
||||
|
@ -4255,7 +4255,7 @@ virStorageFileCanonicalizeFormatPath(char **components,
|
||||
bool beginSlash,
|
||||
bool beginDoubleSlash)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
char *ret = NULL;
|
||||
|
||||
|
@ -148,7 +148,7 @@ char *virStringListJoin(const char **strings,
|
||||
const char *delim)
|
||||
{
|
||||
char *ret;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
while (*strings) {
|
||||
virBufferAdd(&buf, *strings, -1);
|
||||
if (*(strings+1))
|
||||
@ -1069,7 +1069,7 @@ virStringReplace(const char *haystack,
|
||||
const char *oldneedle,
|
||||
const char *newneedle)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
const char *tmp1, *tmp2;
|
||||
size_t oldneedlelen = strlen(oldneedle);
|
||||
size_t newneedlelen = strlen(newneedle);
|
||||
|
@ -1573,8 +1573,8 @@ virSysinfoFormatFWCfg(virBufferPtr buf,
|
||||
int
|
||||
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||
{
|
||||
virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
|
||||
virBuffer childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||
const char *type = virSysinfoTypeToString(def->type);
|
||||
|
||||
if (!type) {
|
||||
|
@ -100,7 +100,7 @@ char *virSystemdMakeScopeName(const char *name,
|
||||
const char *drivername,
|
||||
bool legacy_behaviour)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
virBufferAddLit(&buf, "machine-");
|
||||
if (legacy_behaviour) {
|
||||
@ -116,7 +116,7 @@ char *virSystemdMakeScopeName(const char *name,
|
||||
|
||||
char *virSystemdMakeSliceName(const char *partition)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
if (*partition == '/')
|
||||
partition++;
|
||||
|
@ -252,7 +252,7 @@ virURIFormat(virURIPtr uri)
|
||||
|
||||
char *virURIFormatParams(virURIPtr uri)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
bool amp = false;
|
||||
|
||||
|
@ -683,8 +683,7 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
|
||||
const xmlChar *cur, *base;
|
||||
unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
|
||||
int domcode = VIR_FROM_XML;
|
||||
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
char *contextstr = NULL;
|
||||
char *pointerstr = NULL;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user