1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

util: buffer: Remove virBufferError

The function now does not return an error so we can drop it fully.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-10-24 14:25:59 +02:00
parent 418aa809fd
commit 205d6a2af7
28 changed files with 5 additions and 236 deletions

View File

@ -30521,8 +30521,6 @@ virDomainMachineNameAppendValid(virBufferPtr buf,
bool skip_dot = false;
for (; *name; name++) {
if (virBufferError(buf))
break;
if (strlen(virBufferCurrentContent(buf)) >= 64)
break;

View File

@ -1592,7 +1592,6 @@ virBufferAsprintf;
virBufferCheckErrorInternal;
virBufferContentAndReset;
virBufferCurrentContent;
virBufferError;
virBufferEscape;
virBufferEscapeRegex;
virBufferEscapeSexpr;

View File

@ -431,10 +431,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
virBuffer buf = VIR_BUFFER_INITIALIZER;
virNWFilterVarAccessPrint(rule->varAccess[j], &buf);
if (virBufferError(&buf)) {
virReportOOMError();
return -1;
}
val = virNWFilterVarValueCreateSimpleCopyValue("1");
if (!val) {

View File

@ -456,11 +456,6 @@ learnIPAddressThread(void *arg)
macaddr);
}
if (virBufferError(&buf)) {
req->status = ENOMEM;
goto done;
}
filter = virBufferContentAndReset(&buf);
if (pcap_compile(handle, &fp, filter, 1, 0) != 0) {

View File

@ -1314,12 +1314,6 @@ get_files(vahControl * ctl)
if (vah_add_file(&buf, ctl->newfile, "rwk") != 0)
goto cleanup;
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
vah_error(NULL, 0, _("failed to allocate file buffer"));
goto cleanup;
}
rc = 0;
ctl->files = virBufferContentAndReset(&buf);
@ -1507,11 +1501,6 @@ main(int argc, char **argv)
virBufferAdd(&buf, ctl->files, -1);
}
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
vah_error(ctl, 1, _("failed to allocate buffer"));
}
included_files = virBufferContentAndReset(&buf);
/* (re)create the include file using included_files */

View File

@ -446,12 +446,6 @@ virBitmapFormat(virBitmapPtr bitmap)
start = prev = cur;
}
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL;
}
return virBufferContentAndReset(&buf);
}

View File

@ -276,21 +276,6 @@ void virBufferFreeAndReset(virBufferPtr buf)
memset(buf, 0, sizeof(*buf));
}
/**
* virBufferError:
* @buf: the buffer
*
* Check to see if the buffer is in an error state due
* to failed memory allocation or usage error
*
* Return positive errno value or -1 on usage error, 0 if normal
*/
int
virBufferError(const virBuffer *buf G_GNUC_UNUSED)
{
return 0;
}
/**
* virBufferCheckErrorInternal:
* @buf: the buffer

View File

@ -43,7 +43,6 @@ struct _virBuffer {
const char *virBufferCurrentContent(virBufferPtr buf);
char *virBufferContentAndReset(virBufferPtr buf);
void virBufferFreeAndReset(virBufferPtr buf);
int virBufferError(const virBuffer *buf);
int virBufferCheckErrorInternal(const virBuffer *buf)
ATTRIBUTE_NONNULL(1);

View File

@ -1389,11 +1389,6 @@ virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf)
return;
}
if (virBufferError(buf)) {
cmd->has_error = ENOMEM;
virBufferFreeAndReset(buf);
return;
}
if (!virBufferUse(buf)) {
cmd->has_error = EINVAL;
return;
@ -1525,8 +1520,7 @@ virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf)
}
/* Arg plus trailing NULL. */
if (virBufferError(buf) ||
VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) {
if (VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) {
cmd->has_error = ENOMEM;
virBufferFreeAndReset(buf);
return;

View File

@ -1137,11 +1137,6 @@ virLogGetFilters(void)
}
virLogUnlock();
if (virBufferError(&filterbuf)) {
virBufferFreeAndReset(&filterbuf);
return NULL;
}
return virBufferContentAndReset(&filterbuf);
}
@ -1185,9 +1180,6 @@ virLogGetOutputs(void)
}
}
if (virBufferError(&outputbuf))
goto error;
virLogUnlock();
return virBufferContentAndReset(&outputbuf);

