[PATCH 27/75] vbox: Drop virAsprintf() and virAsprintfQuiet() retval checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These functions can't fail really. Drop checking of their retval
then.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/vbox/vbox_XPCOMCGlue.c    |  3 +-
 src/vbox/vbox_common.c        | 62 +++++++++++++++--------------------
 src/vbox/vbox_network.c       | 13 +++-----
 src/vbox/vbox_snapshot_conf.c | 18 ++++------
 src/vbox/vbox_storage.c       |  5 ++-
 src/vbox/vbox_tmpl.c          | 32 ++++++++----------
 6 files changed, 53 insertions(+), 80 deletions(-)

diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c
index a20b1c2a36..09768d5d38 100644
--- a/src/vbox/vbox_XPCOMCGlue.c
+++ b/src/vbox/vbox_XPCOMCGlue.c
@@ -85,8 +85,7 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing,
     PFNVBOXGETXPCOMCFUNCTIONS pfnGetFunctions;
 
     if (dir != NULL) {
-        if (virAsprintf(&name, "%s/%s", dir, DYNLIB_NAME) < 0)
-            return -1;
+        virAsprintf(&name, "%s/%s", dir, DYNLIB_NAME);
 
         if (!virFileExists(name)) {
             if (!ignoreMissing)
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 475b3a3147..6ffa43addc 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1770,13 +1770,12 @@ vboxAttachUSB(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
         /* Zero pad for nice alignment when fewer than 9999
          * devices.
          */
-        if (virAsprintf(&filtername, "filter%04zu", i) >= 0) {
-            VBOX_UTF8_TO_UTF16(filtername, &filternameUtf16);
-            VIR_FREE(filtername);
-            gVBoxAPI.UIUSBCommon.CreateDeviceFilter(USBCommon,
-                                                    filternameUtf16,
-                                                    &filter);
-        }
+        virAsprintf(&filtername, "filter%04zu", i);
+        VBOX_UTF8_TO_UTF16(filtername, &filternameUtf16);
+        VIR_FREE(filtername);
+        gVBoxAPI.UIUSBCommon.CreateDeviceFilter(USBCommon,
+                                                filternameUtf16,
+                                                &filter);
         VBOX_UTF16_FREE(filternameUtf16);
 
         if (!filter)
@@ -2127,10 +2126,9 @@ vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, vboxIID *iid
     if (guiPresent) {
         if (guiDisplay) {
             char *displayutf8;
-            if (virAsprintf(&displayutf8, "DISPLAY=%s", guiDisplay) >= 0) {
-                VBOX_UTF8_TO_UTF16(displayutf8, &env);
-                VIR_FREE(displayutf8);
-            }
+            virAsprintf(&displayutf8, "DISPLAY=%s", guiDisplay);
+            VBOX_UTF8_TO_UTF16(displayutf8, &env);
+            VIR_FREE(displayutf8);
             VIR_FREE(guiDisplay);
         }
 
@@ -2140,10 +2138,9 @@ vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, vboxIID *iid
     if (sdlPresent) {
         if (sdlDisplay) {
             char *displayutf8;
-            if (virAsprintf(&displayutf8, "DISPLAY=%s", sdlDisplay) >= 0) {
-                VBOX_UTF8_TO_UTF16(displayutf8, &env);
-                VIR_FREE(displayutf8);
-            }
+            virAsprintf(&displayutf8, "DISPLAY=%s", sdlDisplay);
+            VBOX_UTF8_TO_UTF16(displayutf8, &env);
+            VIR_FREE(displayutf8);
             VIR_FREE(sdlDisplay);
         }
 
@@ -4619,8 +4616,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
     }
     VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
 
-    if (virAsprintf(&nameTmpUse, "%s.vbox", machineName) < 0)
-        goto cleanup;
+    virAsprintf(&nameTmpUse, "%s.vbox", machineName);
     machineLocationPath = virStringReplace(settingsFilePath_Utf8, nameTmpUse, "");
     if (machineLocationPath == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -4636,9 +4632,8 @@ vboxSnapshotRedefine(virDomainPtr dom,
         goto cleanup;
     }
     if (snapshotMachineDesc->currentSnapshot != NULL) {
-        if (virAsprintf(&currentSnapshotXmlFilePath, "%s%s.xml", machineLocationPath,
-                       snapshotMachineDesc->currentSnapshot) < 0)
-            goto cleanup;
+        virAsprintf(&currentSnapshotXmlFilePath, "%s%s.xml",
+                    machineLocationPath, snapshotMachineDesc->currentSnapshot);
         snapshotFileExists = virFileExists(currentSnapshotXmlFilePath);
     }
 
@@ -5206,8 +5201,8 @@ vboxSnapshotRedefine(virDomainPtr dom,
             vboxIIDUnalloc(&parentiid);
             VBOX_UTF8_TO_UTF16("VDI", &formatUtf16);
 
-            if (virAsprintf(&newLocationUtf8, "%sfakedisk-%d.vdi", machineLocationPath, it) < 0)
-                goto cleanup;
+            virAsprintf(&newLocationUtf8, "%sfakedisk-%d.vdi",
+                        machineLocationPath, it);
             VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation);
             rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj,
                                                       formatUtf16,
@@ -5305,8 +5300,8 @@ vboxSnapshotRedefine(virDomainPtr dom,
          * next define. This file is saved as "'machineLocation'/snapshot-'uuid'.xml"
          */
         VIR_FREE(currentSnapshotXmlFilePath);
-        if (virAsprintf(&currentSnapshotXmlFilePath, "%s%s.xml", machineLocationPath, snapshotMachineDesc->currentSnapshot) < 0)
-            goto cleanup;
+        virAsprintf(&currentSnapshotXmlFilePath, "%s%s.xml",
+                    machineLocationPath, snapshotMachineDesc->currentSnapshot);
         char *snapshotContent = virDomainSnapshotDefFormat(NULL, def,
                                                            data->caps,
                                                            data->xmlopt,
@@ -6893,8 +6888,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
         goto cleanup;
     }
     VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
-    if (virAsprintf(&nameTmpUse, "%s.vbox", machineName) < 0)
-        goto cleanup;
+    virAsprintf(&nameTmpUse, "%s.vbox", machineName);
     machineLocationPath = virStringReplace(settingsFilepath, nameTmpUse, "");
     if (machineLocationPath == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -6978,9 +6972,8 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
                 VBOX_UTF16_FREE(locationUtf16);
                 VBOX_UTF8_TO_UTF16("VDI", &formatUtf16);
 
-                if (virAsprintf(&newLocationUtf8, "%sfakedisk-%s-%d.vdi",
-                                machineLocationPath, def->parent.parent_name, it) < 0)
-                    goto cleanup;
+                virAsprintf(&newLocationUtf8, "%sfakedisk-%s-%d.vdi",
+                            machineLocationPath, def->parent.parent_name, it);
                 VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation);
                 rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj,
                                                           formatUtf16,
@@ -7383,17 +7376,14 @@ vboxDomainScreenshot(virDomainPtr dom,
         return NULL;
     }
 
-    if ((privileged && virAsprintf(&cacheDir, "%s/cache/libvirt", LOCALSTATEDIR) < 0) ||
-        (!privileged && !(cacheDir = virGetUserCacheDirectory()))) {
+    if (privileged) {
+        virAsprintf(&cacheDir, "%s/cache/libvirt", LOCALSTATEDIR);
+    } else if (!(cacheDir = virGetUserCacheDirectory())) {
         VBOX_RELEASE(machine);
         return NULL;
     }
 
-    if (virAsprintf(&tmp, "%s/vbox.screendump.XXXXXX", cacheDir) < 0) {
-        VBOX_RELEASE(machine);
-        VIR_FREE(cacheDir);
-        return NULL;
-    }
+    virAsprintf(&tmp, "%s/vbox.screendump.XXXXXX", cacheDir);
 
     if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
         virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp);
diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c
index 9e632ab709..a942587bcb 100644
--- a/src/vbox/vbox_network.c
+++ b/src/vbox/vbox_network.c
@@ -432,8 +432,8 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start)
 
     VBOX_UTF16_TO_UTF8(networkInterfaceNameUtf16, &networkInterfaceNameUtf8);
 
-    if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", networkInterfaceNameUtf8) < 0)
-        goto cleanup;
+    virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s",
+                networkInterfaceNameUtf8);
 
     VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16);
 
@@ -588,8 +588,7 @@ vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface)
      * show up in the net-list in virsh
      */
 
-    if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0)
-        goto cleanup;
+    virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name);
 
     VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);
 
