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 <michalx.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8503 (master)

(cherry-picked from commit 9d48662103)
Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
Change-Id: Ifbde973eae6e261d79e1c340eb28644bce5f4e45
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9801
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Michal Berger 2021-06-24 16:44:45 +02:00 committed by Tomasz Zawadzki
parent 49e5142b3c
commit 1cf67849c8
2 changed files with 4 additions and 3 deletions

View File

@ -489,17 +489,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

View File

@ -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