]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix miscellaneous Codacy warnings in Tools and VGAuth code.
authorJohn Wolfe <jwolfe@vmware.com>
Mon, 22 Feb 2021 17:37:00 +0000 (09:37 -0800)
committerJohn Wolfe <jwolfe@vmware.com>
Mon, 22 Feb 2021 17:37:00 +0000 (09:37 -0800)
Multiple warnings "The scope of the variable can be reduced" reported by
the Codacy static analysis tool have been addressed.

12 files changed:
open-vm-tools/lib/file/fileLockPrimitive.c
open-vm-tools/lib/file/filePosix.c
open-vm-tools/lib/hgfsServer/hgfsServerOplockMonitor.c
open-vm-tools/lib/include/codeset.h
open-vm-tools/lib/misc/codesetUTF8.c
open-vm-tools/lib/nicInfo/nicInfoPosix.c
open-vm-tools/lib/rpcChannel/simpleSocket.c
open-vm-tools/services/plugins/guestInfo/diskInfo.c
open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c
open-vm-tools/vgauth/serviceImpl/alias.c
open-vm-tools/vgauth/serviceImpl/proto.c
open-vm-tools/vmblock-fuse/fsops.c

index f2054f09eb031db87625fa7db1cec933e8ff1988..c6eda739053876523e87aee6dce553123f0cbd00 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2007-2020 VMware, Inc. All rights reserved.
+ * Copyright (C) 2007-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -755,7 +755,6 @@ FileLockScanDirectory(const char *lockDir,      // IN:
       LockValues *ptr;
       Bool       myLockFile;
       LockValues memberValues;
-      char buffer[FILELOCK_DATA_SIZE];
 
       if ((fileList[i] == NULL) || (*fileList[i] == 'E')) {
          continue;
@@ -768,6 +767,7 @@ FileLockScanDirectory(const char *lockDir,      // IN:
          /* It's me! No need to read or validate anything. */
          ptr = myValues;
       } else {
+         char buffer[FILELOCK_DATA_SIZE];
          /* It's not me! Attempt to extract the member values. */
          err = FileLockMemberValues(lockDir, fileList[i], buffer,
                                     FILELOCK_DATA_SIZE, &memberValues);
index 5681ebfd3d2a8862b234855d8f44cc2358123df0..c56f13650291319154eacd7d35e5c418f032c087 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2006-2020 VMware, Inc. All rights reserved.
+ * Copyright (C) 2006-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -2881,11 +2881,12 @@ int
 File_ListDirectory(const char *dirName,  // IN:
                    char ***ids)          // OUT: relative paths
 {
-   int err = 0;
    int count = -1;
    WalkDirContext context = File_WalkDirectoryStart(dirName);
 
    if (context != NULL) {
+      int err;
+
       while (File_WalkDirectoryNext(context, NULL))
          ;
 
index 8e20f10b4796b20eb254393ba9dd385d6681ef81..de97373cb53e8ed74e6d954843fec305f24f297b 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2020 VMware, Inc. All rights reserved.
+ * Copyright (C) 2020-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -198,14 +198,15 @@ HgfsOplockMonitorFileChangeCallback(HgfsSessionInfo *session,   // IN:
                                     void *data)                 // IN:
 {
    oplockMonitorData *monitorData = data;
-   DblLnkLst_Links *link, *nextLink;
-   oplockMonitorCallbackList *callbackItem;
 
    ASSERT(monitorData);
    MXUser_AcquireExclLock(oplockMonitorLock);
    if (HashTable_Lookup(gOplockMonitorMap, monitorData->utf8Name, NULL)) {
+      DblLnkLst_Links *link, *nextLink;
       DblLnkLst_ForEachSafe(link, nextLink, &monitorData->callbackList) {
-         callbackItem = DblLnkLst_Container(link, oplockMonitorCallbackList, links);
+         oplockMonitorCallbackList *callbackItem = DblLnkLst_Container(link,
+                                                   oplockMonitorCallbackList,
+                                                   links);
          callbackItem->callback(session, callbackItem->data);
          /*
           * callbackItem->data has been freed in the user callback.
index dd1df88f556765f6f43d8b3c43a4dd10f500325e..fbf7b5e66798770ff0f8f1045e282efe801eb84d 100644 (file)
@@ -1,5 +1,5 @@
 /* **********************************************************
- * Copyright (C) 2007-2020 VMware, Inc.  All rights reserved.
+ * Copyright (c) 2007-2021 VMware, Inc.  All rights reserved.
  * **********************************************************/
 
 /*
@@ -498,10 +498,10 @@ CodeSet_Utf8FindCodePointBoundary(const char *buf,   // IN
                                   size_t offset)     // IN
 {
    size_t origOffset = offset;
-   signed char c;
 
    if (offset > 0) {
 
+      signed char c;
       /*
        * Back up 1 byte and then find the start of the UTF-8 code
        * point occupying that location.
index a6345d6cbade041e18435b62bbb5c865ba3342d4..3ff0a208db2d2a9cc04eff56828185122bf868b7 100644 (file)
@@ -1,5 +1,5 @@
 /* **********************************************************
- * Copyright (C) 2015-2020 VMware, Inc.  All rights reserved.
+ * Copyright (c) 2015-2021 VMware, Inc.  All rights reserved.
  * **********************************************************/
 
 /*
@@ -146,10 +146,9 @@ CodeSet_IsValidUTF8String(const char *bufIn,  // IN:
 {
    size_t i;
    uint32 state = UTF8_ACCEPT;
-   unsigned char c;
 
    for (i = 0; i < sizeIn; i++) {
-      c = (unsigned char) *bufIn++;
+      unsigned char c = (unsigned char) *bufIn++;
 
       if (UNLIKELY(c == '\0')) {
          return FALSE;
index cc5fa281a9140f39a07648b557c12d329dfaa0e9..f13b23a0976298e4c36de9799786e4b527db4d4a 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2014-2020 VMware, Inc. All rights reserved.
+ * Copyright (C) 2014-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -665,7 +665,6 @@ ReadInterfaceDetails(const struct intf_entry *entry, // IN
                      void *arg,                      // IN
                      NicInfoPriority priority)       // IN
 {
-   int i;
    NicInfoV3 *nicInfo = arg;
 
    ASSERT(entry);
@@ -684,6 +683,7 @@ ReadInterfaceDetails(const struct intf_entry *entry, // IN
       if (entry->intf_link_addr.addr_type == ADDR_TYPE_ETH) {
          char macAddress[NICINFO_MAC_LEN];
          GuestNicV3 *nic = NULL;
+         int i;
 
          Str_Sprintf(macAddress, sizeof macAddress, "%s",
                      addr_ntoa(&entry->intf_link_addr));
index 1d085436a14d0f7f1cb9c6c9c91d8bbbd942dcd6..10b62547895f837a839cb2d74bffa7d1f6e754c8 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2013-2017,2019-2020 VMware, Inc. All rights reserved.
+ * Copyright (C) 2013-2017,2019-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -222,11 +222,10 @@ Socket_Send(SOCKET fd,      // IN
 {
    int left = len;
    int sent = 0;
-   int rv;
    int sysErr;
 
    while (left > 0) {
-      rv = send(fd, buf + sent, left, 0);
+      int rv = send(fd, buf + sent, left, 0);
       if (rv == SOCKET_ERROR) {
          sysErr = SocketGetLastError();
          if (sysErr == SYSERR_EINTR) {
index f8d9e967f754d681bd93925731d26ac1e6c752e8..5537918aa629954b30feb61870a3639eeda9d585 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2014-2020 VMware, Inc. All rights reserved.
+ * Copyright (C) 2014-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -947,7 +947,6 @@ GuestInfoGetDiskDevice(const char *fsName,
    if (!GuestInfoIsLinuxLvmDevice(fsName, partEntry)) {
 
       /* Not an LVM; check if a basic block device. */
-      char blockDevPath[PATH_MAX];
       const char *baseDevName = strrchr(fsName, '/');
 
       /*
@@ -956,6 +955,8 @@ GuestInfoGetDiskDevice(const char *fsName,
        * lookup; avoid at this time.
        */
       if (baseDevName != NULL && strcmp(partEntry->fsType, "zfs") != 0) {
+         char blockDevPath[PATH_MAX];
+
          /*
           * Have a single disk device associated with this mount point.  The
           * majority of these will be handled by the basic Linux block device
index 18865996c326acb691a6619269202be5f259975d..d4892e45e7627b7985d69791dc20d11b6563ee51 100644 (file)
@@ -914,7 +914,6 @@ RandR12Revert(Display *display,    // IN: The display connection
    unsigned int i;
    RandR12Info *info = *pInfo;
    XRRScreenResources *xrrRes = info->xrrRes;
-   RandR12Output *rrOutput;
    XRRCrtcInfo *crtc;
    RRCrtc crtcID;
 
@@ -922,7 +921,7 @@ RandR12Revert(Display *display,    // IN: The display connection
 
    for (i = 0; i < info->nOutput; ++i) {
 
-      rrOutput = &info->outputs[i];
+      RandR12Output *rrOutput = &info->outputs[i];
       crtc = info->crtcs[rrOutput->crtc];
       crtcID = xrrRes->crtcs[rrOutput->crtc];
 
index 0a43811e7418a66d719c0310a5629153cda93e76..26e33aa77a3e2a35b2c1e9c2b1b05241951072ee 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2011-2020 VMware, Inc. All rights reserved.
+ * Copyright (C) 2011-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -3100,7 +3100,6 @@ ServiceIDVerifyStoreContents(void)
    GDir *dir;
    GError *gErr;
    const gchar *fileName;
-   gchar *fullFileName;
    gboolean saveBadFile = FALSE;
 
    dir = g_dir_open(aliasStoreRootDir, 0, &gErr);
@@ -3112,9 +3111,9 @@ ServiceIDVerifyStoreContents(void)
    }
 
    while ((fileName = g_dir_read_name(dir)) != NULL) {
-      fullFileName = g_strdup_printf("%s"DIRSEP"%s",
-                                     aliasStoreRootDir,
-                                     fileName);
+      gchar *fullFileName = g_strdup_printf("%s"DIRSEP"%s",
+                                            aliasStoreRootDir,
+                                            fileName);
       // mapping file is special
       if (g_strcmp0(ALIASSTORE_MAPFILE_NAME, fileName) == 0) {
          err = AliasCheckMapFilePerms(fullFileName);
index dc1dfd7f2151d1bcb8bebc0252b7b052adf74954..36cc6840aa8ab92efac0dc8dbb678acb7951e7ec 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2011-2016,2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 2011-2016,2019-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -1747,11 +1747,8 @@ ServiceProtoQueryAliases(ServiceConnection *conn,
 {
    VGAuthError err;
    gchar *packet;
-   gchar *endPacket;
    int num;
    ServiceAlias *aList;
-   int i;
-   int j;
 
    /*
     * The alias code will do argument validation.
@@ -1763,11 +1760,15 @@ ServiceProtoQueryAliases(ServiceConnection *conn,
    if (err != VGAUTH_E_OK) {
       packet = Proto_MakeErrorReply(conn, req, err, "queryAliases failed");
    } else {
+      int i;
+      gchar *endPacket;
+
       packet = g_markup_printf_escaped(VGAUTH_QUERYALIASES_REPLY_FORMAT_START,
                                        req->sequenceNumber);
       // now the aliases
       for (i = 0; i < num; i++) {
          gchar *certPacket;
+         int j;
 
          certPacket = g_markup_printf_escaped(VGAUTH_ALIAS_FORMAT_START,
                                               aList[i].pemCert);
index 28337d80b5304a0fe093c5604727795eb7bb9d0d..c14d78d4763d12409b9a136b830b011bf18efbeb 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -252,7 +252,6 @@ int
 VMBlockGetAttr(const char *path,        // IN: File to get attributes of.
                struct stat *statBuf)    // OUT: Where to put the attributes.
 {
-   char target[PATH_MAX + 1];
    vmblockSpecialDirEntry *dirEntry;
    ASSERT(path != NULL);
    ASSERT(statBuf != NULL);
@@ -272,6 +271,7 @@ VMBlockGetAttr(const char *path,        // IN: File to get attributes of.
       }
    }
    if (strncmp(path, REDIRECT_DIR, strlen(REDIRECT_DIR)) == 0) {
+      char target[PATH_MAX + 1];
       int status = RealReadLink(path, target, sizeof target);
 
       LOG(4, "%s: Called RealReadLink which returned: %d\n", __func__, status);