From: John Wolfe Date: Mon, 22 Feb 2021 17:37:00 +0000 (-0800) Subject: Fix miscellaneous Codacy warnings in Tools and VGAuth code. X-Git-Tag: stable-11.3.0~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=433270c8dc916aeafd222a55a9bd2a301ac573f6;p=thirdparty%2Fopen-vm-tools.git Fix miscellaneous Codacy warnings in Tools and VGAuth code. Multiple warnings "The scope of the variable can be reduced" reported by the Codacy static analysis tool have been addressed. --- diff --git a/open-vm-tools/lib/file/fileLockPrimitive.c b/open-vm-tools/lib/file/fileLockPrimitive.c index f2054f09e..c6eda7390 100644 --- a/open-vm-tools/lib/file/fileLockPrimitive.c +++ b/open-vm-tools/lib/file/fileLockPrimitive.c @@ -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); diff --git a/open-vm-tools/lib/file/filePosix.c b/open-vm-tools/lib/file/filePosix.c index 5681ebfd3..c56f13650 100644 --- a/open-vm-tools/lib/file/filePosix.c +++ b/open-vm-tools/lib/file/filePosix.c @@ -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)) ; diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerOplockMonitor.c b/open-vm-tools/lib/hgfsServer/hgfsServerOplockMonitor.c index 8e20f10b4..de97373cb 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerOplockMonitor.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServerOplockMonitor.c @@ -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. diff --git a/open-vm-tools/lib/include/codeset.h b/open-vm-tools/lib/include/codeset.h index dd1df88f5..fbf7b5e66 100644 --- a/open-vm-tools/lib/include/codeset.h +++ b/open-vm-tools/lib/include/codeset.h @@ -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. diff --git a/open-vm-tools/lib/misc/codesetUTF8.c b/open-vm-tools/lib/misc/codesetUTF8.c index a6345d6cb..3ff0a208d 100644 --- a/open-vm-tools/lib/misc/codesetUTF8.c +++ b/open-vm-tools/lib/misc/codesetUTF8.c @@ -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; diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c index cc5fa281a..f13b23a09 100644 --- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c +++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c @@ -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)); diff --git a/open-vm-tools/lib/rpcChannel/simpleSocket.c b/open-vm-tools/lib/rpcChannel/simpleSocket.c index 1d085436a..10b625478 100644 --- a/open-vm-tools/lib/rpcChannel/simpleSocket.c +++ b/open-vm-tools/lib/rpcChannel/simpleSocket.c @@ -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) { diff --git a/open-vm-tools/services/plugins/guestInfo/diskInfo.c b/open-vm-tools/services/plugins/guestInfo/diskInfo.c index f8d9e967f..5537918aa 100644 --- a/open-vm-tools/services/plugins/guestInfo/diskInfo.c +++ b/open-vm-tools/services/plugins/guestInfo/diskInfo.c @@ -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 diff --git a/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c b/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c index 18865996c..d4892e45e 100644 --- a/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c +++ b/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c @@ -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]; diff --git a/open-vm-tools/vgauth/serviceImpl/alias.c b/open-vm-tools/vgauth/serviceImpl/alias.c index 0a43811e7..26e33aa77 100644 --- a/open-vm-tools/vgauth/serviceImpl/alias.c +++ b/open-vm-tools/vgauth/serviceImpl/alias.c @@ -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); diff --git a/open-vm-tools/vgauth/serviceImpl/proto.c b/open-vm-tools/vgauth/serviceImpl/proto.c index dc1dfd7f2..36cc6840a 100644 --- a/open-vm-tools/vgauth/serviceImpl/proto.c +++ b/open-vm-tools/vgauth/serviceImpl/proto.c @@ -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); diff --git a/open-vm-tools/vmblock-fuse/fsops.c b/open-vm-tools/vmblock-fuse/fsops.c index 28337d80b..c14d78d47 100644 --- a/open-vm-tools/vmblock-fuse/fsops.c +++ b/open-vm-tools/vmblock-fuse/fsops.c @@ -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);