View File

@ -268,10 +268,6 @@ cpuTestGuestCPU(const void *arg)
virBufferAsprintf(&buf, ",%s", data->modelsName);
virBufferAddLit(&buf, "-result");
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
goto cleanup;
}
result = virBufferContentAndReset(&buf);
if (cpuTestCompareXML(data->arch, cpu, result) < 0)

View File

@ -76,9 +76,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (networkAddFirewallRules(def) < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = actualargv = virBufferContentAndReset(&buf);
virTestClearCommandPath(actualargv);
virCommandSetDryRun(NULL, NULL, NULL);

View File

@ -109,9 +109,6 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED)
if (ebiptables_driver.allTeardown("vnet0") < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = virBufferContentAndReset(&buf);
virTestClearCommandPath(actual);
@ -180,9 +177,6 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED)
if (ebiptables_driver.tearOldRules("vnet0") < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = virBufferContentAndReset(&buf);
virTestClearCommandPath(actual);
@ -229,9 +223,6 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED)
if (ebiptables_driver.removeBasicRules("vnet0") < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = virBufferContentAndReset(&buf);
virTestClearCommandPath(actual);
@ -263,9 +254,6 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED)
if (ebiptables_driver.tearNewRules("vnet0") < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = virBufferContentAndReset(&buf);
virTestClearCommandPath(actual);
@ -335,9 +323,6 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED)
if (ebiptables_driver.applyBasicRules("vnet0", &mac) < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = virBufferContentAndReset(&buf);
virTestClearCommandPath(actual);
@ -425,9 +410,6 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED)
if (ebiptables_driver.applyDHCPOnlyRules("vnet0", &mac, &val, false) < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = virBufferContentAndReset(&buf);
virTestClearCommandPath(actual);
@ -498,9 +480,6 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED)
if (ebiptables_driver.applyDropAllRules("vnet0") < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actual = virBufferContentAndReset(&buf);
virTestClearCommandPath(actual);

View File

@ -394,9 +394,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (ebiptables_driver.applyNewRules("vnet0", inst.rules, inst.nrules) < 0)
goto cleanup;
if (virBufferError(&buf))
goto cleanup;
actualargv = virBufferContentAndReset(&buf);
virTestClearCommandPath(actualargv);
virCommandSetDryRun(NULL, NULL, NULL);

View File

@ -763,8 +763,6 @@ virTestLogContentAndReset(void)
{
char *ret;
if (virBufferError(&testLog.buf))
return NULL;
ret = virBufferContentAndReset(&testLog.buf);
if (!ret)
ret = g_strdup("");

View File

@ -36,11 +36,6 @@ testFilterXML(char *xml)
virBufferStrcat(&buf, *xmlLine, "\n", NULL);
}
if (virBufferError(&buf)) {
virReportOOMError();
goto cleanup;
}
ret = virBufferContentAndReset(&buf);
cleanup:

View File

@ -29,15 +29,13 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED)
ret = -1;
}
if (virBufferGetIndent(buf) != 3 ||
virBufferGetEffectiveIndent(buf) != 3 ||
virBufferError(buf)) {
virBufferGetEffectiveIndent(buf) != 3) {
VIR_TEST_DEBUG("Wrong indentation");
ret = -1;
}
virBufferAdjustIndent(buf, -2);
if (virBufferGetIndent(buf) != 1 ||
virBufferGetEffectiveIndent(buf) != 1 ||
virBufferError(buf)) {
virBufferGetEffectiveIndent(buf) != 1) {
VIR_TEST_DEBUG("Wrong indentation");
ret = -1;
}
@ -50,17 +48,12 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED)
virBufferAdjustIndent(buf, 3);
virBufferFreeAndReset(buf);
if (virBufferGetIndent(buf) != 0 ||
virBufferGetEffectiveIndent(buf) != 0 ||
virBufferError(buf)) {
virBufferGetEffectiveIndent(buf) != 0) {
VIR_TEST_DEBUG("Reset didn't clear indentation");
ret = -1;
}
virBufferAdjustIndent(buf, 2);
virBufferAddLit(buf, "1");
if (virBufferError(buf)) {
VIR_TEST_DEBUG("Buffer had error");
return -1;
}
if (STRNEQ(virBufferCurrentContent(buf), " 1")) {
VIR_TEST_DEBUG("Wrong content");
ret = -1;
@ -87,11 +80,6 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED)
virBufferEscapeShell(buf, " 11");
virBufferAddChar(buf, '\n');
if (virBufferError(buf)) {
VIR_TEST_DEBUG("Buffer had error");
return -1;
}
result = virBufferContentAndReset(buf);
if (!result || STRNEQ(result, expected)) {
virTestDifference(stderr, expected, result);
@ -125,11 +113,6 @@ static int testBufTrim(const void *data G_GNUC_UNUSED)
virBufferTrim(buf, "b,,", 1);
virBufferTrim(buf, ",", -1);
if (virBufferError(buf)) {
VIR_TEST_DEBUG("Buffer had error");
return -1;
}
result = virBufferContentAndReset(buf);
if (!result || STRNEQ(result, expected)) {
virTestDifference(stderr, expected, result);

View File

@ -234,9 +234,6 @@ testFirewallSingleGroup(const void *opaque)
if (virFirewallApply(fw) < 0)
goto cleanup;
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -300,9 +297,6 @@ testFirewallRemoveRule(const void *opaque)
if (virFirewallApply(fw) < 0)
goto cleanup;
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -373,9 +367,6 @@ testFirewallManyGroups(const void *opaque G_GNUC_UNUSED)
if (virFirewallApply(fw) < 0)
goto cleanup;
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -469,9 +460,6 @@ testFirewallIgnoreFailGroup(const void *opaque G_GNUC_UNUSED)
if (virFirewallApply(fw) < 0)
goto cleanup;
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -543,9 +531,6 @@ testFirewallIgnoreFailRule(const void *opaque G_GNUC_UNUSED)
if (virFirewallApply(fw) < 0)
goto cleanup;
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -611,9 +596,6 @@ testFirewallNoRollback(const void *opaque G_GNUC_UNUSED)
goto cleanup;
}
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -698,9 +680,6 @@ testFirewallSingleRollback(const void *opaque G_GNUC_UNUSED)
goto cleanup;
}
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -788,9 +767,6 @@ testFirewallManyRollback(const void *opaque G_GNUC_UNUSED)
goto cleanup;
}
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -908,9 +884,6 @@ testFirewallChainedRollback(const void *opaque G_GNUC_UNUSED)
goto cleanup;
}
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (STRNEQ_NULLABLE(expected, actual)) {
@ -1085,9 +1058,6 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED)
if (virFirewallApply(fw) < 0)
goto cleanup;
if (virBufferError(&cmdbuf))
goto cleanup;
actual = virBufferCurrentContent(&cmdbuf);
if (expectedLineError) {

View File

@ -69,11 +69,7 @@ checkOutput(virBufferPtr buf, const char *exp_cmd)
char *actual_cmd = NULL;
if (!(actual_cmd = virBufferContentAndReset(buf))) {
int err = virBufferError(buf);
if (err)
fprintf(stderr, "buffer's in error state: %d", err);
else
fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd);
fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd);
goto cleanup;
}

