From: John Wolfe Date: Mon, 22 Feb 2021 17:36:59 +0000 (-0800) Subject: Fix miscellaneous Codacy warnings in deployPkg plugin code. X-Git-Tag: stable-11.3.0~147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbd0de661501194f0834ff0f8ff215344989ef38;p=thirdparty%2Fopen-vm-tools.git Fix miscellaneous Codacy warnings in deployPkg plugin 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/libDeployPkg/linuxDeployment.c b/open-vm-tools/libDeployPkg/linuxDeployment.c index 99463b506..063c0b789 100644 --- a/open-vm-tools/libDeployPkg/linuxDeployment.c +++ b/open-vm-tools/libDeployPkg/linuxDeployment.c @@ -238,11 +238,10 @@ DeployPkg_SetProcessTimeout(uint16 timeout) NORETURN void Panic(const char *fmtstr, ...) { - va_list args; - char *tmp = malloc(MAXSTRING); if (tmp != NULL) { + va_list args; va_start(args, fmtstr); Str_Vsnprintf(tmp, MAXSTRING, fmtstr, args); va_end(args); diff --git a/open-vm-tools/libDeployPkg/processPosix.c b/open-vm-tools/libDeployPkg/processPosix.c index 928630305..7aa9c249f 100644 --- a/open-vm-tools/libDeployPkg/processPosix.c +++ b/open-vm-tools/libDeployPkg/processPosix.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 @@ -433,7 +433,6 @@ ProcessError Process_Destroy(ProcessHandle h) { ProcessInternal* p; - int i; p = (ProcessInternal*)h; if (p->stdoutFd >= 0) { close(p->stdoutFd); @@ -444,6 +443,7 @@ Process_Destroy(ProcessHandle h) free(p->stdoutStr); free(p->stderrStr); if (p->args != NULL) { + int i; for (i = 0; p->args[i] != NULL; i++) { free(p->args[i]); } diff --git a/open-vm-tools/services/plugins/deployPkg/deployPkg.c b/open-vm-tools/services/plugins/deployPkg/deployPkg.c index d7a84b421..7805f59ee 100644 --- a/open-vm-tools/services/plugins/deployPkg/deployPkg.c +++ b/open-vm-tools/services/plugins/deployPkg/deployPkg.c @@ -210,7 +210,6 @@ void DeployPkgExecDeploy(ToolsAppCtx *ctx, // IN: app context void *pkgName) // IN: pkg file name { - char errMsg[2048]; ToolsDeployPkgError ret; char *pkgNameStr = (char *) pkgName; Bool enableCust; @@ -246,6 +245,7 @@ DeployPkgExecDeploy(ToolsAppCtx *ctx, // IN: app context g_free(msg); vm_free(result); } else { + char errMsg[2048]; /* Unpack the package and run the command. */ ret = DeployPkgDeployPkgInGuest(ctx, pkgNameStr, errMsg, sizeof errMsg); if (ret != TOOLSDEPLOYPKG_ERROR_SUCCESS) { diff --git a/open-vm-tools/services/plugins/deployPkg/deployPkgLog.c b/open-vm-tools/services/plugins/deployPkg/deployPkgLog.c index 84b39bab9..3b8f78243 100644 --- a/open-vm-tools/services/plugins/deployPkg/deployPkgLog.c +++ b/open-vm-tools/services/plugins/deployPkg/deployPkgLog.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 @@ -154,9 +154,6 @@ DeployPkgLog_Log(int level, // IN ...) // IN { va_list args; - gchar *tstamp; - const char *logLevel; - GLogLevelFlags glogLevel; if (fmtstr == NULL) { return; @@ -165,6 +162,8 @@ DeployPkgLog_Log(int level, // IN va_start(args, fmtstr); if (_file != NULL) { + const char *logLevel; + gchar *tstamp; size_t fmtstrLen = strlen(fmtstr); switch (level) { case log_debug: @@ -193,6 +192,7 @@ DeployPkgLog_Log(int level, // IN } g_free(tstamp); } else { + GLogLevelFlags glogLevel; switch (level) { case log_debug: glogLevel = G_LOG_LEVEL_DEBUG;