Re: [PATCH 3/3] storageBackendCreateRaw: remove unused created variable

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

 



On 12/29/20 12:29 PM, Yi Li wrote:
refactor and remove unused created variable

Signed-off-by: Yi Li <yili@xxxxxxxxxxx>
---
  src/storage/storage_util.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index c6d0f7a97c..c02ece8253 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -384,11 +384,10 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool,
                          unsigned int flags)
  {
      virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
-    int ret = -1;
+    int ret = 0;

No, please don't initialize this to zero. The pattern we use (and are used to) is:

  int ret = -1;

  if (something)
    goto cleanup;

  if (something else)
    goto cleanup;

  ret = 0;
 cleanup:
  if (ret < 0)
    cleanupWhatsNeeded();

  return ret;


Alternatively, we can rename 'cleanup' to 'error' and do the following (without even having to use @ret variable):

  if (something)
    goto error;

  if (something else)
    goto error;

  return 0;
 error:
  cleanupWhatsNeeded();
  return -1;

Michal




[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