From bd0a21c9ee1d79cf07ee72c975c9ae8b4629144c Mon Sep 17 00:00:00 2001 From: leleliu008 Date: Mon, 4 Sep 2023 19:20:52 +0800 Subject: [PATCH] optimized Signed-off-by: leleliu008 --- src/check.c | 2 +- src/cleanup.c | 8 +++----- src/depends.c | 2 +- src/env.c | 2 +- src/fetch.c | 2 +- src/formula-repo-add.c | 2 +- src/formula-repo-create.c | 2 +- src/formula-repo-list.c | 2 +- src/formula-repo-lookup.c | 2 +- src/formula-repo-remove.c | 2 +- src/generate-url-transform-sample.c | 2 +- src/info.c | 10 +++++----- src/install.c | 2 +- src/integrate.c | 2 +- src/list-installed-packages.c | 2 +- src/list-outdated-packages.c | 2 +- src/receipt-parse.c | 2 +- src/session.c | 2 +- src/tree.c | 2 +- src/uninstall.c | 2 +- src/upgrade-self.c | 2 +- 21 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/check.c b/src/check.c index ad50a33..f6c2953 100644 --- a/src/check.c +++ b/src/check.c @@ -72,7 +72,7 @@ int uppm_check_if_the_given_package_is_installed(const char * packageName) { return ret; } - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/cleanup.c b/src/cleanup.c index f046b15..6cf46ee 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -1,11 +1,9 @@ +#include #include #include -#include #include - #include - #include #include "core/rm-r.h" @@ -13,7 +11,7 @@ #include "uppm.h" static int uppm_cleanup_downloads(bool verbose) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); @@ -95,7 +93,7 @@ static int uppm_cleanup_downloads(bool verbose) { } static int uppm_cleanup_installed(bool verbose) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/depends.c b/src/depends.c index 6077f9b..6341b8c 100644 --- a/src/depends.c +++ b/src/depends.c @@ -291,7 +291,7 @@ int uppm_depends(const char * packageName, UPPMDependsOutputType outputType, con //////////////////////////////////////////////////////////////// - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/env.c b/src/env.c index 64daaba..899ca09 100644 --- a/src/env.c +++ b/src/env.c @@ -67,7 +67,7 @@ static int uppm_list_dirs(const char * installedDIR, size_t installedDIRLength, } int uppm_env(bool verbose) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/fetch.c b/src/fetch.c index e56950a..ac2afbf 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -41,7 +41,7 @@ int uppm_fetch(const char * packageName, bool verbose) { ////////////////////////////////////////////////////////////////////////// - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/formula-repo-add.c b/src/formula-repo-add.c index f4165c8..2481575 100644 --- a/src/formula-repo-add.c +++ b/src/formula-repo-add.c @@ -42,7 +42,7 @@ int uppm_formula_repo_add(const char * formulaRepoName, const char * formulaRepo /////////////////////////////////////////////////////////////////////////////////////// - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/formula-repo-create.c b/src/formula-repo-create.c index 826aa64..32ce891 100644 --- a/src/formula-repo-create.c +++ b/src/formula-repo-create.c @@ -37,7 +37,7 @@ int uppm_formula_repo_create(const char * formulaRepoName, const char * formulaR /////////////////////////////////////////////////////////////////////////////////////// - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/formula-repo-list.c b/src/formula-repo-list.c index e6997f9..18a69d6 100644 --- a/src/formula-repo-list.c +++ b/src/formula-repo-list.c @@ -7,7 +7,7 @@ #include "uppm.h" int uppm_formula_repo_list(UPPMFormulaRepoList * * out) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/formula-repo-lookup.c b/src/formula-repo-lookup.c index 5d7f42f..383488a 100644 --- a/src/formula-repo-lookup.c +++ b/src/formula-repo-lookup.c @@ -5,7 +5,7 @@ #include "uppm.h" int uppm_formula_repo_lookup(const char * formulaRepoName, UPPMFormulaRepo * * formulaRepoPP) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/formula-repo-remove.c b/src/formula-repo-remove.c index bf13d5a..1cc9fda 100644 --- a/src/formula-repo-remove.c +++ b/src/formula-repo-remove.c @@ -23,7 +23,7 @@ int uppm_formula_repo_remove(const char * formulaRepoName) { return UPPM_ERROR; } - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/generate-url-transform-sample.c b/src/generate-url-transform-sample.c index 26fc9e9..204928e 100644 --- a/src/generate-url-transform-sample.c +++ b/src/generate-url-transform-sample.c @@ -12,7 +12,7 @@ #include "uppm.h" int uppm_generate_url_transform_sample() { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/info.c b/src/info.c index ae8a567..d56c700 100644 --- a/src/info.c +++ b/src/info.c @@ -315,7 +315,7 @@ int uppm_info(const char * packageName, const char * key) { uppm_formula_free(formula); } else if (strcmp(key, "bin-fp") == 0) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); @@ -373,7 +373,7 @@ int uppm_info(const char * packageName, const char * key) { uppm_formula_free(formula); } else if (strcmp(key, "installed-dir") == 0) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); @@ -410,7 +410,7 @@ int uppm_info(const char * packageName, const char * key) { return UPPM_ERROR_PACKAGE_IS_BROKEN; } } else if (strcmp(key, "installed-files") == 0) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); @@ -487,7 +487,7 @@ int uppm_info(const char * packageName, const char * key) { } } } else if (strcmp(key, "installed-receipt-path") == 0) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); @@ -524,7 +524,7 @@ int uppm_info(const char * packageName, const char * key) { return UPPM_ERROR_PACKAGE_IS_BROKEN; } } else if (strcmp(key, "installed-receipt-yaml") == 0) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/install.c b/src/install.c index fa7a803..a843b01 100644 --- a/src/install.c +++ b/src/install.c @@ -63,7 +63,7 @@ int uppm_install(const char * packageName, bool verbose) { ////////////////////////////////////////////////////////////////////////// - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/integrate.c b/src/integrate.c index 3812979..7a45b53 100644 --- a/src/integrate.c +++ b/src/integrate.c @@ -68,7 +68,7 @@ static int mkdir_p(const char * dir, bool verbose) { } int uppm_integrate_zsh_completion(const char * outputDIR, bool verbose) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/list-installed-packages.c b/src/list-installed-packages.c index fda9052..ef52f97 100644 --- a/src/list-installed-packages.c +++ b/src/list-installed-packages.c @@ -9,7 +9,7 @@ #include "uppm.h" int uppm_list_the_installed_packages() { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/list-outdated-packages.c b/src/list-outdated-packages.c index 9422ff9..e235fd2 100644 --- a/src/list-outdated-packages.c +++ b/src/list-outdated-packages.c @@ -8,7 +8,7 @@ #include "uppm.h" int uppm_list_the_outdated__packages() { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/receipt-parse.c b/src/receipt-parse.c index 3baa5ad..dc0c37a 100644 --- a/src/receipt-parse.c +++ b/src/receipt-parse.c @@ -340,7 +340,7 @@ int uppm_receipt_parse(const char * packageName, UPPMReceipt * * out) { return ret; } - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/session.c b/src/session.c index a72ff7c..6f41cdf 100644 --- a/src/session.c +++ b/src/session.c @@ -10,7 +10,7 @@ #include "uppm.h" int uppm_session_dir(char buf[], size_t bufSize, size_t * outSize) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/tree.c b/src/tree.c index 29aeb2a..852da87 100644 --- a/src/tree.c +++ b/src/tree.c @@ -13,7 +13,7 @@ int uppm_tree(const char * packageName, size_t argc, char* argv[]) { return ret; } - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/uninstall.c b/src/uninstall.c index e4eecf2..1bb4bca 100644 --- a/src/uninstall.c +++ b/src/uninstall.c @@ -13,7 +13,7 @@ int uppm_uninstall(const char * packageName, bool verbose) { return ret; } - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength); diff --git a/src/upgrade-self.c b/src/upgrade-self.c index 83d1816..9a12597 100644 --- a/src/upgrade-self.c +++ b/src/upgrade-self.c @@ -12,7 +12,7 @@ #include "uppm.h" int uppm_upgrade_self(bool verbose) { - char uppmHomeDIR[256]; + char uppmHomeDIR[256] = {0}; size_t uppmHomeDIRLength; int ret = uppm_home_dir(uppmHomeDIR, 255, &uppmHomeDIRLength);