View File

@ -84,11 +84,6 @@ testVirNetDevBandwidthSet(const void *data)
goto cleanup;
if (!(actual_cmd = virBufferContentAndReset(&buf))) {
int err = virBufferError(&buf);
if (err) {
fprintf(stderr, "buffer's in error state: %d", err);
goto cleanup;
}
/* This is interesting, no command has been executed.
* Maybe that's expected, actually. */
}

View File

@ -570,9 +570,6 @@ testActivation(bool useNames)
setenv("LISTEN_FDS", nfdstr, 1);
setenv("LISTEN_PID", pidstr, 1);
if (virBufferError(&names))
goto cleanup;
if (useNames)
setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), 1);
else

View File

@ -267,11 +267,6 @@ cmdCheckpointCreateAs(vshControl *ctl,
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</domaincheckpoint>\n");
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Out of memory"));
goto cleanup;
}
buffer = virBufferContentAndReset(&buf);
if (vshCommandOptBool(cmd, "print-xml")) {

View File

@ -2410,12 +2410,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
type, iface->addrs[j].addr,
iface->addrs[j].prefix);
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
goto cleanup;
}
ip_addr_str = virBufferContentAndReset(&buf);
if (!ip_addr_str)

View File

@ -754,11 +754,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</disk>\n");
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to allocate XML buffer"));
goto cleanup;
}
xml = virBufferContentAndReset(&buf);
if (vshCommandOptBool(cmd, "print-xml")) {
@ -1072,11 +1067,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</interface>\n");
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to allocate XML buffer"));
goto cleanup;
}
xml = virBufferContentAndReset(&buf);
if (vshCommandOptBool(cmd, "print-xml")) {
@ -8396,10 +8386,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
virBufferTrim(&buf, " ", -1);
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to collect new description/title"));
goto cleanup;
}
desc = virBufferContentAndReset(&buf);
if (edit || desc) {
@ -9517,10 +9503,6 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
virBufferTrim(&buf, " ", -1);
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to collect command"));
return false;
}
monitor_cmd = virBufferContentAndReset(&buf);
if (vshCommandOptBool(cmd, "hmp"))
@ -9818,10 +9800,6 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
virBufferTrim(&buf, " ", -1);
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to collect command"));
goto cleanup;
}
guest_agent_cmd = virBufferContentAndReset(&buf);
judge = vshCommandOptInt(ctl, cmd, "timeout", &timeout);
@ -11551,12 +11529,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
params = true;
}
/* Ensure we can print our URI */
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to create display URI"));
goto cleanup;
}
/* Print out our full URI */
VIR_FREE(output);
output = virBufferContentAndReset(&buf);

