Skip to contentSkip to conversation

scripts: coccicheck: Correct usage of make coccicheck

PATCH Superseded Sumera Priyadarsini 2 participants 2 messages Nov 11, 2020 – Nov 17, 2020 Coccinelle/Semantic Patches (SmPL)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: coccicheck: Correct usage of make coccicheck

The command "make coccicheck C=1 CHECK=scripts/coccicheck" results in the error:
./scripts/coccicheck: line 65: -1: shift count out of range

This happens because every time the C variable is specified, the shell arguments need to be "shifted" in order to take only the last argument, which is the C file to test. These shell arguments mostly comprise flags that have been set in the Makefile. However, when coccicheck is specified in the make command as a rule, the number of shell arguments is zero, thus passing the invalid value -1 to the shift command, resulting in an error.

Modify coccicheck to print correct usage of make coccicheck so as to avoid the error.

---
 scripts/coccicheck | 12 ++++++++++++
 1 file changed, 12 insertions(+)
scripts/coccicheck +12 -0
index 209bb0427b43..b990c8a60a94 100755
@@ -63,6 +63,18 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
 
     # Take only the last argument, which is the C file to test
     shift $(( $# - 1 ))
+    err=$?
+    if [[ $err -ne 0 ]]; then
+	    echo ''
+	    echo 'Specifying both the variable "C" and rule "coccicheck" in the make
+command results in a shift count error.'
+	    echo ''
+	    echo 'Try specifying "scripts/coccicheck" as a value for the CHECK variable instead.'
+	    echo ''
+	    echo 'Example:	make C=2 CHECK=scripts/coccicheck drivers/staging/wfx/hi_t.o'
+	    echo ''
+	    exit 1
+    fi
     OPTIONS="$COCCIINCLUDE $1"
 
     # No need to parallelize Coccinelle since this mode takes one input file.
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 12 lines · Sumera Priyadarsini

The command "make coccicheck C=1 CHECK=scripts/coccicheck" results in the error:
./scripts/coccicheck: line 65: -1: shift count out of range

This happens because every time the C variable is specified, the shell arguments need to be "shifted" in order to take only the last argument, which is the C file to test. These shell arguments mostly comprise flags that have been set in the Makefile. However, when coccicheck is specified in the make command as a rule, the number of shell arguments is zero, thus passing the invalid value -1 to the shift command, resulting in an error.

Quoted 2 lines

Modify coccicheck to print correct usage of make coccicheck so as to avoid the error.

With this, one still gets the error from shift. Could you move the test so that one only gets the error message?

julia

Quoted 33 lines
---
 scripts/coccicheck | 12 ++++++++++++
 1 file changed, 12 insertions(+)
scripts/coccicheck +12 -1
index 209bb0427b43..b990c8a60a94 100755
@@ -63,6 +63,18 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
 
     # Take only the last argument, which is the C file to test
     shift $(( $# - 1 ))
+    err=$?
+    if [[ $err -ne 0 ]]; then
+	    echo ''
+	    echo 'Specifying both the variable "C" and rule "coccicheck" in the make
+command results in a shift count error.'
+	    echo ''
+	    echo 'Try specifying "scripts/coccicheck" as a value for the CHECK variable instead.'
+	    echo ''
+	    echo 'Example:	make C=2 CHECK=scripts/coccicheck drivers/staging/wfx/hi_t.o'
+	    echo ''
+	    exit 1
+    fi
     OPTIONS="$COCCIINCLUDE $1"
 
     # No need to parallelize Coccinelle since this mode takes one input file.
--

2.25.1