From 9d48662103c33c759d21cdda207d7d4597d8e161 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Thu, 24 Jun 2021 16:44:45 +0200 Subject: [PATCH] check_format: Ignore shellcheck's SC2128 and SC2178 directives These are currently prone to false-positives especially in terms of scoping. Consider the following: foo() { local bar=(42) echo "${bar[*]}" } bar=43 foo echo "$bar" Some versions of shellcheck, including the latest, 0.7.2, complain about $bar being reused as a plain string here. This is incorrect since foo() holds its own copy of bar[@] hence the assignment which takes place outside of it doesn't affect its content. SC2178 can be mitigated be reversing the order of declaration: bar=43 foo() { ... } ... but the SC2128 still remains. Currently, in our code majority of these warnings are coming from false-positives due to initial source'ing which most of our test scripts do (e.g. they fetch a function where local bar=() is used and in the test itself $bar happens to be assigned a plain string. This is still valid code). To mitigate, disable these directives untill shellcheck is capable of properly interpreting scoping when checking them. Signed-off-by: Michal Berger Change-Id: Ifbde973eae6e261d79e1c340eb28644bce5f4e45 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8503 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Karol Latecki Reviewed-by: Jim Harris --- scripts/check_format.sh | 4 +++- test/dpdk_memory_utility/test_dpdk_mem_info.sh | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 2e451344a..22e58ae64 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -480,17 +480,19 @@ function check_bash_static_analysis() { # SC2086: Double quote to prevent globbing and word splitting. # SC2119: Use foo "$@" if function's $1 should mean script's $1. # SC2120: foo references arguments, but none are ever passed. + # SC2128: Expanding an array without an index only gives the first element. # SC2148: Add shebang to the top of your script. # SC2153: Possible Misspelling: MYVARIABLE may not be assigned, but MY_VARIABLE is. # SC2154: var is referenced but not assigned. # SC2164: Use cd ... || exit in case cd fails. # SC2174: When used with -p, -m only applies to the deepest directory. + # SC2178: Variable was used as an array but is now assigned a string. # SC2206: Quote to prevent word splitting/globbing, # or split robustly with mapfile or read -a. # SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting). # SC2223: This default assignment may cause DoS due to globbing. Quote it. SHCK_EXCLUDE="$SHCK_EXCLUDE,SC1083,SC1090,SC1091,SC2010,SC2015,SC2016,SC2034,SC2046,SC2086,\ -SC2119,SC2120,SC2148,SC2153,SC2154,SC2164,SC2174,SC2001,SC2206,SC2207,SC2223" +SC2119,SC2120,SC2128,SC2148,SC2153,SC2154,SC2164,SC2174,SC2178,SC2001,SC2206,SC2207,SC2223" SHCK_FORMAT="tty" SHCK_APPLY=false diff --git a/test/dpdk_memory_utility/test_dpdk_mem_info.sh b/test/dpdk_memory_utility/test_dpdk_mem_info.sh index e49094635..59bea5314 100755 --- a/test/dpdk_memory_utility/test_dpdk_mem_info.sh +++ b/test/dpdk_memory_utility/test_dpdk_mem_info.sh @@ -5,10 +5,9 @@ rootdir=$(readlink -f $testdir/../..) source $rootdir/test/common/autotest_common.sh rpc_py="$rootdir/scripts/rpc.py" -SPDK_APP="$SPDK_BIN_DIR/spdk_tgt" MEM_SCRIPT="$rootdir/scripts/dpdk_mem_info.py" -$SPDK_APP & +"${SPDK_APP[@]}" & spdkpid=$! waitforlisten $spdkpid