View File

@ -416,11 +416,6 @@ virshBuildPoolXML(vshControl *ctl,
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</pool>\n");
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to allocate XML buffer"));
return false;
}
*xml = virBufferContentAndReset(&buf);
*retname = name;
return true;
@ -1480,10 +1475,6 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED)
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</source>\n");
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Out of memory"));
return false;
}
srcSpec = virBufferContentAndReset(&buf);
}

View File

@ -445,11 +445,6 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</domainsnapshot>\n");
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Out of memory"));
goto cleanup;
}
buffer = virBufferContentAndReset(&buf);
if (vshCommandOptBool(cmd, "print-xml")) {

View File

@ -341,10 +341,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</volume>\n");
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to allocate XML buffer"));
goto cleanup;
}
xml = virBufferContentAndReset(&buf);
if (printXML) {

View File

@ -2269,9 +2269,6 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
virBufferTrim(&buf, "\n", -1);
virBufferAddChar(&buf, '\n');
if (virBufferError(&buf))
goto error;
str = virBufferContentAndReset(&buf);
len = strlen(str);
@ -2532,9 +2529,6 @@ vshTreePrintInternal(vshControl *ctl,
int ret = -1;
const char *dev = (lookup)(devid, false, opaque);
if (virBufferError(indent))
goto cleanup;
/* Print this device, with indent if not at root */
vshPrint(ctl, "%s%s%s\n", virBufferCurrentContent(indent),
root ? "" : "+- ", dev);
@ -2543,8 +2537,6 @@ vshTreePrintInternal(vshControl *ctl,
if (!root) {
virBufferAddChar(indent, devid == lastdev ? ' ' : '|');
virBufferAddChar(indent, ' ');
if (virBufferError(indent))
goto cleanup;
}
/* Determine the index of the last child device */
@ -2561,8 +2553,6 @@ vshTreePrintInternal(vshControl *ctl,
/* Finally print all children */
virBufferAddLit(indent, " ");
if (virBufferError(indent))
goto cleanup;
for (i = 0; i < num_devices; i++) {
const char *parent = (lookup)(i, true, opaque);
@ -3315,10 +3305,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
if (xml) {
virBufferEscapeString(&xmlbuf, "%s", arg);
if (virBufferError(&xmlbuf)) {
vshError(ctl, "%s", _("Failed to allocate XML buffer"));
return false;
}
str = virBufferContentAndReset(&xmlbuf);
} else {
str = g_strdup(arg);
@ -3332,10 +3318,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
VIR_FREE(str);
}
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to allocate XML buffer"));
return false;
}
arg = virBufferContentAndReset(&buf);
if (arg) {
if (err)