@@ -693,8 +692,7 @@ static int vboxNetworkCreate(virNetworkPtr network)
      * server by giving the machine static IP
      */
 
-    if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0)
-        goto cleanup;
+    virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name);
 
     VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);
 
@@ -791,8 +789,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
     def->ips = ipdef;
     def->nips = 1;
 
-    if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0)
-        goto cleanup;
+    virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name);
 
     VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);
 
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index 8cdfb35357..8c92d8797b 100644
--- a/src/vbox/vbox_snapshot_conf.c
+++ b/src/vbox/vbox_snapshot_conf.c
@@ -84,8 +84,7 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xmlNodePtr diskNode,
     }
     if (location[0] != '/') {
         /*The location is a relative path, so we must change it into an absolute one. */
-        if (virAsprintf(&tmp, "%s%s", machineLocation, location) < 0)
-            goto cleanup;
+        virAsprintf(&tmp, "%s%s", machineLocation, location);
         hardDisk->location = g_strdup(tmp);
     } else {
         hardDisk->location = g_strdup(location);
@@ -331,8 +330,7 @@ virVBoxSnapshotConfCreateHardDiskNode(virVBoxSnapshotConfHardDiskPtr hardDisk)
     size_t i = 0;
     char *uuid = NULL;
     xmlNodePtr ret = xmlNewNode(NULL, BAD_CAST "HardDisk");
-    if (virAsprintf(&uuid, "{%s}", hardDisk->uuid) < 0)
-        goto cleanup;
+    virAsprintf(&uuid, "{%s}", hardDisk->uuid);
 
     if (xmlNewProp(ret, BAD_CAST "uuid", BAD_CAST uuid) == NULL)
         goto cleanup;
@@ -378,8 +376,7 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node,
     char **secondRegex = NULL;
     int secondRegexResult = 0;
 
-    if (virAsprintf(&uuid, "{%s}", snapshot->uuid) < 0)
-        goto cleanup;
+    virAsprintf(&uuid, "{%s}", snapshot->uuid);
 
     if (xmlNewProp(node, BAD_CAST "uuid", BAD_CAST uuid) == NULL)
         goto cleanup;
@@ -400,8 +397,7 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node,
         goto cleanup;
     if (secondRegexResult < 1)
         goto cleanup;
-    if (virAsprintf(&timeStamp, "%sT%sZ", firstRegex[0], secondRegex[0]) < 0)
-        goto cleanup;
+    virAsprintf(&timeStamp, "%sT%sZ", firstRegex[0], secondRegex[0]);
 
     if (xmlNewProp(node, BAD_CAST "timeStamp", BAD_CAST timeStamp) == NULL)
         goto cleanup;
@@ -1073,8 +1069,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachinePtr machine,
     }
 
     if (machine->currentSnapshot != NULL) {
-        if (virAsprintf(&currentSnapshot, "{%s}", machine->currentSnapshot) < 0)
-            goto cleanup;
+        virAsprintf(&currentSnapshot, "{%s}", machine->currentSnapshot);
         if (!xmlNewProp(machineNode, BAD_CAST "currentSnapshot", BAD_CAST currentSnapshot)) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("Error in xmlNewProp"));
