From f46a9e3543d8a72b066f2a3e99490916ca318182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 20 Jan 2021 18:43:49 +0100 Subject: [PATCH] fixed/excluded some shellcheck warnings and actually fail the build when something is found (#3068) --- .github/workflows/scriptcheck.yml | 2 +- cve-test-suite/download.sh | 2 +- man/build-pdf.sh | 2 +- test/cfg/generate-cfg-tests.sh | 2 +- test/cfg/runtests.sh | 6 +--- test/synthetic/run-clang.sh | 1 + tools/daca2-logs2git.sh | 46 ++++++++++++++--------------- tools/extract_and_run_more_tests.sh | 4 +-- tools/run-coverity.sh | 4 +-- webreport.sh | 2 +- 10 files changed, 34 insertions(+), 37 deletions(-) diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index c92809a84..8652fbafc 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -26,7 +26,7 @@ jobs: - name: run Shellcheck run: | - find . -name "*.sh" | xargs shellcheck || true + find . -name "*.sh" | xargs shellcheck --exclude SC2002,SC2013,SC2034,SC2035,SC2043,SC2046,SC2086,SC2089,SC2090,SC2129,SC2211,SC2231 - name: run pylint run: | diff --git a/cve-test-suite/download.sh b/cve-test-suite/download.sh index 8e6e4ff4e..a1c9c7206 100755 --- a/cve-test-suite/download.sh +++ b/cve-test-suite/download.sh @@ -3,7 +3,7 @@ echo "CVE" > cve.txt -for i in `seq 1 20`; +for i in $(seq 1 20); do echo "page $i" # CVE 119 issues: diff --git a/man/build-pdf.sh b/man/build-pdf.sh index f9930ef01..648b01064 100755 --- a/man/build-pdf.sh +++ b/man/build-pdf.sh @@ -25,7 +25,7 @@ pandoc $1.md -o $1.pdf -s --number-sections --toc \ --listings \ -f markdown \ -V mainfont="$MainFont" \ - -V monofont="$Consolas" \ + -V monofont="$MonoFont" \ -V geometry:a4paper \ -V geometry:margin=2.4cm \ -V subparagraph \ diff --git a/test/cfg/generate-cfg-tests.sh b/test/cfg/generate-cfg-tests.sh index 3162f1c5b..885dc8572 100755 --- a/test/cfg/generate-cfg-tests.sh +++ b/test/cfg/generate-cfg-tests.sh @@ -1,5 +1,5 @@ #!/bin/bash -cd ~/cppcheck +cd ~/cppcheck || exit 1 make generate_cfg_tests ./generate_cfg_tests cfg/avr.cfg > test/cfg/generated-cfg-tests-avr.cpp ./generate_cfg_tests cfg/bsd.cfg > test/cfg/generated-cfg-tests-bsd.cpp diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index ecfe20732..b54195dea 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -401,11 +401,7 @@ set -e if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then echo "pkg-config needed to retrieve cppunit configuration is not available, skipping syntax check." else - set +e - CPPUNIT=$(pkg-config cppunit) - CPPUNIT_RETURNCODE=$? - set -e - if [ $CPPUNIT_RETURNCODE -ne 0 ]; then + if pkg-config cppunit; then echo "cppunit not found, skipping syntax check for cppunit" else echo "cppunit found, checking syntax with ${CXX} now." diff --git a/test/synthetic/run-clang.sh b/test/synthetic/run-clang.sh index 45fcac06b..3adf2600a 100755 --- a/test/synthetic/run-clang.sh +++ b/test/synthetic/run-clang.sh @@ -1,3 +1,4 @@ +#!/bin/bash ~/llvm/build/bin/clang -cc1 -analyze -analyzer-checker=alpha.security controlflow.c data.c functions.c 2>&1 /dev/null | grep warning ~/llvm/build/bin/clang -cc1 -analyze -analyzer-checker=alpha.security,core ub.c 2>&1 /dev/null | grep warning diff --git a/tools/daca2-logs2git.sh b/tools/daca2-logs2git.sh index 8523ff54c..3d990a719 100755 --- a/tools/daca2-logs2git.sh +++ b/tools/daca2-logs2git.sh @@ -8,7 +8,7 @@ base_url="http://cppcheck.sourceforge.net/devinfo/daca2-report/" echo ${base_url}daca2.html -for site in `curl -s --compressed ${base_url}daca2.html | grep "^/g;' > ${site} done @@ -24,37 +24,37 @@ grep "^-.*" /tmp/daca_tmp_diff > /tmp/daca_tmp_minus -plus_glob=`wc -l /tmp/daca_tmp_plus | cut -d' ' -f1` +plus_glob=$(wc -l /tmp/daca_tmp_plus | cut -d' ' -f1) -plus_error=`grep -c ":\ \(inconclusive\ \)\?error: " /tmp/daca_tmp_plus` -plus_warning=`grep -c ":\ \(inconclusive\ \)\?warning: " /tmp/daca_tmp_plus` -plus_style=`grep -c ":\ \(inconclusive\ \)\?style: " /tmp/daca_tmp_plus` -plus_performance=`grep -c ":\ \(inconclusive\ \)\?performance: " /tmp/daca_tmp_plus` -plus_portability=`grep -c ":\ \(inconclusive\ \)\?portability: " /tmp/daca_tmp_plus` -#plus_information=`grep -c "]: (information)" /tmp/daca_tmp_plus` -plus_crash=`grep -c "\ Crash?$" /tmp/daca_tmp_plus` -plus_varid=`grep -c "called with varid 0\." /tmp/daca_tmp_plus` +plus_error=$(grep -c ":\ \(inconclusive\ \)\?error: " /tmp/daca_tmp_plus) +plus_warning=$(grep -c ":\ \(inconclusive\ \)\?warning: " /tmp/daca_tmp_plus) +plus_style=$(grep -c ":\ \(inconclusive\ \)\?style: " /tmp/daca_tmp_plus) +plus_performance=$(grep -c ":\ \(inconclusive\ \)\?performance: " /tmp/daca_tmp_plus) +plus_portability=$(grep -c ":\ \(inconclusive\ \)\?portability: " /tmp/daca_tmp_plus) +#plus_information=$(grep -c "]: (information)" /tmp/daca_tmp_plus) +plus_crash=$(grep -c "\ Crash?$" /tmp/daca_tmp_plus) +plus_varid=$(grep -c "called with varid 0\." /tmp/daca_tmp_plus) -minus_glob=`wc -l /tmp/daca_tmp_minus | cut -d' ' -f1` +minus_glob=$(wc -l /tmp/daca_tmp_minus | cut -d' ' -f1) -minus_error=`grep -c ":\ \(inconclusive\ \)\?error: " /tmp/daca_tmp_minus` -minus_warning=`grep -c ":\ \(inconclusive\ \)\?warning: " /tmp/daca_tmp_minus` -minus_style=`grep -c ":\ \(inconclusive\ \)\?style: " /tmp/daca_tmp_minus` -minus_performance=`grep -c ":\ \(inconclusive\ \)\?performance: " /tmp/daca_tmp_minus` -minus_portability=`grep -c ":\ \(inconclusive\ \)\?portability: " /tmp/daca_tmp_minus` -#minus_information=`grep -c "]: (information)" /tmp/daca_tmp_minus` -minus_crash=`grep -c "\ Crash?$" /tmp/daca_tmp_minus` -minus_varid=`grep -c "called with varid 0\." /tmp/daca_tmp_minus` +minus_error=$(grep -c ":\ \(inconclusive\ \)\?error: " /tmp/daca_tmp_minus) +minus_warning=$(grep -c ":\ \(inconclusive\ \)\?warning: " /tmp/daca_tmp_minus) +minus_style=$(grep -c ":\ \(inconclusive\ \)\?style: " /tmp/daca_tmp_minus) +minus_performance=$(grep -c ":\ \(inconclusive\ \)\?performance: " /tmp/daca_tmp_minus) +minus_portability=$(grep -c ":\ \(inconclusive\ \)\?portability: " /tmp/daca_tmp_minus) +#minus_information=$(grep -c "]: (information)" /tmp/daca_tmp_minus) +minus_crash=$(grep -c "\ Crash?$" /tmp/daca_tmp_minus) +minus_varid=$(grep -c "called with varid 0\." /tmp/daca_tmp_minus) -files=`git ls-files` +files=$(git ls-files) -ID_stats=`awk '{ print $NF }' $files | grep "^\[.*\]$" | sort -n | uniq --count | sort -n` +ID_stats=$(awk '{ print $NF }' $files | grep "^\[.*\]$" | sort -n | uniq --count | sort -n) -echo "Update `date`" >> /tmp/daca_msg -echo "Updated: `git status --porcelain | grep daca | cut -d' ' -f3 | sed s/daca2-// | sed s/\.html// | tr '\n' ' '`" >> /tmp/daca_msg +echo "Update $(date)" >> /tmp/daca_msg +echo "Updated: $(git status --porcelain | grep daca | cut -d' ' -f3 | sed s/daca2-// | sed s/\.html// | tr '\n' ' ')" >> /tmp/daca_msg echo "all: new: $plus_glob gone: $minus_glob = $((plus_glob-minus_glob))" >> /tmp/daca_msg echo "error: new: $plus_error gone: $minus_error = $((plus_error-minus_error))" >> /tmp/daca_msg echo "warning: new: $plus_warning gone: $minus_warning = $((plus_warning-minus_warning))" >> /tmp/daca_msg diff --git a/tools/extract_and_run_more_tests.sh b/tools/extract_and_run_more_tests.sh index c564f9f17..f47d4132a 100755 --- a/tools/extract_and_run_more_tests.sh +++ b/tools/extract_and_run_more_tests.sh @@ -1,8 +1,8 @@ #!/bin/bash -cd ~/cppcheck +cd ~/cppcheck || exit 1 rm -rf test1 python tools/extracttests.py --code=test1 test/testleakautovar.cpp -cd ~/cppcheck/test1 +cd ~/cppcheck/test1 || exit 1 ~/cppcheck/tools/run_more_tests.sh diff --git a/tools/run-coverity.sh b/tools/run-coverity.sh index 689c24f4e..3404ffd30 100644 --- a/tools/run-coverity.sh +++ b/tools/run-coverity.sh @@ -1,6 +1,6 @@ #!/bin/bash PATH=$PATH:/home/danielmarjamaki/cov-analysis-linux64-2019.03/bin -cd /home/danielmarjamaki/cppcheck-devinfo +cd /home/danielmarjamaki/cppcheck-devinfo || exit 1 git pull echo Analyze @@ -15,7 +15,7 @@ curl --insecure \ --form token=e74RRnWR6BVsn5LKdclfcA \ --form email=daniel.marjamaki@gmail.com \ --form file=@cppcheck.tgz \ - --form version=`git log -1 --format=oneline | sed -r 's/([a-f0-9]{7}).*/\1/'` \ + --form version=$(git log -1 --format=oneline | sed -r 's/([a-f0-9]{7}).*/\1/') \ --form description="Development" \ https://scan.coverity.com/builds?project=cppcheck diff --git a/webreport.sh b/webreport.sh index 17d735f29..af9aec46a 100755 --- a/webreport.sh +++ b/webreport.sh @@ -10,7 +10,7 @@ mv coverage_report devinfo/ doxygen 2> devinfo/doxygen-errors.txt mv doxyoutput/html devinfo/doxyoutput -cd addons +cd addons || exit 1 doxygen cppcheckdata.doxyfile mv html ../devinfo/cppcheckdata cd ..