These functions can't fail really. Drop checking of their retval then. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- tests/commandtest.c | 27 +++---- tests/cputest.c | 95 +++++++++--------------- tests/domaincapstest.c | 26 +++---- tests/domainconftest.c | 5 +- tests/fchosttest.c | 7 +- tests/fdstreamtest.c | 6 +- tests/genericxml2xmltest.c | 10 +-- tests/interfacexml2xmltest.c | 5 +- tests/libxlxml2domconfigtest.c | 8 +- tests/lxcconf2xmltest.c | 20 ++--- tests/lxcxml2xmltest.c | 10 +-- tests/networkxml2conftest.c | 9 +-- tests/networkxml2firewalltest.c | 16 ++-- tests/networkxml2xmltest.c | 9 +-- tests/networkxml2xmlupdatetest.c | 15 ++-- tests/nodedevxml2xmltest.c | 5 +- tests/nssmock.c | 9 +-- tests/nwfilterxml2firewalltest.c | 15 ++-- tests/nwfilterxml2xmltest.c | 9 +-- tests/openvzutilstest.c | 6 +- tests/qemuagenttest.c | 4 +- tests/qemublocktest.c | 34 +++------ tests/qemucapabilitiestest.c | 20 ++--- tests/qemucaps2xmltest.c | 15 ++-- tests/qemudomaincheckpointxml2xmltest.c | 5 +- tests/qemudomainsnapshotxml2xmltest.c | 5 +- tests/qemufirmwaretest.c | 4 +- tests/qemuhotplugtest.c | 29 ++++---- tests/qemumemlocktest.c | 5 +- tests/qemumigparamstest.c | 23 +++--- tests/qemumonitorjsontest.c | 56 +++++++------- tests/qemumonitortestutils.c | 38 +++------- tests/qemusecuritymock.c | 5 +- tests/qemusecuritytest.c | 3 +- tests/qemuvhostusertest.c | 4 +- tests/qemuxml2argvtest.c | 35 +++------ tests/qemuxml2xmltest.c | 41 +++-------- tests/scsihosttest.c | 26 ++----- tests/secretxml2xmltest.c | 14 ++-- tests/securityselinuxlabeltest.c | 23 ++---- tests/storagebackendsheepdogtest.c | 11 +-- tests/storagepoolcapstest.c | 6 +- tests/storagepoolxml2argvtest.c | 11 +-- tests/storagepoolxml2xmltest.c | 9 +-- tests/storagevolxml2argvtest.c | 31 +++----- tests/storagevolxml2xmltest.c | 13 ++-- tests/sysinfotest.c | 18 ++--- tests/testutils.c | 17 ++--- tests/testutils.h | 5 +- tests/testutilsqemu.c | 11 +-- tests/vboxsnapshotxmltest.c | 5 +- tests/virbuftest.c | 7 +- tests/vircaps2xmltest.c | 15 ++-- tests/vircgroupmock.c | 11 +-- tests/vircgrouptest.c | 5 +- tests/virconftest.c | 7 +- tests/virfilemock.c | 2 +- tests/virfiletest.c | 3 +- tests/virfilewrapper.c | 4 +- tests/virhostcputest.c | 38 ++++------ tests/virjsontest.c | 27 +++---- tests/virmacmaptest.c | 12 +-- tests/virnetdaemontest.c | 10 +-- tests/virnetdevmock.c | 8 +- tests/virnetdevopenvswitchtest.c | 5 +- tests/virnetsockettest.c | 6 +- tests/virnetworkportxml2xmltest.c | 6 +- tests/virnumamock.c | 3 +- tests/virnwfilterbindingxml2xmltest.c | 7 +- tests/virpcimock.c | 97 ++++++++++--------------- tests/virpcitest.c | 16 ++-- tests/virrandommock.c | 5 +- tests/virresctrltest.c | 15 ++-- tests/virschematest.c | 19 ++--- tests/virscsitest.c | 11 +-- tests/virshtest.c | 5 +- tests/virstoragetest.c | 63 ++++++++-------- tests/virtestmock.c | 8 +- tests/virusbmock.c | 9 +-- tests/virusbtest.c | 6 +- tests/vmwarevertest.c | 4 +- tests/vmx2xmltest.c | 18 ++--- tests/xlconfigtest.c | 8 +- tests/xmconfigtest.c | 8 +- tests/xml2vmxtest.c | 16 ++-- 85 files changed, 480 insertions(+), 842 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index 6ff2039ab1..9ee23add4c 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -67,11 +67,8 @@ static int checkoutput(const char *testname, char *actualname = NULL; char *actuallog = NULL; - if (virAsprintf(&expectname, "%s/commanddata/%s.log", abs_srcdir, - testname) < 0) - goto cleanup; - if (virAsprintf(&actualname, "%s/commandhelper.log", abs_builddir) < 0) - goto cleanup; + virAsprintf(&expectname, "%s/commanddata/%s.log", abs_srcdir, testname); + virAsprintf(&actualname, "%s/commandhelper.log", abs_builddir); if (virFileReadAll(expectname, 1024*64, &expectlog) < 0) { fprintf(stderr, "cannot read %s\n", expectname); @@ -86,8 +83,7 @@ static int checkoutput(const char *testname, if (prefix) { char *tmp = NULL; - if (virAsprintf(&tmp, "%s%s", prefix, expectlog) < 0) - goto cleanup; + virAsprintf(&tmp, "%s%s", prefix, expectlog); VIR_FREE(expectlog); expectlog = tmp; @@ -595,8 +591,7 @@ static int test15(const void *unused G_GNUC_UNUSED) char *cwd = NULL; int ret = -1; - if (virAsprintf(&cwd, "%s/commanddata", abs_srcdir) < 0) - goto cleanup; + virAsprintf(&cwd, "%s/commanddata", abs_srcdir); virCommandSetWorkingDirectory(cmd, cwd); virCommandSetUmask(cmd, 002); @@ -815,8 +810,7 @@ static int test20(const void *unused G_GNUC_UNUSED) sigaction(SIGPIPE, &sig_action, NULL); - if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0) - goto cleanup; + virAsprintf(&buf, "1\n%100000d\n", 2); virCommandSetInputBuffer(cmd, buf); if (virCommandRun(cmd, NULL) < 0) { @@ -1174,13 +1168,10 @@ static int test27(const void *unused G_GNUC_UNUSED) buffer2[buflen - 2] = '\n'; buffer2[buflen - 1] = 0; - if (virAsprintf(&outexpect, TEST27_OUTEXPECT_TEMP, - buffer0, buffer1, buffer2) < 0 || - virAsprintf(&errexpect, TEST27_ERREXPECT_TEMP, - buffer0, buffer1, buffer2) < 0) { - printf("Could not virAsprintf expected output\n"); - goto cleanup; - } + virAsprintf(&outexpect, TEST27_OUTEXPECT_TEMP, + buffer0, buffer1, buffer2); + virAsprintf(&errexpect, TEST27_ERREXPECT_TEMP, + buffer0, buffer1, buffer2); if (pipe(pipe1) < 0 || pipe(pipe2) < 0) { printf("Could not create pipe: %s\n", g_strerror(errno)); diff --git a/tests/cputest.c b/tests/cputest.c index 83b494857f..e1b609ef73 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -75,9 +75,8 @@ cpuTestLoadXML(virArch arch, const char *name) xmlXPathContextPtr ctxt = NULL; virCPUDefPtr cpu = NULL; - if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", - abs_srcdir, virArchToString(arch), name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, + virArchToString(arch), name); if (!(doc = virXMLParseFileCtxt(xml, &ctxt))) goto cleanup; @@ -105,9 +104,8 @@ cpuTestLoadMultiXML(virArch arch, int n; size_t i; - if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", - abs_srcdir, virArchToString(arch), name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, + virArchToString(arch), name); if (!(doc = virXMLParseFileCtxt(xml, &ctxt))) goto cleanup; @@ -150,9 +148,8 @@ cpuTestCompareXML(virArch arch, char *actual = NULL; int ret = -1; - if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", - abs_srcdir, virArchToString(arch), name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, + virArchToString(arch), name); if (!(actual = virCPUDefFormat(cpu, NULL))) goto cleanup; @@ -345,8 +342,7 @@ cpuTestBaseline(const void *arg) suffix = "migratable"; else suffix = "result"; - if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0) - goto cleanup; + virAsprintf(&result, "%s-%s", data->name, suffix); if (cpuTestCompareXML(data->arch, baseline, result) < 0) goto cleanup; @@ -399,8 +395,7 @@ cpuTestUpdate(const void *arg) if (virCPUUpdate(host->arch, cpu, migHost) < 0) goto cleanup; - if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0) - goto cleanup; + virAsprintf(&result, "%s+%s", data->host, data->name); ret = cpuTestCompareXML(data->arch, cpu, result); @@ -485,9 +480,8 @@ cpuTestMakeQEMUCaps(const struct data *data) bool fail_no_props = true; char *json = NULL; - if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json", - abs_srcdir, virArchToString(data->arch), data->host) < 0) - goto error; + virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json", abs_srcdir, + virArchToString(data->arch), data->host); if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true))) goto error; @@ -589,9 +583,8 @@ cpuTestCPUID(bool guest, const void *arg) char *result = NULL; virDomainCapsCPUModelsPtr models = NULL; - if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", - abs_srcdir, virArchToString(data->arch), data->host) < 0) - goto cleanup; + virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir, + virArchToString(data->arch), data->host); if (virTestLoadFile(hostFile, &host) < 0 || !(hostData = virCPUDataParse(host))) @@ -622,10 +615,7 @@ cpuTestCPUID(bool guest, const void *arg) if (cpuDecode(cpu, hostData, models) < 0) goto cleanup; - if (virAsprintf(&result, "cpuid-%s-%s", - data->host, - guest ? "guest" : "host") < 0) - goto cleanup; + virAsprintf(&result, "cpuid-%s-%s", data->host, guest ? "guest" : "host"); ret = cpuTestCompareXML(data->arch, cpu, result); @@ -667,17 +657,12 @@ cpuTestCompareSignature(const struct data *data, signature = virCPUx86DataGetSignature(hostData, &family, &model, &stepping); - if (virAsprintf(&result, "%s/cputestdata/%s-cpuid-%s.sig", - abs_srcdir, virArchToString(data->arch), data->host) < 0) - return -1; + virAsprintf(&result, "%s/cputestdata/%s-cpuid-%s.sig", abs_srcdir, + virArchToString(data->arch), data->host); - if (virAsprintf(&sigStr, - "%1$06lx\n" - "family: %2$3u (0x%2$02x)\n" - "model: %3$3u (0x%3$02x)\n" - "stepping: %4$3u (0x%4$02x)\n", - signature, family, model, stepping) < 0) - return -1; + virAsprintf(&sigStr, "%1$06lx\n" "family: %2$3u (0x%2$02x)\n" + "model: %3$3u (0x%3$02x)\n" "stepping: %4$3u (0x%4$02x)\n", + signature, family, model, stepping); return virTestCompareToFile(sigStr, result); } @@ -692,9 +677,8 @@ cpuTestCPUIDSignature(const void *arg) char *host = NULL; int ret = -1; - if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", - abs_srcdir, virArchToString(data->arch), data->host) < 0) - goto cleanup; + virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir, + virArchToString(data->arch), data->host); if (virTestLoadFile(hostFile, &host) < 0 || !(hostData = virCPUDataParse(host))) @@ -817,24 +801,24 @@ cpuTestUpdateLive(const void *arg) virDomainCapsCPUModelsPtr models = NULL; int ret = -1; - if (virAsprintf(&cpuFile, "cpuid-%s-guest", data->host) < 0 || - !(cpu = cpuTestLoadXML(data->arch, cpuFile))) + virAsprintf(&cpuFile, "cpuid-%s-guest", data->host); + if (!(cpu = cpuTestLoadXML(data->arch, cpuFile))) goto cleanup; - if (virAsprintf(&enabledFile, "%s/cputestdata/%s-cpuid-%s-enabled.xml", - abs_srcdir, virArchToString(data->arch), data->host) < 0 || - virTestLoadFile(enabledFile, &enabled) < 0 || + virAsprintf(&enabledFile, "%s/cputestdata/%s-cpuid-%s-enabled.xml", + abs_srcdir, virArchToString(data->arch), data->host); + if (virTestLoadFile(enabledFile, &enabled) < 0 || !(enabledData = virCPUDataParse(enabled))) goto cleanup; - if (virAsprintf(&disabledFile, "%s/cputestdata/%s-cpuid-%s-disabled.xml", - abs_srcdir, virArchToString(data->arch), data->host) < 0 || - virTestLoadFile(disabledFile, &disabled) < 0 || + virAsprintf(&disabledFile, "%s/cputestdata/%s-cpuid-%s-disabled.xml", + abs_srcdir, virArchToString(data->arch), data->host); + if (virTestLoadFile(disabledFile, &disabled) < 0 || !(disabledData = virCPUDataParse(disabled))) goto cleanup; - if (virAsprintf(&expectedFile, "cpuid-%s-json", data->host) < 0 || - !(expected = cpuTestLoadXML(data->arch, expectedFile))) + virAsprintf(&expectedFile, "cpuid-%s-json", data->host); + if (!(expected = cpuTestLoadXML(data->arch, expectedFile))) goto cleanup; /* In case the host CPU signature does not exactly match any CPU model from @@ -906,8 +890,7 @@ cpuTestJSONCPUID(const void *arg) char *result = NULL; int ret = -1; - if (virAsprintf(&result, "cpuid-%s-json", data->host) < 0) - goto cleanup; + virAsprintf(&result, "cpuid-%s-json", data->host); if (!(qemuCaps = cpuTestMakeQEMUCaps(data))) goto cleanup; @@ -1028,11 +1011,8 @@ mymain(void) tmp = virTestLogContentAndReset(); \ VIR_FREE(tmp); \ \ - if (virAsprintf(&testLabel, "%s(%s): %s", \ - #api, virArchToString(arch), name) < 0) { \ - ret = -1; \ - break; \ - } \ + virAsprintf(&testLabel, "%s(%s): %s", \ + #api, virArchToString(arch), name); \ \ if (virTestRun(testLabel, api, &data) < 0) { \ if (virTestGetDebug()) { \ @@ -1072,12 +1052,9 @@ mymain(void) suffix = " (expanded)"; \ if ((flags) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) \ suffix = " (migratable)"; \ - if (virAsprintf(&label, "%s%s", name, suffix) < 0) { \ - ret = -1; \ - } else { \ - DO_TEST(arch, cpuTestBaseline, label, NULL, \ - "baseline-" name, NULL, flags, result); \ - } \ + virAsprintf(&label, "%s%s", name, suffix); \ + DO_TEST(arch, cpuTestBaseline, label, NULL, \ + "baseline-" name, NULL, flags, result); \ VIR_FREE(label); \ } while (0) diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 61bc019671..3289eb3ef7 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -88,9 +88,8 @@ fillQemuCaps(virDomainCapsPtr domCaps, fakeHostCPU(caps, domCaps->arch) < 0) goto cleanup; - if (virAsprintf(&path, "%s/%s.%s.xml", - TEST_QEMU_CAPS_PATH, name, arch) < 0 || - !(qemuCaps = qemuTestParseCapabilities(caps, path))) + virAsprintf(&path, "%s/%s.%s.xml", TEST_QEMU_CAPS_PATH, name, arch); + if (!(qemuCaps = qemuTestParseCapabilities(caps, path))) goto cleanup; if (machine) { @@ -217,9 +216,8 @@ test_virDomainCapsFormat(const void *opaque) char *domCapsXML = NULL; int ret = -1; - if (virAsprintf(&path, "%s/domaincapsschemadata/%s.xml", - abs_srcdir, data->name) < 0) - goto cleanup; + virAsprintf(&path, "%s/domaincapsschemadata/%s.xml", abs_srcdir, + data->name); if (!(domCaps = virDomainCapsNew(data->emulator, data->machine, virArchFromString(data->arch), @@ -299,13 +297,10 @@ mymain(void) #define DO_TEST_QEMU(Name, CapsName, Emulator, Machine, Arch, Type) \ do { \ char *name = NULL; \ - if (virAsprintf(&name, "qemu_%s%s%s.%s", \ - Name, \ - Machine ? "-" : "", Machine ? Machine : "", \ - Arch) < 0) { \ - ret = -1; \ - break; \ - } \ + virAsprintf(&name, "qemu_%s%s%s.%s", \ + Name, \ + Machine ? "-" : "", Machine ? Machine : "", \ + Arch); \ struct testData data = { \ .name = name, \ .emulator = Emulator, \ @@ -338,10 +333,7 @@ mymain(void) #define DO_TEST_BHYVE(Name, Emulator, BhyveCaps, Type) \ do { \ char *name = NULL; \ - if (virAsprintf(&name, "bhyve_%s.x86_64", Name) < 0) { \ - ret = -1; \ - break; \ - } \ + virAsprintf(&name, "bhyve_%s.x86_64", Name); \ struct testData data = { \ .name = name, \ .emulator = Emulator, \ diff --git a/tests/domainconftest.c b/tests/domainconftest.c index e7bdc99438..3de6e7740e 100644 --- a/tests/domainconftest.c +++ b/tests/domainconftest.c @@ -46,9 +46,8 @@ static int testGetFilesystem(const void *opaque) const struct testGetFilesystemData *data = opaque; virDomainFSDefPtr fsdef; - if (virAsprintf(&filename, "%s/domainconfdata/%s.xml", - abs_srcdir, data->filename) < 0) - goto cleanup; + virAsprintf(&filename, "%s/domainconfdata/%s.xml", abs_srcdir, + data->filename); if (!(def = virDomainDefParseFile(filename, caps, xmlopt, NULL, 0))) goto cleanup; diff --git a/tests/fchosttest.c b/tests/fchosttest.c index 4e37656576..fe4f255fe1 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -343,11 +343,7 @@ mymain(void) { int ret = 0; - if (virAsprintf(&fchost_prefix, "%s/%s", abs_srcdir, - "fchostdata/fc_host/") < 0) { - ret = -1; - goto cleanup; - } + virAsprintf(&fchost_prefix, "%s/%s", abs_srcdir, "fchostdata/fc_host/"); if (virTestRun("virVHBAPathExists", test1, NULL) < 0) ret = -1; @@ -377,7 +373,6 @@ mymain(void) test11_xml) < 0) ret = -1; - cleanup: VIR_FREE(fchost_prefix); return ret; } diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c index 98519e6266..4acc97967e 100644 --- a/tests/fdstreamtest.c +++ b/tests/fdstreamtest.c @@ -62,8 +62,7 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking) for (i = 0; i < PATTERN_LEN; i++) pattern[i] = i; - if (virAsprintf(&file, "%s/input.data", scratchdir) < 0) - goto cleanup; + virAsprintf(&file, "%s/input.data", scratchdir); if ((fd = open(file, O_CREAT|O_WRONLY|O_EXCL, 0600)) < 0) goto cleanup; @@ -194,8 +193,7 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) for (i = 0; i < PATTERN_LEN; i++) pattern[i] = i; - if (virAsprintf(&file, "%s/input.data", scratchdir) < 0) - goto cleanup; + virAsprintf(&file, "%s/input.data", scratchdir); if (!(st = virStreamNew(conn, flags))) goto cleanup; diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 1840d6e6a8..7b59749d01 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -29,17 +29,15 @@ testCompareXMLToXMLHelper(const void *data) char *xml_out = NULL; int ret = -1; - if (virAsprintf(&xml_in, "%s/genericxml2xmlindata/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&xml_out, "%s/genericxml2xmloutdata/%s.xml", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml_in, "%s/genericxml2xmlindata/%s.xml", + abs_srcdir, info->name); + virAsprintf(&xml_out, "%s/genericxml2xmloutdata/%s.xml", + abs_srcdir, info->name); ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, info->different ? xml_out : xml_in, !info->inactive_only, 0, info->expectResult); - cleanup: VIR_FREE(xml_in); VIR_FREE(xml_out); return ret; diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c index 1fc61e3853..c7de2e4bd0 100644 --- a/tests/interfacexml2xmltest.c +++ b/tests/interfacexml2xmltest.c @@ -50,9 +50,8 @@ testCompareXMLToXMLHelper(const void *data) int result = -1; char *xml = NULL; - if (virAsprintf(&xml, "%s/interfaceschemadata/%s.xml", - abs_srcdir, (const char*)data) < 0) - return -1; + virAsprintf(&xml, "%s/interfaceschemadata/%s.xml", abs_srcdir, + (const char *)data); result = testCompareXMLToXMLFiles(xml); diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 120796b110..efd003eb58 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -151,15 +151,11 @@ testCompareXMLToDomConfigHelper(const void *data) char *xmlfile = NULL; char *jsonfile = NULL; - if (virAsprintf(&xmlfile, "%s/libxlxml2domconfigdata/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&jsonfile, "%s/libxlxml2domconfigdata/%s.json", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xmlfile, "%s/libxlxml2domconfigdata/%s.xml", abs_srcdir, info->name); + virAsprintf(&jsonfile, "%s/libxlxml2domconfigdata/%s.json", abs_srcdir, info->name); ret = testCompareXMLToDomConfig(xmlfile, jsonfile); - cleanup: VIR_FREE(xmlfile); VIR_FREE(jsonfile); return ret; diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 2a277042ce..f2d884dc15 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -71,15 +71,13 @@ testCompareXMLToConfigHelperLegacy(const void *data) char *xml = NULL; char *config = NULL; - if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s.config", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml", + abs_srcdir, info->name); + virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s.config", + abs_srcdir, info->name); result = testCompareXMLToConfigFiles(xml, config, info->expectError); - cleanup: VIR_FREE(xml); VIR_FREE(config); return result; @@ -93,15 +91,13 @@ testCompareXMLToConfigHelperV3(const void *data) char *xml = NULL; char *config = NULL; - if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s-v3.config", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml", + abs_srcdir, info->name); + virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s-v3.config", + abs_srcdir, info->name); result = testCompareXMLToConfigFiles(xml, config, info->expectError); - cleanup: VIR_FREE(xml); VIR_FREE(config); return result; diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index e871700d1d..ded35f8d4b 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -34,18 +34,16 @@ testCompareXMLToXMLHelper(const void *data) char *xml_out = NULL; int ret = -1; - if (virAsprintf(&xml_in, "%s/lxcxml2xmldata/lxc-%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&xml_out, "%s/lxcxml2xmloutdata/lxc-%s.xml", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml_in, "%s/lxcxml2xmldata/lxc-%s.xml", + abs_srcdir, info->name); + virAsprintf(&xml_out, "%s/lxcxml2xmloutdata/lxc-%s.xml", + abs_srcdir, info->name); ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, info->different ? xml_out : xml_in, !info->inactive_only, info->parse_flags, TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); - cleanup: VIR_FREE(xml_in); VIR_FREE(xml_out); return ret; diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 098b5eff09..9992afaf62 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -86,16 +86,11 @@ testCompareXMLToConfHelper(const void *data) char *inxml = NULL; char *outconf = NULL; - if (virAsprintf(&inxml, "%s/networkxml2confdata/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&outconf, "%s/networkxml2confdata/%s.conf", - abs_srcdir, info->name) < 0) { - goto cleanup; - } + virAsprintf(&inxml, "%s/networkxml2confdata/%s.xml", abs_srcdir, info->name); + virAsprintf(&outconf, "%s/networkxml2confdata/%s.conf", abs_srcdir, info->name); result = testCompareXMLToConfFiles(inxml, outconf, info->caps); - cleanup: VIR_FREE(inxml); VIR_FREE(outconf); diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c index b8e974971a..0aaebf5bc6 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -117,15 +117,13 @@ testCompareXMLToIPTablesHelper(const void *data) char *xml = NULL; char *args = NULL; - if (virAsprintf(&xml, "%s/networkxml2firewalldata/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&args, "%s/networkxml2firewalldata/%s-%s.args", - abs_srcdir, info->name, RULESTYPE) < 0) - goto cleanup; + virAsprintf(&xml, "%s/networkxml2firewalldata/%s.xml", + abs_srcdir, info->name); + virAsprintf(&args, "%s/networkxml2firewalldata/%s-%s.args", + abs_srcdir, info->name, RULESTYPE); result = testCompareXMLToArgvFiles(xml, args, info->baseargs); - cleanup: VIR_FREE(xml); VIR_FREE(args); return result; @@ -169,11 +167,7 @@ mymain(void) goto cleanup; } - if (virAsprintf(&basefile, "%s/networkxml2firewalldata/base.args", - abs_srcdir) < 0) { - ret = -1; - goto cleanup; - } + virAsprintf(&basefile, "%s/networkxml2firewalldata/base.args", abs_srcdir); if (virTestLoadFile(basefile, &baseargs) < 0) { ret = -1; diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 3d90023445..64aada5f34 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -90,17 +90,12 @@ testCompareXMLToXMLHelper(const void *data) char *inxml = NULL; char *outxml = NULL; - if (virAsprintf(&inxml, "%s/networkxml2xmlin/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&outxml, "%s/networkxml2xmlout/%s.xml", - abs_srcdir, info->name) < 0) { - goto cleanup; - } + virAsprintf(&inxml, "%s/networkxml2xmlin/%s.xml", abs_srcdir, info->name); + virAsprintf(&outxml, "%s/networkxml2xmlout/%s.xml", abs_srcdir, info->name); result = testCompareXMLToXMLFiles(inxml, outxml, info->flags, info->expectResult); - cleanup: VIR_FREE(inxml); VIR_FREE(outxml); diff --git a/tests/networkxml2xmlupdatetest.c b/tests/networkxml2xmlupdatetest.c index 69c19e800d..a76498c085 100644 --- a/tests/networkxml2xmlupdatetest.c +++ b/tests/networkxml2xmlupdatetest.c @@ -82,20 +82,17 @@ testCompareXMLToXMLHelper(const void *data) char *updatexml = NULL; char *outxml = NULL; - if (virAsprintf(&netxml, "%s/networkxml2xmlin/%s.xml", - abs_srcdir, info->netxml) < 0 || - virAsprintf(&updatexml, "%s/networkxml2xmlupdatein/%s.xml", - abs_srcdir, info->updatexml) < 0 || - virAsprintf(&outxml, "%s/networkxml2xmlupdateout/%s.xml", - abs_srcdir, info->outxml) < 0) { - goto cleanup; - } + virAsprintf(&netxml, "%s/networkxml2xmlin/%s.xml", + abs_srcdir, info->netxml); + virAsprintf(&updatexml, "%s/networkxml2xmlupdatein/%s.xml", + abs_srcdir, info->updatexml); + virAsprintf(&outxml, "%s/networkxml2xmlupdateout/%s.xml", + abs_srcdir, info->outxml); result = testCompareXMLToXMLFiles(netxml, updatexml, outxml, info->flags, info->command, info->section, info->parentIndex, info->expectFailure); - cleanup: VIR_FREE(netxml); VIR_FREE(updatexml); VIR_FREE(outxml); diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index 9248a60fbf..e8b869526d 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -72,9 +72,8 @@ testCompareXMLToXMLHelper(const void *data) int result = -1; char *xml = NULL; - if (virAsprintf(&xml, "%s/nodedevschemadata/%s.xml", - abs_srcdir, (const char*)data) < 0) - return -1; + virAsprintf(&xml, "%s/nodedevschemadata/%s.xml", abs_srcdir, + (const char *)data); result = testCompareXMLToXMLFiles(xml); diff --git a/tests/nssmock.c b/tests/nssmock.c index ea4b26ffab..be70a60790 100644 --- a/tests/nssmock.c +++ b/tests/nssmock.c @@ -55,12 +55,9 @@ getrealpath(char **newpath, const char *path) { if (STRPREFIX(path, LEASEDIR)) { - if (virAsprintfQuiet(newpath, "%s/nssdata/%s", - abs_srcdir, - path + strlen(LEASEDIR)) < 0) { - errno = ENOMEM; - return -1; - } + virAsprintfQuiet(newpath, "%s/nssdata/%s", + abs_srcdir, + path + strlen(LEASEDIR)); } else { *newpath = g_strdup(path); } diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index bef3790da2..95b6b24014 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -243,9 +243,8 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPtr inc, int ret = -1; char *xml; - if (virAsprintf(&xml, "%s/nwfilterxml2firewalldata/%s.xml", - abs_srcdir, inc->filterref) < 0) - return -1; + virAsprintf(&xml, "%s/nwfilterxml2firewalldata/%s.xml", abs_srcdir, + inc->filterref); /* create a temporary hashmap for depth-first tree traversal */ if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params, @@ -429,15 +428,13 @@ testCompareXMLToIPTablesHelper(const void *data) char *xml = NULL; char *args = NULL; - if (virAsprintf(&xml, "%s/nwfilterxml2firewalldata/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&args, "%s/nwfilterxml2firewalldata/%s-%s.args", - abs_srcdir, info->name, RULESTYPE) < 0) - goto cleanup; + virAsprintf(&xml, "%s/nwfilterxml2firewalldata/%s.xml", + abs_srcdir, info->name); + virAsprintf(&args, "%s/nwfilterxml2firewalldata/%s-%s.args", + abs_srcdir, info->name, RULESTYPE); result = testCompareXMLToArgvFiles(xml, args); - cleanup: VIR_FREE(xml); VIR_FREE(args); return result; diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index 5fc9d19d47..344dd68bc5 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -62,16 +62,11 @@ testCompareXMLToXMLHelper(const void *data) char *inxml = NULL; char *outxml = NULL; - if (virAsprintf(&inxml, "%s/nwfilterxml2xmlin/%s.xml", - abs_srcdir, tp->name) < 0 || - virAsprintf(&outxml, "%s/nwfilterxml2xmlout/%s.xml", - abs_srcdir, tp->name) < 0) { - goto cleanup; - } + virAsprintf(&inxml, "%s/nwfilterxml2xmlin/%s.xml", abs_srcdir, tp->name); + virAsprintf(&outxml, "%s/nwfilterxml2xmlout/%s.xml", abs_srcdir, tp->name); result = testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning); - cleanup: VIR_FREE(inxml); VIR_FREE(outxml); diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index c15ce9a47b..9287dc3c79 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -17,7 +17,8 @@ static int testLocateConfFile(int vpsid G_GNUC_UNUSED, char **conffile, const char *ext G_GNUC_UNUSED) { - return virAsprintf(conffile, "%s/openvzutilstest.conf", abs_srcdir); + virAsprintf(conffile, "%s/openvzutilstest.conf", abs_srcdir); + return 0; } struct testConfigParam { @@ -40,8 +41,7 @@ testReadConfigParam(const void *data G_GNUC_UNUSED) char *conf = NULL; char *value = NULL; - if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0) - return -1; + virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir); for (i = 0; i < G_N_ELEMENTS(configParams); ++i) { if (openvzReadConfigParam(conf, configParams[i].param, diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index cef9ae5fee..65fb937901 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -183,9 +183,7 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOptionPtr xmlopt, if (!(ret_test = qemuMonitorTestNewAgent(xmlopt))) return -1; - if (virAsprintf(&domain_filename, "%s/qemuagentdata/fsinfo.xml", - abs_srcdir) < 0) - goto cleanup; + virAsprintf(&domain_filename, "%s/qemuagentdata/fsinfo.xml", abs_srcdir); if (!(ret_def = virDomainDefParseFile(domain_filename, driver.caps, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 5f89d73c72..0c7c6ed4fa 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -82,8 +82,7 @@ testBackingXMLjsonXML(const void *args) if (!(propsstr = virJSONValueToString(wrapper, false))) return -1; - if (virAsprintf(&protocolwrapper, "json:%s", propsstr) < 0) - return -1; + virAsprintf(&protocolwrapper, "json:%s", propsstr); if (virStorageSourceNewFromBackingAbsolute(protocolwrapper, &jsonsrc) < 0) { @@ -163,9 +162,8 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src) srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username); - if (virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias", - NULLSTR(src->nodestorage)) < 0) - return -1; + virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias", + NULLSTR(src->nodestorage)); } if (src->encryption) { @@ -173,9 +171,8 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src) return -1; srcpriv->encinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; - if (virAsprintf(&srcpriv->encinfo->s.aes.alias, "%s-encalias", - NULLSTR(src->nodeformat)) < 0) - return -1; + virAsprintf(&srcpriv->encinfo->s.aes.alias, "%s-encalias", + NULLSTR(src->nodeformat)); } return 0; @@ -197,9 +194,7 @@ testQemuDiskXMLToProps(const void *opaque) char *xmlstr = NULL; int ret = -1; - if (virAsprintf(&xmlpath, "%s%s.xml", - testQemuDiskXMLToJSONPath, data->name) < 0) - goto cleanup; + virAsprintf(&xmlpath, "%s%s.xml", testQemuDiskXMLToJSONPath, data->name); if (virTestLoadFile(xmlpath, &xmlstr) < 0) goto cleanup; @@ -316,9 +311,7 @@ testQemuDiskXMLToPropsValidateFile(const void *opaque) if (data->fail) return EXIT_AM_SKIP; - if (virAsprintf(&jsonpath, "%s%s.json", - testQemuDiskXMLToJSONPath, data->name) < 0) - goto cleanup; + virAsprintf(&jsonpath, "%s%s.json", testQemuDiskXMLToJSONPath, data->name); for (i = 0; i < data->nprops; i++) { char *jsonstr; @@ -367,9 +360,7 @@ testQemuImageCreateLoadDiskXML(const char *name, g_autofree char *xmlpath = NULL; virStorageSourcePtr ret = NULL; - if (virAsprintf(&xmlpath, "%s%s.xml", - testQemuImageCreatePath, name) < 0) - return NULL; + virAsprintf(&xmlpath, "%s%s.xml", testQemuImageCreatePath, name); if (!(doc = virXMLParseFileCtxt(xmlpath, &ctxt))) return NULL; @@ -465,9 +456,7 @@ testQemuImageCreate(const void *opaque) virBufferTrim(&actualbuf, "\n", -1); virBufferAddLit(&actualbuf, "\n"); - if (virAsprintf(&jsonpath, "%s%s.json", - testQemuImageCreatePath, data->name) < 0) - return -1; + virAsprintf(&jsonpath, "%s%s.json", testQemuImageCreatePath, data->name); if (!(actual = virBufferContentAndReset(&actualbuf))) return -1; @@ -488,9 +477,8 @@ testQemuDiskXMLToPropsValidateFileSrcOnly(const void *opaque) if (data->fail) return EXIT_AM_SKIP; - if (virAsprintf(&jsonpath, "%s%s-srconly.json", - testQemuDiskXMLToJSONPath, data->name) < 0) - return -1; + virAsprintf(&jsonpath, "%s%s-srconly.json", testQemuDiskXMLToJSONPath, + data->name); for (i = 0; i < data->npropssrc; i++) { g_autofree char *jsonstr = NULL; diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index a9a1e75587..cf1e86c893 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -76,11 +76,10 @@ testQemuCaps(const void *opaque) unsigned int fakeMicrocodeVersion = 0; const char *p; - if (virAsprintf(&repliesFile, "%s/%s.%s.replies", - data->dataDir, data->base, data->archName) < 0 || - virAsprintf(&capsFile, "%s/%s.%s.xml", - data->dataDir, data->base, data->archName) < 0) - goto cleanup; + virAsprintf(&repliesFile, "%s/%s.%s.replies", + data->dataDir, data->base, data->archName); + virAsprintf(&capsFile, "%s/%s.%s.xml", + data->dataDir, data->base, data->archName); if (!(mon = qemuMonitorTestNewFromFileFull(repliesFile, &data->driver, NULL, NULL))) @@ -145,9 +144,8 @@ testQemuCapsCopy(const void *opaque) virQEMUCapsPtr copy = NULL; char *actual = NULL; - if (virAsprintf(&capsFile, "%s/%s.%s.xml", - data->dataDir, data->base, data->archName) < 0) - goto cleanup; + virAsprintf(&capsFile, "%s/%s.%s.xml", data->dataDir, data->base, + data->archName); if (!(caps = virCapabilitiesNew(virArchFromString(data->archName), false, false))) @@ -186,10 +184,8 @@ doCapsTest(const char *base, g_autofree char *title = NULL; g_autofree char *copyTitle = NULL; - if (virAsprintf(&title, "%s (%s)", base, archName) < 0 || - virAsprintf(©Title, "copy %s (%s)", base, archName) < 0) { - return -1; - } + virAsprintf(&title, "%s (%s)", base, archName); + virAsprintf(©Title, "copy %s (%s)", base, archName); data->base = base; data->archName = archName; diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c index f5aecaa391..f46b056c18 100644 --- a/tests/qemucaps2xmltest.c +++ b/tests/qemucaps2xmltest.c @@ -102,8 +102,7 @@ testGetCaps(char *capsData, const testQemuData *data) virArch arch = virArchFromString(data->archName); g_autofree char *binary = NULL; - if (virAsprintf(&binary, "/usr/bin/qemu-system-%s", data->archName) < 0) - goto error; + virAsprintf(&binary, "/usr/bin/qemu-system-%s", data->archName); if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) { fprintf(stderr, "failed to parse qemu capabilities flags"); @@ -142,13 +141,10 @@ testQemuCapsXML(const void *opaque) char *capsXml = NULL; virCapsPtr capsProvided = NULL; - if (virAsprintf(&xmlFile, "%s/caps.%s.xml", - data->outputDir, data->archName) < 0) - goto cleanup; + virAsprintf(&xmlFile, "%s/caps.%s.xml", data->outputDir, data->archName); - if (virAsprintf(&capsFile, "%s/%s.%s.xml", - data->inputDir, data->base, data->archName) < 0) - goto cleanup; + virAsprintf(&capsFile, "%s/%s.%s.xml", data->inputDir, data->base, + data->archName); if (virTestLoadFile(capsFile, &capsData) < 0) goto cleanup; @@ -181,8 +177,7 @@ doCapsTest(const char *base, testQemuDataPtr data = (testQemuDataPtr) opaque; g_autofree char *title = NULL; - if (virAsprintf(&title, "%s (%s)", base, archName) < 0) - return -1; + virAsprintf(&title, "%s (%s)", base, archName); data->base = base; data->archName = archName; diff --git a/tests/qemudomaincheckpointxml2xmltest.c b/tests/qemudomaincheckpointxml2xmltest.c index 4540f15ddd..7f393d68a8 100644 --- a/tests/qemudomaincheckpointxml2xmltest.c +++ b/tests/qemudomaincheckpointxml2xmltest.c @@ -120,9 +120,8 @@ testCheckpointPostParse(virDomainMomentDefPtr def) if (def->creationTime) return -1; def->creationTime = mocktime; - if (!def->name && - virAsprintf(&def->name, "%lld", def->creationTime) < 0) - return -1; + if (!def->name) + virAsprintf(&def->name, "%lld", def->creationTime); return 0; } diff --git a/tests/qemudomainsnapshotxml2xmltest.c b/tests/qemudomainsnapshotxml2xmltest.c index 66cb124f09..0a3aaac6cf 100644 --- a/tests/qemudomainsnapshotxml2xmltest.c +++ b/tests/qemudomainsnapshotxml2xmltest.c @@ -105,9 +105,8 @@ testSnapshotPostParse(virDomainMomentDefPtr def) if (def->creationTime) return -1; def->creationTime = mocktime; - if (!def->name && - virAsprintf(&def->name, "%lld", def->creationTime) < 0) - return -1; + if (!def->name) + virAsprintf(&def->name, "%lld", def->creationTime); return 0; } diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c index ad7ed7a384..01d4ebc26f 100644 --- a/tests/qemufirmwaretest.c +++ b/tests/qemufirmwaretest.c @@ -24,9 +24,7 @@ testParseFormatFW(const void *opaque) g_autofree char *expected = NULL; g_autofree char *actual = NULL; - if (virAsprintf(&path, "%s/qemufirmwaredata/%s", - abs_srcdir, filename) < 0) - return -1; + virAsprintf(&path, "%s/qemufirmwaredata/%s", abs_srcdir, filename); if (!(fw = qemuFirmwareParse(path))) return -1; diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 4ff2b38c83..04dc347fd8 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -245,15 +245,14 @@ testQemuHotplug(const void *data) qemuMonitorTestPtr test_mon = NULL; qemuDomainObjPrivatePtr priv = NULL; - if (virAsprintf(&domain_filename, "%s/qemuhotplugtestdomains/qemuhotplug-%s.xml", - abs_srcdir, test->domain_filename) < 0 || - virAsprintf(&device_filename, "%s/qemuhotplugtestdevices/qemuhotplug-%s.xml", - abs_srcdir, test->device_filename) < 0 || - virAsprintf(&result_filename, - "%s/qemuhotplugtestdomains/qemuhotplug-%s+%s.xml", - abs_srcdir, test->domain_filename, - test->device_filename) < 0) - goto cleanup; + virAsprintf(&domain_filename, "%s/qemuhotplugtestdomains/qemuhotplug-%s.xml", + abs_srcdir, test->domain_filename); + virAsprintf(&device_filename, "%s/qemuhotplugtestdevices/qemuhotplug-%s.xml", + abs_srcdir, test->device_filename); + virAsprintf(&result_filename, + "%s/qemuhotplugtestdomains/qemuhotplug-%s+%s.xml", + abs_srcdir, test->domain_filename, + test->device_filename); if (virTestLoadFile(domain_filename, &domain_xml) < 0 || virTestLoadFile(device_filename, &device_xml) < 0) @@ -409,19 +408,17 @@ testQemuHotplugCpuPrepare(const char *test, char *prefix = NULL; struct testQemuHotplugCpuData *data = NULL; - if (virAsprintf(&prefix, "%s/qemuhotplugtestcpus/%s", abs_srcdir, test) < 0) - return NULL; + virAsprintf(&prefix, "%s/qemuhotplugtestcpus/%s", abs_srcdir, test); if (VIR_ALLOC(data) < 0) goto error; data->modern = modern; - if (virAsprintf(&data->file_xml_dom, "%s-domain.xml", prefix) < 0 || - virAsprintf(&data->file_xml_res_live, "%s-result-live.xml", prefix) < 0 || - virAsprintf(&data->file_xml_res_conf, "%s-result-conf.xml", prefix) < 0 || - virAsprintf(&data->file_json_monitor, "%s-monitor.json", prefix) < 0) - goto error; + virAsprintf(&data->file_xml_dom, "%s-domain.xml", prefix); + virAsprintf(&data->file_xml_res_live, "%s-result-live.xml", prefix); + virAsprintf(&data->file_xml_res_conf, "%s-result-conf.xml", prefix); + virAsprintf(&data->file_json_monitor, "%s-monitor.json", prefix); if (virTestLoadFile(data->file_xml_dom, &data->xml_dom) < 0) goto error; diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index 490e2ef11f..8e395759e1 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -34,9 +34,8 @@ testCompareMemLock(const void *data) char *xml = NULL; int ret = -1; - if (virAsprintf(&xml, "%s/qemumemlockdata/qemumemlock-%s.xml", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/qemumemlockdata/qemumemlock-%s.xml", abs_srcdir, + info->name); if (!(def = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) { diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c index aacb905639..ded3a8ef64 100644 --- a/tests/qemumigparamstest.c +++ b/tests/qemumigparamstest.c @@ -66,9 +66,8 @@ qemuMigParamsTestXML2XML(const void *opaque) char *actualXML = NULL; int ret = -1; - if (virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml", - abs_srcdir, data->name) < 0) - goto cleanup; + virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml", abs_srcdir, + data->name); if (!(doc = virXMLParseFileCtxt(xmlFile, &ctxt))) goto cleanup; @@ -110,11 +109,10 @@ qemuMigParamsTestXML(const void *opaque) char *actualXML = NULL; int ret = -1; - if (virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply", - abs_srcdir, data->name) < 0 || - virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml", - abs_srcdir, data->name) < 0) - goto cleanup; + virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply", + abs_srcdir, data->name); + virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml", + abs_srcdir, data->name); if (!(mon = qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true))) goto cleanup; @@ -161,11 +159,10 @@ qemuMigParamsTestJSON(const void *opaque) char *actualJSON = NULL; int ret = -1; - if (virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply", - abs_srcdir, data->name) < 0 || - virAsprintf(&jsonFile, "%s/qemumigparamsdata/%s.json", - abs_srcdir, data->name) < 0) - goto cleanup; + virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply", + abs_srcdir, data->name); + virAsprintf(&jsonFile, "%s/qemumigparamsdata/%s.json", + abs_srcdir, data->name); if (!(mon = qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true))) goto cleanup; diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index c0eee921cf..c87f7db2e0 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -796,11 +796,9 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt, if (!reply) reply = ""; - if (virAsprintf(&jsonreply, "{\"return\": {%s}}", reply) < 0) - goto cleanup; + virAsprintf(&jsonreply, "{\"return\": {%s}}", reply); - if (virAsprintf(&fulllabel, "qemuMonitorJSONTestAttachChardev(%s)", label) < 0) - goto cleanup; + virAsprintf(&fulllabel, "qemuMonitorJSONTestAttachChardev(%s)", label); data.chr = chr; data.fail = fail; @@ -2459,13 +2457,12 @@ testQemuMonitorJSONGetCPUData(const void *opaque) if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema))) return -1; - if (virAsprintf(&jsonFile, - "%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.json", - abs_srcdir, data->name) < 0 || - virAsprintf(&dataFile, - "%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.data", - abs_srcdir, data->name) < 0) - goto cleanup; + virAsprintf(&jsonFile, + "%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.json", + abs_srcdir, data->name); + virAsprintf(&dataFile, + "%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.data", + abs_srcdir, data->name); if (virTestLoadFile(jsonFile, &jsonStr) < 0) goto cleanup; @@ -2712,16 +2709,15 @@ testQemuMonitorCPUInfo(const void *opaque) if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema))) return -1; - if (virAsprintf(&queryCpusFile, - "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-cpus.json", - abs_srcdir, data->name) < 0 || - virAsprintf(&queryHotpluggableFile, - "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-hotplug.json", - abs_srcdir, data->name) < 0 || - virAsprintf(&dataFile, - "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s.data", - abs_srcdir, data->name) < 0) - goto cleanup; + virAsprintf(&queryCpusFile, + "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-cpus.json", + abs_srcdir, data->name); + virAsprintf(&queryHotpluggableFile, + "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-hotplug.json", + abs_srcdir, data->name); + virAsprintf(&dataFile, + "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s.data", + abs_srcdir, data->name); if (virTestLoadFile(queryCpusFile, &queryCpusStr) < 0) goto cleanup; @@ -2816,9 +2812,8 @@ testBlockNodeNameDetect(const void *opaque) virBuffer buf = VIR_BUFFER_INITIALIZER; int ret = -1; - if (virAsprintf(&resultFile, "%s/%s%s.result", - abs_srcdir, pathprefix, testname) < 0) - goto cleanup; + virAsprintf(&resultFile, "%s/%s%s.result", abs_srcdir, pathprefix, + testname); if (!(namedNodesJson = virTestLoadFileJSON(pathprefix, testname, "-named-nodes.json", NULL))) @@ -2961,13 +2956,12 @@ testQueryJobs(const void *opaque) if (!test) return -1; - if (virAsprintf(&filenameJSON, - abs_srcdir "/qemumonitorjsondata/query-jobs-%s.json", - data->name) < 0 || - virAsprintf(&filenameResult, - abs_srcdir "/qemumonitorjsondata/query-jobs-%s.result", - data->name) < 0) - goto cleanup; + virAsprintf(&filenameJSON, + abs_srcdir "/qemumonitorjsondata/query-jobs-%s.json", + data->name); + virAsprintf(&filenameResult, + abs_srcdir "/qemumonitorjsondata/query-jobs-%s.result", + data->name); if (virTestLoadFile(filenameJSON, &fileJSON) < 0) goto cleanup; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index fb76bf185d..b7625bb157 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -145,11 +145,8 @@ qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test, } /* format the JSON error message */ - if (virAsprintf(&jsonmsg, "{ \"error\": " - " { \"desc\": \"%s\", " - " \"class\": \"UnexpectedCommand\" } }", - escapemsg) < 0) - return -1; + virAsprintf(&jsonmsg, "{ \"error\": " " { \"desc\": \"%s\", " + " \"class\": \"UnexpectedCommand\" } }", escapemsg); return qemuMonitorTestAddResponse(test, jsonmsg); } @@ -161,8 +158,7 @@ qemuMonitorTestAddUnexpectedErrorResponse(qemuMonitorTestPtr test, { g_autofree char *msg = NULL; - if (virAsprintf(&msg, "unexpected command: '%s'", command) < 0) - return -1; + virAsprintf(&msg, "unexpected command: '%s'", command); return qemuMonitorTestAddErrorResponse(test, msg); } @@ -175,9 +171,8 @@ qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTestPtr test, { g_autofree char *msg = NULL; - if (virAsprintf(&msg, "expected command '%s' got '%s'", - expectedcommand, actualcommand) < 0) - return -1; + virAsprintf(&msg, "expected command '%s' got '%s'", expectedcommand, + actualcommand); return qemuMonitorTestAddErrorResponse(test, msg); } @@ -196,11 +191,8 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...) if (virVasprintf(&msg, errmsg, msgargs) < 0) goto cleanup; - if (virAsprintf(&jsonmsg, "{ \"error\": " - " { \"desc\": \"%s\", " - " \"class\": \"UnexpectedCommand\" } }", - msg) < 0) - goto cleanup; + virAsprintf(&jsonmsg, "{ \"error\": " " { \"desc\": \"%s\", " + " \"class\": \"UnexpectedCommand\" } }", msg); ret = qemuMonitorTestAddResponse(test, jsonmsg); @@ -530,8 +522,7 @@ qemuMonitorTestProcessCommandDefaultValidate(qemuMonitorTestPtr test, if (STREQ(cmdname, "device_add")) return 0; - if (virAsprintf(&schemapath, "%s/arg-type", cmdname) < 0) - return -1; + virAsprintf(&schemapath, "%s/arg-type", cmdname); if (virQEMUQAPISchemaPathGet(schemapath, test->qapischema, &schemaroot) < 0 || !schemaroot) { @@ -649,8 +640,7 @@ qemuMonitorTestProcessCommandVerbatim(qemuMonitorTestPtr test, ret = qemuMonitorTestAddResponse(test, data->response); } else { if (data->cmderr) { - if (virAsprintf(&errmsg, "%s: %s", data->cmderr, cmdstr) < 0) - return -1; + virAsprintf(&errmsg, "%s: %s", data->cmderr, cmdstr); ret = qemuMonitorTestAddErrorResponse(test, errmsg); } else { @@ -741,8 +731,7 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTestPtr test, goto cleanup; } - if (virAsprintf(&retmsg, "{\"return\":%llu}", id) < 0) - goto cleanup; + virAsprintf(&retmsg, "{\"return\":%llu}", id); ret = qemuMonitorTestAddResponse(test, retmsg); @@ -1068,8 +1057,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, tmpdir_template = NULL; - if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0) - goto error; + virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir); if (vm) { test->vm = virObjectRef(vm); @@ -1297,9 +1285,7 @@ qemuMonitorTestFullAddItem(qemuMonitorTestPtr test, char *cmderr; int ret; - if (virAsprintf(&cmderr, "wrong expected command in %s:%zu: ", - filename, line) < 0) - return -1; + virAsprintf(&cmderr, "wrong expected command in %s:%zu: ", filename, line); ret = qemuMonitorTestAddItemVerbatim(test, command, cmderr, response); diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 50435bbd02..63bcae0f27 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -117,10 +117,7 @@ get_key(const char *path, { char *ret; - if (virAsprintf(&ret, "%s:%s", path, name) < 0) { - fprintf(stderr, "Unable to create hash table key\n"); - abort(); - } + virAsprintf(&ret, "%s:%s", path, name); return ret; } diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 1c6cefd705..e8ebbf36d8 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -45,8 +45,7 @@ prepareObjects(virQEMUDriverPtr driver, g_autofree char *domxml = NULL; g_autofree char *latestCapsFile = NULL; - if (virAsprintf(&filename, "%s/qemuxml2argvdata/%s.xml", abs_srcdir, xmlname) < 0) - return -1; + virAsprintf(&filename, "%s/qemuxml2argvdata/%s.xml", abs_srcdir, xmlname); if (virTestLoadFile(filename, &domxml) < 0) return -1; diff --git a/tests/qemuvhostusertest.c b/tests/qemuvhostusertest.c index 3e1890a88f..903e6631dc 100644 --- a/tests/qemuvhostusertest.c +++ b/tests/qemuvhostusertest.c @@ -24,9 +24,7 @@ testParseFormatVU(const void *opaque) g_autofree char *expected = NULL; g_autofree char *actual = NULL; - if (virAsprintf(&path, "%s/qemuvhostuserdata/%s", - abs_srcdir, filename) < 0) - return -1; + virAsprintf(&path, "%s/qemuvhostuserdata/%s", abs_srcdir, filename); if (!(vu = qemuVhostUserParse(path))) return -1; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index fd330df3e0..39bc3b0aef 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -106,11 +106,8 @@ fakeStoragePoolLookupByName(virConnectPtr conn, virStoragePoolPtr ret = NULL; if (STRNEQ(name, "inactive")) { - if (virAsprintf(&xmlpath, "%s/%s%s.xml", - abs_srcdir, - STORAGE_POOL_XML_PATH, - name) < 0) - return NULL; + virAsprintf(&xmlpath, "%s/%s%s.xml", abs_srcdir, + STORAGE_POOL_XML_PATH, name); if (!virFileExists(xmlpath)) { virReportError(VIR_ERR_NO_STORAGE_POOL, @@ -190,7 +187,7 @@ fakeStorageVolGetPath(virStorageVolPtr vol) { char *ret = NULL; - ignore_value(virAsprintf(&ret, "/some/%s/device/%s", vol->key, vol->name)); + virAsprintf(&ret, "/some/%s/device/%s", vol->key, vol->name); return ret; } @@ -208,11 +205,8 @@ fakeStoragePoolGetXMLDesc(virStoragePoolPtr pool, return NULL; } - if (virAsprintf(&xmlpath, "%s/%s%s.xml", - abs_srcdir, - STORAGE_POOL_XML_PATH, - pool->name) < 0) - return NULL; + virAsprintf(&xmlpath, "%s/%s%s.xml", abs_srcdir, STORAGE_POOL_XML_PATH, + pool->name); if (virTestLoadFile(xmlpath, &xmlbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -594,18 +588,14 @@ testCompareXMLToArgv(const void *data) return ret; } -static int +static void testInfoSetPaths(struct testQemuInfo *info, const char *suffix) { - if (virAsprintf(&info->infile, "%s/qemuxml2argvdata/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&info->outfile, "%s/qemuxml2argvdata/%s%s.args", - abs_srcdir, info->name, suffix ? suffix : "") < 0) { - return -1; - } - - return 0; + virAsprintf(&info->infile, "%s/qemuxml2argvdata/%s.xml", + abs_srcdir, info->name); + virAsprintf(&info->outfile, "%s/qemuxml2argvdata/%s%s.args", + abs_srcdir, info->name, suffix ? suffix : ""); } # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" @@ -713,10 +703,7 @@ mymain(void) if (testQemuInfoSetArgs(&info, capslatest, \ __VA_ARGS__, ARG_END) < 0) \ return EXIT_FAILURE; \ - if (testInfoSetPaths(&info, _suffix) < 0) { \ - VIR_TEST_DEBUG("Failed to generate paths for '%s'", _name); \ - return EXIT_FAILURE; \ - } \ + testInfoSetPaths(&info, _suffix); \ if (virTestRun("QEMU XML-2-ARGV " _name _suffix, \ testCompareXMLToArgv, &info) < 0) \ ret = -1; \ diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 89c9494e6c..679b882704 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -98,48 +98,31 @@ testInfoSetPaths(struct testQemuInfo *info, VIR_FREE(info->infile); VIR_FREE(info->outfile); - if (virAsprintf(&info->infile, "%s/qemuxml2argvdata/%s.xml", - abs_srcdir, info->name) < 0) - goto error; + virAsprintf(&info->infile, "%s/qemuxml2argvdata/%s.xml", abs_srcdir, + info->name); - if (virAsprintf(&info->outfile, - "%s/qemuxml2xmloutdata/%s-%s%s.xml", - abs_srcdir, info->name, - when == WHEN_ACTIVE ? "active" : "inactive", - suffix) < 0) - goto error; + virAsprintf(&info->outfile, "%s/qemuxml2xmloutdata/%s-%s%s.xml", + abs_srcdir, info->name, + when == WHEN_ACTIVE ? "active" : "inactive", suffix); if (!virFileExists(info->outfile)) { VIR_FREE(info->outfile); - if (virAsprintf(&info->outfile, - "%s/qemuxml2xmloutdata/%s%s.xml", - abs_srcdir, info->name, suffix) < 0) - goto error; + virAsprintf(&info->outfile, "%s/qemuxml2xmloutdata/%s%s.xml", + abs_srcdir, info->name, suffix); } return 0; - - error: - testQemuInfoClear(info); - return -1; } static const char *statusPath = abs_srcdir "/qemustatusxml2xmldata/"; -static int +static void testInfoSetStatusPaths(struct testQemuInfo *info) { - if (virAsprintf(&info->infile, "%s%s-in.xml", statusPath, info->name) < 0 || - virAsprintf(&info->outfile, "%s%s-out.xml", statusPath, info->name) < 0) - goto error; - - return 0; - - error: - testQemuInfoClear(info); - return -1; + virAsprintf(&info->infile, "%s%s-in.xml", statusPath, info->name); + virAsprintf(&info->outfile, "%s%s-out.xml", statusPath, info->name); } @@ -1283,11 +1266,11 @@ mymain(void) if (testQemuInfoSetArgs(&info, capslatest, \ ARG_QEMU_CAPS, QEMU_CAPS_LAST, \ ARG_END) < 0 || \ - qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0 || \ - testInfoSetStatusPaths(&info) < 0) { \ + qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \ VIR_TEST_DEBUG("Failed to generate status test data for '%s'", _name); \ return -1; \ } \ + testInfoSetStatusPaths(&info); \ \ if (virTestRun("QEMU status XML-2-XML " _name, \ testCompareStatusXMLToXMLFiles, &info) < 0) \ diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c index 35c7d93376..f86c99df86 100644 --- a/tests/scsihosttest.c +++ b/tests/scsihosttest.c @@ -72,13 +72,10 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath, int ret = -1; int fd = -1; - if (virAsprintfQuiet(&unique_id_path, "%s/devices/pci0000:00/%s/unique_id", - fakesysfsdir, devicepath) < 0 || - virAsprintfQuiet(&link_path, "%s/class/scsi_host/%s", - fakesysfsdir, hostname) < 0) { - fprintf(stderr, "Out of memory\n"); - goto cleanup; - } + virAsprintfQuiet(&unique_id_path, "%s/devices/pci0000:00/%s/unique_id", + fakesysfsdir, devicepath); + virAsprintfQuiet(&link_path, "%s/class/scsi_host/%s", + fakesysfsdir, hostname); /* Rather than create path & file, temporarily snip off the file to * create the path @@ -208,9 +205,7 @@ testVirFindSCSIHostByPCI(const void *data G_GNUC_UNUSED) char *ret_host = NULL; int ret = -1; - if (virAsprintf(&path_addr, "%s/%s", abs_srcdir, - "sysfs/class/scsi_host") < 0) - goto cleanup; + virAsprintf(&path_addr, "%s/%s", abs_srcdir, "sysfs/class/scsi_host"); if (!(ret_host = virSCSIHostFindByPCI(TEST_SCSIHOST_CLASS_PATH, pci_addr1, unique_id1)) || @@ -260,21 +255,14 @@ mymain(void) goto cleanup; } - if (virAsprintfQuiet(&fakesysfsdir, "%s/sys", fakerootdir) < 0) { - fprintf(stderr, "Out of memory\n"); - goto cleanup; - } + virAsprintfQuiet(&fakesysfsdir, "%s/sys", fakerootdir); if (init_scsihost_sysfs(fakesysfsdir) < 0) { fprintf(stderr, "Failed to create fakesysfs='%s'\n", fakesysfsdir); goto cleanup; } - if (virAsprintfQuiet(&scsihost_class_path, "%s/class/scsi_host", - fakesysfsdir) < 0) { - fprintf(stderr, "Out of memory\n"); - goto cleanup; - } + virAsprintfQuiet(&scsihost_class_path, "%s/class/scsi_host", fakesysfsdir); VIR_DEBUG("Reading from '%s'", scsihost_class_path); if (virTestRun("testVirReadSCSIUniqueId", diff --git a/tests/secretxml2xmltest.c b/tests/secretxml2xmltest.c index 595583346a..44f4615be8 100644 --- a/tests/secretxml2xmltest.c +++ b/tests/secretxml2xmltest.c @@ -44,18 +44,14 @@ testCompareXMLToXMLHelper(const void *data) char *outxml = NULL; const struct testInfo *info = data; - if (virAsprintf(&inxml, "%s/secretxml2xmlin/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&outxml, "%s/secretxml2xml%s/%s.xml", - abs_srcdir, - info->different ? "out" : "in", - info->name) < 0) { - goto cleanup; - } + virAsprintf(&inxml, "%s/secretxml2xmlin/%s.xml", abs_srcdir, info->name); + virAsprintf(&outxml, "%s/secretxml2xml%s/%s.xml", + abs_srcdir, + info->different ? "out" : "in", + info->name); result = testCompareXMLToXMLFiles(inxml, outxml); - cleanup: VIR_FREE(inxml); VIR_FREE(outxml); diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 9156403c51..cc0de456cd 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -60,9 +60,7 @@ testUserXattrEnabled(void) ssize_t len; const char *con_value = "system_u:object_r:svirt_image_t:s0:c41,c264"; char *path = NULL; - if (virAsprintf(&path, "%s/securityselinuxlabeldata/testxattr", - abs_builddir) < 0) - goto cleanup; + virAsprintf(&path, "%s/securityselinuxlabeldata/testxattr", abs_builddir); if (virFileMakePath(abs_builddir "/securityselinuxlabeldata") < 0 || virFileTouch(path, 0600) < 0) @@ -90,9 +88,7 @@ testSELinuxMungePath(char **path) { char *tmp; - if (virAsprintf(&tmp, "%s/securityselinuxlabeldata%s", - abs_builddir, *path) < 0) - return -1; + virAsprintf(&tmp, "%s/securityselinuxlabeldata%s", abs_builddir, *path); VIR_FREE(*path); *path = tmp; @@ -112,9 +108,8 @@ testSELinuxLoadFileList(const char *testname, *files = NULL; *nfiles = 0; - if (virAsprintf(&path, "%s/securityselinuxlabeldata/%s.txt", - abs_srcdir, testname) < 0) - goto cleanup; + virAsprintf(&path, "%s/securityselinuxlabeldata/%s.txt", abs_srcdir, + testname); if (!(fp = fopen(path, "r"))) goto cleanup; @@ -140,9 +135,8 @@ testSELinuxLoadFileList(const char *testname, *tmp = '\0'; tmp++; - if (virAsprintf(&file, "%s/securityselinuxlabeldata%s", - abs_builddir, line) < 0) - goto cleanup; + virAsprintf(&file, "%s/securityselinuxlabeldata%s", abs_builddir, + line); if (*tmp != '\0' && *tmp != '\n') { context = g_strdup(tmp); @@ -178,9 +172,8 @@ testSELinuxLoadDef(const char *testname) virDomainDefPtr def = NULL; size_t i; - if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml", - abs_srcdir, testname) < 0) - goto cleanup; + virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml", abs_srcdir, + testname); if (!(def = virDomainDefParseFile(xmlfile, driver.caps, driver.xmlopt, NULL, 0))) diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c index a5403e7136..7d50b1a303 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -158,13 +158,11 @@ mymain(void) collie_test *test = node_info_tests; - if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/pool-sheepdog.xml", - abs_srcdir) < 0) - goto cleanup; + virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/pool-sheepdog.xml", + abs_srcdir); - if (virAsprintf(&volxml, "%s/storagevolxml2xmlin/vol-sheepdog.xml", - abs_srcdir) < 0) - goto cleanup; + virAsprintf(&volxml, "%s/storagevolxml2xmlin/vol-sheepdog.xml", + abs_srcdir); #define DO_TEST_NODE(collie) \ do { \ @@ -202,7 +200,6 @@ mymain(void) ++test; } - cleanup: return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/storagepoolcapstest.c b/tests/storagepoolcapstest.c index 6b0680291e..5f66a67da6 100644 --- a/tests/storagepoolcapstest.c +++ b/tests/storagepoolcapstest.c @@ -62,10 +62,8 @@ test_virStoragePoolCapsFormat(const void *opaque) if (!(poolCaps = virStoragePoolCapsNew(driverCaps))) return -1; - if (virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml", - abs_srcdir, data->filename) < 0) { - return -1; - } + virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml", + abs_srcdir, data->filename); if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps))) return -1; diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c index 2ec7cbef66..50b79b4625 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -108,14 +108,11 @@ testCompareXMLToArgvHelper(const void *data) g_autofree char *poolxml = NULL; g_autofree char *cmdline = NULL; - if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", - abs_srcdir, info->pool) < 0) - return -1; + virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, + info->pool); - if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s%s.argv", - abs_srcdir, info->pool, info->platformSuffix) < 0 && - !info->shouldFail) - return -1; + virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s%s.argv", + abs_srcdir, info->pool, info->platformSuffix); return testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline); } diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 0f7bc27293..e4c78d3fd5 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -39,11 +39,10 @@ testCompareXMLToXMLHelper(const void *data) g_autofree char *inxml = NULL; g_autofree char *outxml = NULL; - if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml", - abs_srcdir, (const char*)data) < 0 || - virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml", - abs_srcdir, (const char*)data) < 0) - return -1; + virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml", + abs_srcdir, (const char*)data); + virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml", + abs_srcdir, (const char*)data); return testCompareXMLToXMLFiles(inxml, outxml); } diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index af90aa6953..833000a636 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -109,17 +109,13 @@ testCompareXMLToArgvFiles(bool shouldFail, } else { char *createCmdline = actualCmdline; g_autofree char *cvtCmdline = NULL; - int rc; if (!(cvtCmdline = virCommandToString(cmd, false))) goto cleanup; - rc = virAsprintf(&actualCmdline, "%s\n%s", - createCmdline, cvtCmdline); + virAsprintf(&actualCmdline, "%s\n%s", createCmdline, cvtCmdline); VIR_FREE(createCmdline); - if (rc < 0) - goto cleanup; } if (convertStep == VIR_STORAGE_VOL_ENCRYPT_NONE) @@ -162,23 +158,18 @@ testCompareXMLToArgvHelper(const void *data) g_autofree char *inputvolxml = NULL; g_autofree char *cmdline = NULL; - if (info->inputvol && + if (info->inputvol) virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml", - abs_srcdir, info->inputvol) < 0) - return -1; - if (info->inputpool && + abs_srcdir, info->inputvol); + if (info->inputpool) virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml", - abs_srcdir, info->inputpool) < 0) - return -1; - if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", - abs_srcdir, info->pool) < 0 || - virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml", - abs_srcdir, info->vol) < 0) { - return -1; - } - if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv", - abs_srcdir, info->cmdline) < 0 && !info->shouldFail) - return -1; + abs_srcdir, info->inputpool); + virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", + abs_srcdir, info->pool); + virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml", + abs_srcdir, info->vol); + virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv", + abs_srcdir, info->cmdline); return testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml, inputpoolxml, inputvolxml, diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index 0c8cecc10d..4e92d2818c 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -50,13 +50,12 @@ testCompareXMLToXMLHelper(const void *data) g_autofree char *inxml = NULL; g_autofree char *outxml = NULL; - if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", - abs_srcdir, info->pool) < 0 || - virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml", - abs_srcdir, info->name) < 0) - return -1; + virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", + abs_srcdir, info->pool); + virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml", + abs_srcdir, info->name); + virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml", + abs_srcdir, info->name); return testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags); } diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index 6c84582110..4167d4baee 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -90,16 +90,14 @@ sysinfotest_run(const char *test, testdata.func = func; - if ((decoder && - virAsprintf(&testdata.decoder, "%s/%s", abs_srcdir, decoder) < 0) || - (sysinfo && - virAsprintf(&testdata.sysinfo, "%s/%s", abs_srcdir, sysinfo) < 0) || - (cpuinfo && - virAsprintf(&testdata.cpuinfo, "%s/%s", abs_srcdir, cpuinfo) < 0) || - (expected && - virAsprintf(&testdata.expected, "%s/%s", abs_srcdir, expected) < 0)) { - goto error; - } + if (decoder) + virAsprintf(&testdata.decoder, "%s/%s", abs_srcdir, decoder); + if (sysinfo) + virAsprintf(&testdata.sysinfo, "%s/%s", abs_srcdir, sysinfo); + if (cpuinfo) + virAsprintf(&testdata.cpuinfo, "%s/%s", abs_srcdir, cpuinfo); + if (expected) + virAsprintf(&testdata.expected, "%s/%s", abs_srcdir, expected); if (virTestRun(test, testSysinfo, &testdata) < 0) goto error; diff --git a/tests/testutils.c b/tests/testutils.c index a141abc91b..3ae66d3007 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -404,8 +404,7 @@ virTestRewrapFile(const char *filename) return -1; } - if (virAsprintf(&script, "%s/test-wrap-argv.pl", abs_srcdir) < 0) - goto cleanup; + virAsprintf(&script, "%s/test-wrap-argv.pl", abs_srcdir); cmd = virCommandNewArgList(perl, script, "--in-place", filename, NULL); if (virCommandRun(cmd, NULL) < 0) @@ -664,8 +663,7 @@ virTestCompareToFile(const char *actual, if (filecontentLen > 0 && filecontent[filecontentLen - 1] == '\n' && (cmpcontentLen == 0 || cmpcontent[cmpcontentLen - 1] != '\n')) { - if (virAsprintf(&fixedcontent, "%s\n", cmpcontent) < 0) - goto failure; + virAsprintf(&fixedcontent, "%s\n", cmpcontent); cmpcontent = fixedcontent; } } @@ -691,11 +689,9 @@ virTestCompareToULL(unsigned long long expect, g_autofree char *expectStr = NULL; g_autofree char *actualStr = NULL; - if (virAsprintf(&expectStr, "%llu", expect) < 0) - return -1; + virAsprintf(&expectStr, "%llu", expect); - if (virAsprintf(&actualStr, "%llu", actual) < 0) - return -1; + virAsprintf(&actualStr, "%llu", actual); return virTestCompareToString(expectStr, actualStr); } @@ -812,9 +808,8 @@ virTestSetEnvPath(void) char *new_path = NULL; if (path) { - if (strstr(path, abs_builddir) != path && - virAsprintf(&new_path, "%s:%s", abs_builddir, path) < 0) - goto cleanup; + if (strstr(path, abs_builddir) != path) + virAsprintf(&new_path, "%s:%s", abs_builddir, path); } else { new_path = g_strdup(abs_builddir); } diff --git a/tests/testutils.h b/tests/testutils.h index 9099a77664..36d2d5ba04 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -137,9 +137,8 @@ int virTestMain(int argc, } \ if (!preload) { \ newenv = (char *) lib; \ - } else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) { \ - perror("virAsprintf"); \ - return EXIT_FAILURE; \ + } else { \ + virAsprintf(&newenv, "%s:%s", lib, preload); \ } \ setenv(PRELOAD_VAR, newenv, 1); \ FORCE_FLAT_NAMESPACE \ diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 0faa9cb84a..3b656cdd1e 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -809,8 +809,7 @@ testQemuGetLatestCapsForArch(const char *arch, const char *maxname = NULL; char *ret = NULL; - if (virAsprintf(&fullsuffix, "%s.%s", arch, suffix) < 0) - goto cleanup; + virAsprintf(&fullsuffix, "%s.%s", arch, suffix); if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0) goto cleanup; @@ -846,7 +845,7 @@ testQemuGetLatestCapsForArch(const char *arch, goto cleanup; } - ignore_value(virAsprintf(&ret, "%s/%s", TEST_QEMU_CAPS_PATH, maxname)); + virAsprintf(&ret, "%s/%s", TEST_QEMU_CAPS_PATH, maxname); cleanup: VIR_FREE(tmp); @@ -1043,10 +1042,8 @@ testQemuInfoSetArgs(struct testQemuInfo *info, if (STREQ(capsver, "latest")) { capsfile = g_strdup(virHashLookup(capslatest, capsarch)); stripmachinealiases = true; - } else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml", - TEST_QEMU_CAPS_PATH, capsver, capsarch) < 0) { - goto cleanup; - } + } else virAsprintf(&capsfile, "%s/caps_%s.%s.xml", + TEST_QEMU_CAPS_PATH, capsver, capsarch); if (!(qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(capsarch), capsfile))) { diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c index 3d6171e266..fdc2c92719 100644 --- a/tests/vboxsnapshotxmltest.c +++ b/tests/vboxsnapshotxmltest.c @@ -104,9 +104,8 @@ testCompareXMLToXMLHelper(const void *data) int result = -1; char *xml = NULL; - if (virAsprintf(&xml, "%s/vboxsnapshotxmldata/%s.vbox", - abs_srcdir, (const char*)data) < 0) - return -1; + virAsprintf(&xml, "%s/vboxsnapshotxmldata/%s.vbox", abs_srcdir, + (const char *)data); result = testCompareXMLtoXMLFiles(xml); diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 385f016174..6bbd6545ac 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -31,20 +31,19 @@ static int testBufInfiniteLoop(const void *data) * This test is a bit fragile, since it relies on virBuffer internals. */ len = buf->size - buf->use - 1; - if (virAsprintf(&addstr, "%*s", len, "a") < 0) - goto out; + virAsprintf(&addstr, "%*s", len, "a"); if (info->doEscape) virBufferEscapeString(buf, "%s", addstr); else virBufferAsprintf(buf, "%s", addstr); - ret = 0; - out: bufret = virBufferContentAndReset(buf); if (!bufret) { VIR_TEST_DEBUG("Buffer had error set"); ret = -1; + } else { + ret = 0; } VIR_FREE(addstr); diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c index 41e84a3b25..c0a1ef2e2b 100644 --- a/tests/vircaps2xmltest.c +++ b/tests/vircaps2xmltest.c @@ -45,13 +45,11 @@ test_virCapabilities(const void *opaque) char *resctrl = NULL; int ret = -1; - if (virAsprintf(&system, "%s/vircaps2xmldata/linux-%s/system", - abs_srcdir, data->filename) < 0) - goto cleanup; + virAsprintf(&system, "%s/vircaps2xmldata/linux-%s/system", abs_srcdir, + data->filename); - if (virAsprintf(&resctrl, "%s/vircaps2xmldata/linux-%s/resctrl", - abs_srcdir, data->filename) < 0) - goto cleanup; + virAsprintf(&resctrl, "%s/vircaps2xmldata/linux-%s/resctrl", abs_srcdir, + data->filename); virFileWrapperAddPrefix("/sys/devices/system", system); virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl); @@ -69,9 +67,8 @@ test_virCapabilities(const void *opaque) if (!(capsXML = virCapabilitiesFormatXML(caps))) goto cleanup; - if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s-%s.xml", - abs_srcdir, archStr, data->filename) < 0) - goto cleanup; + virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s-%s.xml", abs_srcdir, + archStr, data->filename); if (virTestCompareToFile(capsXML, path) < 0) goto cleanup; diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index 7bbaa6dd0f..4c67b9ad4e 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -376,9 +376,8 @@ static void init_sysfs(void) VIR_FREE(fakesysfscgroupdir); - if (virAsprintfQuiet(&fakesysfscgroupdir, "%s%s", - fakerootdir, SYSFS_CGROUP_PREFIX) < 0) - abort(); + virAsprintfQuiet(&fakesysfscgroupdir, "%s%s", + fakerootdir, SYSFS_CGROUP_PREFIX); if (virFileMakePath(fakesysfscgroupdir) < 0) { fprintf(stderr, "Cannot create %s\n", fakesysfscgroupdir); @@ -459,10 +458,8 @@ FILE *fopen(const char *path, const char *mode) errno = EACCES; return NULL; } - if (virAsprintfQuiet(&filepath, "%s/vircgroupdata/%s.%s", - abs_srcdir, filename, type) < 0) { - abort(); - } + virAsprintfQuiet(&filepath, "%s/vircgroupdata/%s.%s", + abs_srcdir, filename, type); rc = real_fopen(filepath, mode); free(filepath); return rc; diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index cec07580ac..224e8116dd 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -189,10 +189,7 @@ testCgroupDetectMounts(const void *args) setenv("VIR_CGROUP_MOCK_FILENAME", data->file, 1); - if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", - abs_srcdir, data->file) < 0) { - goto cleanup; - } + virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", abs_srcdir, data->file); if (virCgroupNewSelf(&group) < 0) { if (data->fail) diff --git a/tests/virconftest.c b/tests/virconftest.c index 1ad34caec6..c6d8ff2272 100644 --- a/tests/virconftest.c +++ b/tests/virconftest.c @@ -39,11 +39,8 @@ static int testConfRoundTrip(const void *opaque) char *srcfile = NULL; char *dstfile = NULL; - if (virAsprintf(&srcfile, "%s/virconfdata/%s.conf", - abs_srcdir, name) < 0 || - virAsprintf(&dstfile, "%s/virconfdata/%s.out", - abs_srcdir, name) < 0) - goto cleanup; + virAsprintf(&srcfile, "%s/virconfdata/%s.conf", abs_srcdir, name); + virAsprintf(&dstfile, "%s/virconfdata/%s.out", abs_srcdir, name); if (VIR_ALLOC_N_QUIET(buffer, len) < 0) { fprintf(stderr, "out of memory\n"); diff --git a/tests/virfilemock.c b/tests/virfilemock.c index 00efb820ad..e32d749d52 100644 --- a/tests/virfilemock.c +++ b/tests/virfilemock.c @@ -188,7 +188,7 @@ canonicalize_file_name(const char *path) char *ret; if ((p = STRSKIP(path, "/some/symlink"))) - ignore_value(virAsprintfQuiet(&ret, "/gluster%s", p)); + virAsprintfQuiet(&ret, "/gluster%s", p); else ret = g_strdup(path); diff --git a/tests/virfiletest.c b/tests/virfiletest.c index ed0daf8478..ba947129be 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -325,8 +325,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) bool actual; int ret = -1; - if (virAsprintf(&mtabFile, abs_srcdir "/virfiledata/%s", data->mtabFile) < 0) - return -1; + virAsprintf(&mtabFile, abs_srcdir "/virfiledata/%s", data->mtabFile); if (setenv("LIBVIRT_MTAB", mtabFile, 1) < 0) { fprintf(stderr, "Unable to set env variable\n"); diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c index b6032f88fd..765b3b31d9 100644 --- a/tests/virfilewrapper.c +++ b/tests/virfilewrapper.c @@ -124,9 +124,7 @@ virMockStatRedirect(const char *path, char **newpath) if (!tmp) continue; - if (virAsprintfQuiet(newpath, "%s%s", overrides[i], tmp) < 0) - return -1; - + virAsprintfQuiet(newpath, "%s%s", overrides[i], tmp); break; } diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 81a126ff73..7b1b1a6d89 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -55,13 +55,12 @@ linuxTestCompareFiles(const char *cpuinfofile, } VIR_FORCE_FCLOSE(cpuinfo); - if (virAsprintf(&actualData, - "CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " - "Cores: %u, Threads: %u\n", - nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo), - nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets, - nodeinfo.cores, nodeinfo.threads) < 0) - goto fail; + virAsprintf(&actualData, + "CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " + "Cores: %u, Threads: %u\n", + nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo), + nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets, + nodeinfo.cores, nodeinfo.threads); if (virTestCompareToFile(actualData, outputfile) < 0) goto fail; @@ -177,20 +176,17 @@ linuxTestHostCPU(const void *opaque) struct linuxTestHostCPUData *data = (struct linuxTestHostCPUData *) opaque; const char *archStr = virArchToString(data->arch); - if (virAsprintf(&sysfs_prefix, "%s/virhostcpudata/linux-%s", - abs_srcdir, data->testName) < 0 || - virAsprintf(&cpuinfo, "%s/virhostcpudata/linux-%s-%s.cpuinfo", - abs_srcdir, archStr, data->testName) < 0 || - virAsprintf(&output, "%s/virhostcpudata/linux-%s-%s.expected", - abs_srcdir, archStr, data->testName) < 0) { - goto cleanup; - } + virAsprintf(&sysfs_prefix, "%s/virhostcpudata/linux-%s", + abs_srcdir, data->testName); + virAsprintf(&cpuinfo, "%s/virhostcpudata/linux-%s-%s.cpuinfo", + abs_srcdir, archStr, data->testName); + virAsprintf(&output, "%s/virhostcpudata/linux-%s-%s.expected", + abs_srcdir, archStr, data->testName); virFileWrapperAddPrefix(SYSFS_SYSTEM_PATH, sysfs_prefix); result = linuxTestCompareFiles(cpuinfo, data->arch, output); virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH); - cleanup: VIR_FREE(cpuinfo); VIR_FREE(output); VIR_FREE(sysfs_prefix); @@ -211,16 +207,14 @@ linuxTestNodeCPUStats(const void *data) char *cpustatfile = NULL; char *outfile = NULL; - if (virAsprintf(&cpustatfile, "%s/virhostcpudata/linux-cpustat-%s.stat", - abs_srcdir, testData->name) < 0 || - virAsprintf(&outfile, "%s/virhostcpudata/linux-cpustat-%s.out", - abs_srcdir, testData->name) < 0) - goto fail; + virAsprintf(&cpustatfile, "%s/virhostcpudata/linux-cpustat-%s.stat", + abs_srcdir, testData->name); + virAsprintf(&outfile, "%s/virhostcpudata/linux-cpustat-%s.out", + abs_srcdir, testData->name); result = linuxCPUStatsCompareFiles(cpustatfile, testData->ncpus, outfile); - fail: VIR_FREE(cpustatfile); VIR_FREE(outfile); return result; diff --git a/tests/virjsontest.c b/tests/virjsontest.c index f72e70879b..75c70a49c9 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -26,11 +26,10 @@ testJSONFromFile(const void *data) g_autofree char *outfile = NULL; g_autofree char *actual = NULL; - if (virAsprintf(&infile, "%s/virjsondata/parse-%s-in.json", - abs_srcdir, info->name) < 0 || - virAsprintf(&outfile, "%s/virjsondata/parse-%s-out.json", - abs_srcdir, info->name) < 0) - return -1; + virAsprintf(&infile, "%s/virjsondata/parse-%s-in.json", + abs_srcdir, info->name); + virAsprintf(&outfile, "%s/virjsondata/parse-%s-out.json", + abs_srcdir, info->name); if (virTestLoadFile(infile, &indata) < 0) return -1; @@ -114,11 +113,10 @@ testJSONAddRemove(const void *data) g_autofree char *outfile = NULL; g_autofree char *actual = NULL; - if (virAsprintf(&infile, "%s/virjsondata/add-remove-%s-in.json", - abs_srcdir, info->name) < 0 || - virAsprintf(&outfile, "%s/virjsondata/add-remove-%s-out.json", - abs_srcdir, info->name) < 0) - return -1; + virAsprintf(&infile, "%s/virjsondata/add-remove-%s-in.json", + abs_srcdir, info->name); + virAsprintf(&outfile, "%s/virjsondata/add-remove-%s-out.json", + abs_srcdir, info->name); if (virTestLoadFile(infile, &indata) < 0) return -1; @@ -350,11 +348,10 @@ testJSONDeflatten(const void *data) g_autofree char *outfile = NULL; g_autofree char *actual = NULL; - if (virAsprintf(&infile, "%s/virjsondata/deflatten-%s-in.json", - abs_srcdir, info->name) < 0 || - virAsprintf(&outfile, "%s/virjsondata/deflatten-%s-out.json", - abs_srcdir, info->name) < 0) - return -1; + virAsprintf(&infile, "%s/virjsondata/deflatten-%s-in.json", + abs_srcdir, info->name); + virAsprintf(&outfile, "%s/virjsondata/deflatten-%s-out.json", + abs_srcdir, info->name); if (virTestLoadFile(infile, &indata) < 0) return -1; diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c index 995aff1178..17880728e7 100644 --- a/tests/virmacmaptest.c +++ b/tests/virmacmaptest.c @@ -41,9 +41,7 @@ testMACLookup(const void *opaque) char *file = NULL; int ret = -1; - if (virAsprintf(&file, "%s/virmacmaptestdata/%s.json", - abs_srcdir, data->file) < 0) - goto cleanup; + virAsprintf(&file, "%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); if (!(mgr = virMacMapNew(file))) goto cleanup; @@ -94,9 +92,7 @@ testMACRemove(const void *opaque) char *file = NULL; int ret = -1; - if (virAsprintf(&file, "%s/virmacmaptestdata/%s.json", - abs_srcdir, data->file) < 0) - goto cleanup; + virAsprintf(&file, "%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); if (!(mgr = virMacMapNew(file))) goto cleanup; @@ -131,9 +127,7 @@ testMACFlush(const void *opaque) char *str = NULL; int ret = -1; - if (virAsprintf(&file, "%s/virmacmaptestdata/%s.json", - abs_srcdir, data->file) < 0) - goto cleanup; + virAsprintf(&file, "%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); if (virMacMapDumpStr(data->mgr, &str) < 0) goto cleanup; diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index f0e91763b8..2dfa04e83f 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -295,13 +295,11 @@ static int testExecRestart(const void *opaque) goto cleanup; } - if (virAsprintf(&infile, "%s/virnetdaemondata/input-data-%s.json", - abs_srcdir, data->jsonfile) < 0) - goto cleanup; + virAsprintf(&infile, "%s/virnetdaemondata/input-data-%s.json", abs_srcdir, + data->jsonfile); - if (virAsprintf(&outfile, "%s/virnetdaemondata/output-data-%s.json", - abs_srcdir, data->jsonfile) < 0) - goto cleanup; + virAsprintf(&outfile, "%s/virnetdaemondata/output-data-%s.json", + abs_srcdir, data->jsonfile); if (virFileReadAll(infile, 8192, &injsonstr) < 0) goto cleanup; diff --git a/tests/virnetdevmock.c b/tests/virnetdevmock.c index 9724a1bc1f..574a26af2d 100644 --- a/tests/virnetdevmock.c +++ b/tests/virnetdevmock.c @@ -30,12 +30,8 @@ virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname, const char *file) { - if (virAsprintfQuiet(pf_sysfs_device_link, "%s/%s/%s", - NET_DEV_TEST_DATA_PREFIX, ifname, file) < 0) { - fprintf(stderr, "Out of memory\n"); - abort(); - } - + virAsprintfQuiet(pf_sysfs_device_link, "%s/%s/%s", + NET_DEV_TEST_DATA_PREFIX, ifname, file); return 0; } #else diff --git a/tests/virnetdevopenvswitchtest.c b/tests/virnetdevopenvswitchtest.c index 3beb4af149..7b814474b7 100644 --- a/tests/virnetdevopenvswitchtest.c +++ b/tests/virnetdevopenvswitchtest.c @@ -38,9 +38,8 @@ testInterfaceParseStats(const void *opaque) g_autofree char *buf = NULL; virDomainInterfaceStatsStruct actual; - if (virAsprintf(&filename, "%s/virnetdevopenvswitchdata/%s", - abs_srcdir, data->filename) < 0) - return -1; + virAsprintf(&filename, "%s/virnetdevopenvswitchdata/%s", abs_srcdir, + data->filename); if (virFileReadAll(filename, 1024, &buf) < 0) return -1; diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 0934842252..29568eea1a 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -196,8 +196,7 @@ testSocketAccept(const void *opaque) VIR_WARN("Failed to create temporary directory"); goto cleanup; } - if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0) - goto cleanup; + virAsprintf(&path, "%s/test.sock", tmpdir); if (virNetSocketNewListenUNIX(path, 0700, -1, getegid(), &usock) < 0) goto cleanup; @@ -321,8 +320,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED) VIR_WARN("Failed to create temporary directory"); goto cleanup; } - if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0) - goto cleanup; + virAsprintf(&path, "%s/test.sock", tmpdir); if (virNetSocketNewListenUNIX(path, 0700, -1, getegid(), &lsock) < 0) goto cleanup; diff --git a/tests/virnetworkportxml2xmltest.c b/tests/virnetworkportxml2xmltest.c index 973fee5747..89f9de0c17 100644 --- a/tests/virnetworkportxml2xmltest.c +++ b/tests/virnetworkportxml2xmltest.c @@ -66,13 +66,11 @@ testCompareXMLToXMLHelper(const void *data) int ret = -1; char *xml = NULL; - if (virAsprintf(&xml, "%s/virnetworkportxml2xmldata/%s.xml", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir, + info->name); ret = testCompareXMLToXMLFiles(xml); - cleanup: VIR_FREE(xml); return ret; diff --git a/tests/virnumamock.c b/tests/virnumamock.c index 3eefb7ccee..faff8bb4a2 100644 --- a/tests/virnumamock.c +++ b/tests/virnumamock.c @@ -43,8 +43,7 @@ virNumaIsAvailable(void) if (numa_avail < 0) { char *sysfs_node_path = NULL; - if (virAsprintfQuiet(&sysfs_node_path, "%s/node", SYSFS_SYSTEM_PATH) < 0) - return false; + virAsprintfQuiet(&sysfs_node_path, "%s/node", SYSFS_SYSTEM_PATH); numa_avail = virFileExists(sysfs_node_path); diff --git a/tests/virnwfilterbindingxml2xmltest.c b/tests/virnwfilterbindingxml2xmltest.c index bba63e9564..d5ace8f89f 100644 --- a/tests/virnwfilterbindingxml2xmltest.c +++ b/tests/virnwfilterbindingxml2xmltest.c @@ -72,14 +72,11 @@ testCompareXMLToXMLHelper(const void *data) const test_parms *tp = data; char *xml = NULL; - if (virAsprintf(&xml, "%s/virnwfilterbindingxml2xmldata/%s.xml", - abs_srcdir, tp->name) < 0) { - goto cleanup; - } + virAsprintf(&xml, "%s/virnwfilterbindingxml2xmldata/%s.xml", abs_srcdir, + tp->name); result = testCompareXMLToXMLFiles(xml); - cleanup: VIR_FREE(xml); return result; diff --git a/tests/virpcimock.c b/tests/virpcimock.c index d7dc0b00f0..a6bdad7a75 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -186,8 +186,7 @@ make_file(const char *path, if (value && len == -1) len = strlen(value); - if (virAsprintfQuiet(&filepath, "%s/%s", path, name) < 0) - ABORT_OOM(); + virAsprintfQuiet(&filepath, "%s/%s", path, name); if ((fd = real_open(filepath, O_CREAT|O_WRONLY, 0666)) < 0) ABORT("Unable to open: %s", filepath); @@ -204,8 +203,7 @@ make_dir(const char *path, { g_autofree char *dirpath = NULL; - if (virAsprintfQuiet(&dirpath, "%s/%s", path, name) < 0) - ABORT_OOM(); + virAsprintfQuiet(&dirpath, "%s/%s", path, name); if (virFileMakePath(dirpath) < 0) ABORT("Unable to create: %s", dirpath); @@ -218,8 +216,7 @@ make_symlink(const char *path, { g_autofree char *filepath = NULL; - if (virAsprintfQuiet(&filepath, "%s/%s", path, name) < 0) - ABORT_OOM(); + virAsprintfQuiet(&filepath, "%s/%s", path, name); if (symlink(target, filepath) < 0) ABORT("Unable to create symlink filepath -> target"); @@ -235,10 +232,7 @@ pci_read_file(const char *path, int fd = -1; g_autofree char *newpath = NULL; - if (virAsprintfQuiet(&newpath, "%s/%s", fakerootdir, path) < 0) { - errno = ENOMEM; - goto cleanup; - } + virAsprintfQuiet(&newpath, "%s/%s", fakerootdir, path); if ((fd = real_open(newpath, O_RDWR)) < 0) goto cleanup; @@ -275,19 +269,13 @@ getrealpath(char **newpath, init_env(); if (STRPREFIX(path, SYSFS_PCI_PREFIX)) { - if (virAsprintfQuiet(newpath, "%s/sys/bus/pci/%s", - fakerootdir, - path + strlen(SYSFS_PCI_PREFIX)) < 0) { - errno = ENOMEM; - return -1; - } + virAsprintfQuiet(newpath, "%s/sys/bus/pci/%s", + fakerootdir, + path + strlen(SYSFS_PCI_PREFIX)); } else if (pathPrefixIsMocked(path)) { - if (virAsprintfQuiet(newpath, "%s/%s", - fakerootdir, - path) < 0) { - errno = ENOMEM; - return -1; - } + virAsprintfQuiet(newpath, "%s/%s", + fakerootdir, + path); } else { *newpath = g_strdup(path); } @@ -368,9 +356,9 @@ pci_address_format(struct pciDeviceAddress const *addr) { char *ret; - ignore_value(virAsprintfQuiet(&ret, ADDR_STR_FMT, - addr->domain, addr->bus, - addr->device, addr->function)); + virAsprintfQuiet(&ret, ADDR_STR_FMT, + addr->domain, addr->bus, + addr->device, addr->function); return ret; } @@ -405,13 +393,13 @@ pci_device_get_path(const struct pciDevice *dev, * and then they are just symlinked to /sys/bus/pci/devices/ */ if (file) { - ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s/%s", - prefix, dev->addr.domain, dev->addr.bus, - devid, file)); + virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s/%s", + prefix, dev->addr.domain, dev->addr.bus, + devid, file); } else { - ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s", - prefix, dev->addr.domain, dev->addr.bus, - devid)); + virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s", + prefix, dev->addr.domain, dev->addr.bus, + devid); } return ret; @@ -427,9 +415,8 @@ pci_device_create_iommu(const struct pciDevice *dev, char tmp[256]; size_t i; - if (virAsprintfQuiet(&iommuPath, "%s/sys/kernel/iommu_groups/%d/devices/", - fakerootdir, dev->iommuGroup) < 0) - ABORT_OOM(); + virAsprintfQuiet(&iommuPath, "%s/sys/kernel/iommu_groups/%d/devices/", + fakerootdir, dev->iommuGroup); if (virFileMakePath(iommuPath) < 0) ABORT("Unable to create: %s", iommuPath); @@ -492,11 +479,11 @@ pci_device_new_from_stub(const struct pciDevice *data) c = strchr(c, ':'); } - if (VIR_ALLOC_QUIET(dev) < 0 || - virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config", - abs_srcdir, id) < 0) + if (VIR_ALLOC_QUIET(dev) < 0) ABORT_OOM(); + virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config", abs_srcdir, id); + memcpy(dev, data, sizeof(*dev)); if (!(devpath = pci_device_get_path(dev, NULL, true))) @@ -557,8 +544,7 @@ pci_device_new_from_stub(const struct pciDevice *data) ABORT("@tmp overflow"); } - if (virAsprintfQuiet(&devsympath, "%s" SYSFS_PCI_PREFIX "devices", fakerootdir) < 0) - ABORT_OOM(); + virAsprintfQuiet(&devsympath, "%s" SYSFS_PCI_PREFIX "devices", fakerootdir); make_symlink(devsympath, devid, tmp); @@ -639,12 +625,9 @@ pci_vfio_release_iommu(struct pciDevice *device) pciIommuGroups[i]->nDevicesBoundToVFIO--; if (!pciIommuGroups[i]->nDevicesBoundToVFIO) { - if (virAsprintfQuiet(&vfiopath, "%s/dev/vfio/%d", - fakerootdir, - device->iommuGroup) < 0) { - errno = ENOMEM; - return -1; - } + virAsprintfQuiet(&vfiopath, "%s/dev/vfio/%d", + fakerootdir, + device->iommuGroup); if (unlink(vfiopath) < 0) return -1; @@ -668,12 +651,9 @@ pci_vfio_lock_iommu(struct pciDevice *device) continue; if (pciIommuGroups[i]->nDevicesBoundToVFIO == 0) { - if (virAsprintfQuiet(&vfiopath, "%s/dev/vfio/%d", - fakerootdir, - device->iommuGroup) < 0) { - errno = ENOMEM; - goto cleanup; - } + virAsprintfQuiet(&vfiopath, "%s/dev/vfio/%d", + fakerootdir, + device->iommuGroup); if ((fd = real_open(vfiopath, O_CREAT)) < 0) goto cleanup; @@ -705,11 +685,11 @@ pci_driver_get_path(const struct pciDriver *driver, prefix = fakerootdir; if (file) { - ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s/%s", - prefix, driver->name, file)); + virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s/%s", + prefix, driver->name, file); } else { - ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s", - prefix, driver->name)); + virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s", + prefix, driver->name); } return ret; @@ -991,9 +971,7 @@ init_env(void) if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR"))) ABORT("Missing LIBVIRT_FAKE_ROOT_DIR env variable\n"); - if (virAsprintfQuiet(&tmp, "%s%s", - fakerootdir, SYSFS_PCI_PREFIX) < 0) - ABORT_OOM(); + virAsprintfQuiet(&tmp, "%s%s", fakerootdir, SYSFS_PCI_PREFIX); if (virFileMakePath(tmp) < 0) ABORT("Unable to create: %s", tmp); @@ -1004,8 +982,7 @@ init_env(void) /* Create /dev/vfio/ dir and /dev/vfio/vfio file */ VIR_FREE(tmp); - if (virAsprintfQuiet(&tmp, "%s/dev/vfio", fakerootdir) < 0) - ABORT_OOM(); + virAsprintfQuiet(&tmp, "%s/dev/vfio", fakerootdir); if (virFileMakePath(tmp) < 0) ABORT("Unable to create: %s", tmp); diff --git a/tests/virpcitest.c b/tests/virpcitest.c index de2ffc7d41..20eb2caea9 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -349,11 +349,8 @@ mymain(void) domain, bus, slot, function, NULL \ }; \ char *label = NULL; \ - if (virAsprintf(&label, "%s(%04x:%02x:%02x.%x)", \ - #fnc, domain, bus, slot, function) < 0) { \ - ret = -1; \ - break; \ - } \ + virAsprintf(&label, "%s(%04x:%02x:%02x.%x)", \ + #fnc, domain, bus, slot, function); \ if (virTestRun(label, fnc, &data) < 0) \ ret = -1; \ VIR_FREE(label); \ @@ -365,12 +362,9 @@ mymain(void) domain, bus, slot, function, driver \ }; \ char *label = NULL; \ - if (virAsprintf(&label, "PCI driver %04x:%02x:%02x.%x is %s", \ - domain, bus, slot, function, \ - NULLSTR(driver)) < 0) { \ - ret = -1; \ - break; \ - } \ + virAsprintf(&label, "PCI driver %04x:%02x:%02x.%x is %s", \ + domain, bus, slot, function, \ + NULLSTR(driver)); \ if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \ &data) < 0) \ ret = -1; \ diff --git a/tests/virrandommock.c b/tests/virrandommock.c index a74776efa3..eff72a8aa7 100644 --- a/tests/virrandommock.c +++ b/tests/virrandommock.c @@ -53,8 +53,9 @@ uint64_t virRandomBits(int nbits) int virRandomGenerateWWN(char **wwn, const char *virt_type G_GNUC_UNUSED) { - return virAsprintf(wwn, "5100000%09llx", - (unsigned long long)virRandomBits(36)); + virAsprintf(wwn, "5100000%09llx", + (unsigned long long)virRandomBits(36)); + return 0; } diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c index 34882ac127..71870e9f3f 100644 --- a/tests/virresctrltest.c +++ b/tests/virresctrltest.c @@ -26,17 +26,14 @@ test_virResctrlGetUnused(const void *opaque) char *schemata_file; virCapsPtr caps = NULL; - if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system", - abs_srcdir, data->filename) < 0) - goto cleanup; + virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system", abs_srcdir, + data->filename); - if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl", - abs_srcdir, data->filename) < 0) - goto cleanup; + virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl", + abs_srcdir, data->filename); - if (virAsprintf(&schemata_file, "%s/virresctrldata/%s.schemata", - abs_srcdir, data->filename) < 0) - goto cleanup; + virAsprintf(&schemata_file, "%s/virresctrldata/%s.schemata", abs_srcdir, + data->filename); virFileWrapperAddPrefix("/sys/devices/system", system_dir); virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir); diff --git a/tests/virschematest.c b/tests/virschematest.c index dabbc02163..1370068601 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -87,12 +87,9 @@ testSchemaDir(const char *schema, if (ent->d_name[0] == '.') continue; - if (virAsprintf(&xml_path, "%s/%s", dir_path, ent->d_name) < 0) - goto cleanup; + virAsprintf(&xml_path, "%s/%s", dir_path, ent->d_name); - if (virAsprintf(&test_name, "Checking %s against %s", - ent->d_name, schema) < 0) - goto cleanup; + virAsprintf(&test_name, "Checking %s against %s", ent->d_name, schema); data.xml_path = xml_path; if (virTestRun(test_name, testSchemaFile, &data) < 0) @@ -105,7 +102,6 @@ testSchemaDir(const char *schema, if (rc < 0) ret = -1; - cleanup: VIR_FREE(test_name); VIR_FREE(xml_path); VIR_DIR_CLOSE(dir); @@ -124,16 +120,12 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr validator, ...) va_start(args, validator); while ((dir = va_arg(args, char *))) { - if (virAsprintf(&dir_path, "%s/%s", abs_srcdir, dir) < 0) { - ret = -1; - goto cleanup; - } + virAsprintf(&dir_path, "%s/%s", abs_srcdir, dir); if (testSchemaDir(schema, validator, dir_path) < 0) ret = -1; VIR_FREE(dir_path); } - cleanup: VIR_FREE(dir_path); va_end(args); return ret; @@ -147,9 +139,8 @@ testSchemaGrammar(const void *opaque) char *schema_path; int ret = -1; - if (virAsprintf(&schema_path, "%s/docs/schemas/%s", - abs_top_srcdir, data->schema) < 0) - return -1; + virAsprintf(&schema_path, "%s/docs/schemas/%s", abs_top_srcdir, + data->schema); if (!(data->validator = virXMLValidatorInit(schema_path))) goto cleanup; diff --git a/tests/virscsitest.c b/tests/virscsitest.c index 99374cc80c..0d2ddd3b6a 100644 --- a/tests/virscsitest.c +++ b/tests/virscsitest.c @@ -167,11 +167,9 @@ create_symlink(const char *tmpdir, const char *src_name, const char *dst_name) char *src_path = NULL; char *dst_path = NULL; - if (virAsprintf(&src_path, "%s/%s", virscsi_prefix, src_name) < 0) - goto cleanup; + virAsprintf(&src_path, "%s/%s", virscsi_prefix, src_name); - if (virAsprintf(&dst_path, "%s/%s", tmpdir, dst_name) < 0) - goto cleanup; + virAsprintf(&dst_path, "%s/%s", tmpdir, dst_name); if (symlink(src_path, dst_path) < 0) { VIR_WARN("Failed to create symlink '%s' to '%s'", src_path, dst_path); @@ -194,10 +192,7 @@ mymain(void) char *tmpdir = NULL; char template[] = "/tmp/libvirt_XXXXXX"; - if (virAsprintf(&virscsi_prefix, "%s" VIR_SCSI_DATA, abs_srcdir) < 0) { - ret = -1; - goto cleanup; - } + virAsprintf(&virscsi_prefix, "%s" VIR_SCSI_DATA, abs_srcdir); tmpdir = mkdtemp(template); diff --git a/tests/virshtest.c b/tests/virshtest.c index fee6833c9b..475933a93c 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -252,9 +252,8 @@ mymain(void) { int ret = 0; - if (virAsprintf(&custom_uri, "test://%s/../examples/xml/test/testnode.xml", - abs_srcdir) < 0) - return EXIT_FAILURE; + virAsprintf(&custom_uri, "test://%s/../examples/xml/test/testnode.xml", + abs_srcdir); if (virTestRun("virsh list (default)", testCompareListDefault, NULL) != 0) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 8f1d93fa5a..af1b4fc43f 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -138,13 +138,12 @@ testPrepImages(void) compat = true; VIR_FREE(buf); - if (virAsprintf(&absraw, "%s/raw", datadir) < 0 || - virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 || - virAsprintf(&abswrap, "%s/wrap", datadir) < 0 || - virAsprintf(&absqed, "%s/qed", datadir) < 0 || - virAsprintf(&absdir, "%s/dir", datadir) < 0 || - virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0) - goto cleanup; + virAsprintf(&absraw, "%s/raw", datadir); + virAsprintf(&absqcow2, "%s/qcow2", datadir); + virAsprintf(&abswrap, "%s/wrap", datadir); + virAsprintf(&absqed, "%s/qed", datadir); + virAsprintf(&absdir, "%s/dir", datadir); + virAsprintf(&abslink2, "%s/sub/link2", datadir); if (virFileMakePath(datadir "/sub") < 0) { fprintf(stderr, "unable to create directory %s\n", datadir "/sub"); @@ -160,8 +159,8 @@ testPrepImages(void) goto cleanup; } - if (virAsprintf(&buf, "%1024d", 0) < 0 || - virFileWriteStr("raw", buf, 0600) < 0) { + virAsprintf(&buf, "%1024d", 0); + if (virFileWriteStr("raw", buf, 0600) < 0) { fprintf(stderr, "unable to create raw file\n"); goto cleanup; } @@ -322,30 +321,28 @@ testStorageChain(const void *args) return -1; } - if (virAsprintf(&expect, - testStorageChainFormat, i, - NULLSTR(data->files[i]->path), - NULLSTR(data->files[i]->expBackingStoreRaw), - data->files[i]->expCapacity, - data->files[i]->expEncrypted, - NULLSTR(data->files[i]->pathRel), - data->files[i]->type, - data->files[i]->format, - virStorageNetProtocolTypeToString(data->files[i]->protocol), - NULLSTR(data->files[i]->hostname)) < 0 || - virAsprintf(&actual, - testStorageChainFormat, i, - NULLSTR(elt->path), - NULLSTR(elt->backingStoreRaw), - elt->capacity, - !!elt->encryption, - NULLSTR(elt->relPath), - elt->type, - elt->format, - virStorageNetProtocolTypeToString(elt->protocol), - NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)) < 0) { - return -1; - } + virAsprintf(&expect, + testStorageChainFormat, i, + NULLSTR(data->files[i]->path), + NULLSTR(data->files[i]->expBackingStoreRaw), + data->files[i]->expCapacity, + data->files[i]->expEncrypted, + NULLSTR(data->files[i]->pathRel), + data->files[i]->type, + data->files[i]->format, + virStorageNetProtocolTypeToString(data->files[i]->protocol), + NULLSTR(data->files[i]->hostname)); + virAsprintf(&actual, + testStorageChainFormat, i, + NULLSTR(elt->path), + NULLSTR(elt->backingStoreRaw), + elt->capacity, + !!elt->encryption, + NULLSTR(elt->relPath), + elt->type, + elt->format, + virStorageNetProtocolTypeToString(elt->protocol), + NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)); if (STRNEQ(expect, actual)) { virTestDifference(stderr, expect, actual); return -1; diff --git a/tests/virtestmock.c b/tests/virtestmock.c index e0f9c6c2a1..7c10a045b3 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -109,9 +109,8 @@ checkPath(const char *path, char *relPath = NULL; char *crippledPath = NULL; - if (path[0] != '/' && - virAsprintfQuiet(&relPath, "./%s", path) < 0) - goto error; + if (path[0] != '/') + virAsprintfQuiet(&relPath, "./%s", path); /* Le sigh. virFileCanonicalizePath() expects @path to exist, otherwise * it will return an error. So if we are called over an non-existent @@ -141,9 +140,6 @@ checkPath(const char *path, VIR_FREE(fullPath); return; - error: - fprintf(stderr, "Out of memory\n"); - abort(); } diff --git a/tests/virusbmock.c b/tests/virusbmock.c index cace140725..7b7d24ac77 100644 --- a/tests/virusbmock.c +++ b/tests/virusbmock.c @@ -53,17 +53,12 @@ static char *get_fake_path(const char *real_path) const char *p = NULL; char *path = NULL; - if ((p = STRSKIP(real_path, USB_SYSFS)) && - virAsprintfQuiet(&path, "%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p) < 0) - goto error; + if ((p = STRSKIP(real_path, USB_SYSFS))) + virAsprintfQuiet(&path, "%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p); else if (!p) path = g_strdup(real_path); return path; - - error: - errno = ENOMEM; - return NULL; } DIR *opendir(const char *name) diff --git a/tests/virusbtest.c b/tests/virusbtest.c index b26173248b..94c55e1fb8 100644 --- a/tests/virusbtest.c +++ b/tests/virusbtest.c @@ -52,10 +52,8 @@ static int testDeviceFileActor(virUSBDevicePtr dev, char *str = NULL; int ret = 0; - if (virAsprintf(&str, USB_DEVFS "%03d/%03d", - virUSBDeviceGetBus(dev), - virUSBDeviceGetDevno(dev)) < 0) - return -1; + virAsprintf(&str, USB_DEVFS "%03d/%03d", virUSBDeviceGetBus(dev), + virUSBDeviceGetDevno(dev)); if (STRNEQ(path, str)) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/tests/vmwarevertest.c b/tests/vmwarevertest.c index c19c6cc302..b482873103 100644 --- a/tests/vmwarevertest.c +++ b/tests/vmwarevertest.c @@ -43,9 +43,7 @@ testVerStrParse(const void *data) unsigned long version; int vmware_type; - if (virAsprintf(&path, "%s/vmwareverdata/%s.txt", abs_srcdir, - info->name) < 0) - return -1; + virAsprintf(&path, "%s/vmwareverdata/%s.txt", abs_srcdir, info->name); if (virTestLoadFile(path, &databuf) < 0) goto cleanup; diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 706fec7bac..7e05052744 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -114,16 +114,13 @@ testCompareHelper(const void *data) char *vmx = NULL; char *xml = NULL; - if (virAsprintf(&vmx, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir, - info->input) < 0 || - virAsprintf(&xml, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir, - info->output) < 0) { - goto cleanup; - } + virAsprintf(&vmx, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir, + info->input); + virAsprintf(&xml, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir, + info->output); ret = testCompareFiles(vmx, xml); - cleanup: VIR_FREE(vmx); VIR_FREE(xml); @@ -151,9 +148,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED) goto cleanup; } - if (virAsprintf(&src, "[%s] %s", datastoreName, - directoryAndFileName) < 0) - goto cleanup; + virAsprintf(&src, "[%s] %s", datastoreName, directoryAndFileName); } else if (STRPREFIX(fileName, "/")) { /* Found absolute path referencing a file outside a datastore */ src = g_strdup(fileName); @@ -162,8 +157,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED) src = NULL; } else { /* Found single file name referencing a file inside a datastore */ - if (virAsprintf(&src, "[datastore] directory/%s", fileName) < 0) - goto cleanup; + virAsprintf(&src, "[datastore] directory/%s", fileName); } cleanup: diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 8e84c84887..25988b1ae8 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -187,18 +187,14 @@ testCompareHelper(const void *data) char *xml = NULL; char *cfg = NULL; - if (virAsprintf(&xml, "%s/xlconfigdata/test-%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&cfg, "%s/xlconfigdata/test-%s.cfg", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/xlconfigdata/test-%s.xml", abs_srcdir, info->name); + virAsprintf(&cfg, "%s/xlconfigdata/test-%s.cfg", abs_srcdir, info->name); if (info->mode == 0) result = testCompareParseXML(cfg, xml, info->replaceVars); else result = testCompareFormatXML(cfg, xml, info->replaceVars); - cleanup: VIR_FREE(xml); VIR_FREE(cfg); diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index b67b14ea9d..55fcd95081 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -131,18 +131,14 @@ testCompareHelper(const void *data) char *cfg = NULL; char *cfgout = NULL; - if (virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml", - abs_srcdir, info->name) < 0 || - virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg", - abs_srcdir, info->name) < 0) - goto cleanup; + virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml", abs_srcdir, info->name); + virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg", abs_srcdir, info->name); if (info->mode == 0) result = testCompareParseXML(cfg, xml); else result = testCompareFormatXML(cfg, xml); - cleanup: VIR_FREE(xml); VIR_FREE(cfg); VIR_FREE(cfgout); diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 42ab4ed929..b39862b4bb 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -115,16 +115,13 @@ testCompareHelper(const void *data) char *xml = NULL; char *vmx = NULL; - if (virAsprintf(&xml, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir, - info->input) < 0 || - virAsprintf(&vmx, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir, - info->output) < 0) { - goto cleanup; - } + virAsprintf(&xml, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir, + info->input); + virAsprintf(&vmx, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir, + info->output); result = testCompareFiles(xml, vmx, info->virtualHW_version); - cleanup: VIR_FREE(xml); VIR_FREE(vmx); @@ -169,9 +166,8 @@ testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED) directoryAndFileName += strspn(directoryAndFileName, " "); } - if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", datastoreName, - directoryAndFileName) < 0) - goto cleanup; + virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", datastoreName, + directoryAndFileName); } else if (STRPREFIX(src, "/")) { /* Found absolute path */ absolutePath = g_strdup(src); -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list