@@ -1111,8 +1106,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachinePtr machine,
     if (secondRegexResult < 1)
         goto cleanup;
 
-    if (virAsprintf(&timeStamp, "%sT%sZ", firstRegex[0], secondRegex[0]) < 0)
-        goto cleanup;
+    virAsprintf(&timeStamp, "%sT%sZ", firstRegex[0], secondRegex[0]);
     if (!xmlNewProp(machineNode, BAD_CAST "lastStateChange", BAD_CAST timeStamp)) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("Error in xmlNewProp"));
diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c
index c7bea2c219..8cd1b20628 100644
--- a/src/vbox/vbox_storage.c
+++ b/src/vbox/vbox_storage.c
@@ -448,9 +448,8 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool,
     }
 
     /* If target.path isn't given, use default path ~/.VirtualBox/image_name */
-    if (def->target.path == NULL &&
-        virAsprintf(&def->target.path, "%s/.VirtualBox/%s", virGetUserDirectory(), def->name) < 0)
-        goto cleanup;
+    if (!def->target.path)
+        virAsprintf(&def->target.path, "%s/.VirtualBox/%s", virGetUserDirectory(), def->name);
     VBOX_UTF8_TO_UTF16(def->target.path, &hddNameUtf16);
 
     if (!hddFormatUtf16 || !hddNameUtf16)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 72011199cf..88e7deaea0 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -613,29 +613,23 @@ _virtualboxCreateMachine(vboxDriverPtr data, virDomainDefPtr def, IMachine **mac
 {
     vboxIID iid = VBOX_IID_INITIALIZER;
     PRUnichar *machineNameUtf16 = NULL;
+    char *createFlags = NULL;
+    PRUnichar *createFlagsUtf16 = NULL;
     nsresult rc = -1;
 
     VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16);
     vboxIIDFromUUID(&iid, def->uuid);
-    {
-        char *createFlags = NULL;
-        PRUnichar *createFlagsUtf16 = NULL;
-
-        if (virAsprintf(&createFlags,
-                        "UUID=%s,forceOverwrite=0", uuidstr) < 0)
-            goto cleanup;
-        VBOX_UTF8_TO_UTF16(createFlags, &createFlagsUtf16);
-        rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
-                                                NULL,
-                                                machineNameUtf16,
-                                                0,
-                                                nsnull,
-                                                nsnull,
-                                                createFlagsUtf16,
-                                                machine);
- cleanup:
-        VIR_FREE(createFlags);
-    }
+    virAsprintf(&createFlags, "UUID=%s,forceOverwrite=0", uuidstr);
+    VBOX_UTF8_TO_UTF16(createFlags, &createFlagsUtf16);
+    rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
+                                            NULL,
+                                            machineNameUtf16,
+                                            0,
+                                            nsnull,
+                                            nsnull,
+                                            createFlagsUtf16,
+                                            machine);
+    VIR_FREE(createFlags);
     VBOX_UTF16_FREE(machineNameUtf16);
     vboxIIDUnalloc(&iid);
     return rc;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux