Skip to content

Commit 247faea

Browse files
committed
csfilter: abstract out line numbers in ShellCheck reports
Reported-by: Jakub Jelen
1 parent 94eeb79 commit 247faea

9 files changed

+271
-1
lines changed

src/csfilter.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ MsgFilter::MsgFilter():
110110
d->addMsgFilter("VALGRIND_WARNING",
111111
" lost in loss record [0-9,]+ of [0-9,]+$", "");
112112

113+
// line numbers embedded in diagnostic messages produced by ShellCheck
114+
d->addMsgFilter("SHELLCHECK_WARNING",
115+
" on line [0-9]+\\.$", " on line NNNN.");
116+
113117
// pylint reports, either raw, or prospector-wrapped
114118
const std::vector<std::string> pylintCheckers= {
115119
"PROSPECTOR_WARNING",

tests/csdiff/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ test_csdiff(diff-misc 08)
7676
test_csdiff(diff-misc 09-shellcheck-raw)
7777
test_csdiff(diff-misc 10-pylint-copr)
7878
test_csdiff(diff-misc 11-pylint-copr-json)
79+
test_csdiff(diff-misc 12-shellcheck-sc222x)

tests/csdiff/diff-misc/12-shellcheck-sc222x-add-z.err

Whitespace-only changes.

tests/csdiff/diff-misc/12-shellcheck-sc222x-add.err

Whitespace-only changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Error: SHELLCHECK_WARNING (CWE-398):
2+
/usr/bin/gpgrt-config:44:25: error[SC2066]: Since you double quoted this, it will not word split, and the loop will only run once.
3+
# 42| # variant of get_attr for list (separated by ',')
4+
# 43| get_attr_l () {
5+
# 44|-> (IFS=', '; for x in "$(get_attr $1)"; do echo $x; done)
6+
# 45| }
7+
# 46|
8+
9+
Error: SHELLCHECK_WARNING (CWE-563):
10+
/usr/bin/gpgrt-config:564:6: warning[SC2034]: delimiter appears unused. Verify use (or export if used externally).
11+
# 562| --modversion)
12+
# 563| want_attr=Version
13+
# 564|-> delimiter="
14+
# 565| "
15+
# 566| ;;
16+
17+
Error: CPPCHECK_WARNING (CWE-664):
18+
libgpg-error-1.41/src/logging.c:1277: error[va_list_usedBeforeStarted]: va_list 'dummy_argptr' used before va_start() was called.
19+
# 1275| static va_list dummy_argptr;
20+
# 1276|
21+
# 1277|-> _gpgrt_logv_printhex (buffer, length, NULL, dummy_argptr);
22+
# 1278| }
23+
# 1279| }
24+
25+
Error: RESOURCE_LEAK (CWE-772):
26+
libgpg-error-1.41/src/mkheader.c:196: alloc_fn: Storage is returned from allocation function "fopen".
27+
libgpg-error-1.41/src/mkheader.c:196: var_assign: Assigning: "fp" = storage returned from "fopen(fname, "r")".
28+
libgpg-error-1.41/src/mkheader.c:204: noescape: Resource "fp" is not freed or pointed-to in "fgets". [Note: The source code implementation of the function has been overridden by a builtin model.]
29+
libgpg-error-1.41/src/mkheader.c:243: noescape: Resource "fp" is not freed or pointed-to in "ferror".
30+
libgpg-error-1.41/src/mkheader.c:247: leaked_storage: Variable "fp" going out of scope leaks the storage it points to.
31+
# 245| fprintf (stderr, "%s:%d: error reading file: %s\n",
32+
# 246| fname, lnr, strerror (errno));
33+
# 247|-> return 1;
34+
# 248| }
35+
# 249|
36+
37+
Error: RESOURCE_LEAK (CWE-772):
38+
libgpg-error-1.41/src/spawn-posix.c:697: alloc_fn: Storage is returned from allocation function "_gpgrt_malloc".
39+
libgpg-error-1.41/src/spawn-posix.c:697: var_assign: Assigning: "r_exitcodes" = storage returned from "_gpgrt_malloc(4UL * count)".
40+
libgpg-error-1.41/src/spawn-posix.c:697: var_assign: Assigning: "dummy" = "r_exitcodes".
41+
libgpg-error-1.41/src/spawn-posix.c:707: leaked_storage: Variable "dummy" going out of scope leaks the storage it points to.
42+
libgpg-error-1.41/src/spawn-posix.c:707: leaked_storage: Returning without freeing "r_exitcodes" leaks the storage that it points to.
43+
# 705|
44+
# 706| if (pids[i] == (pid_t)(-1))
45+
# 707|-> return GPG_ERR_INV_VALUE;
46+
# 708|
47+
# 709| /* See if there was a previously stored result for this pid. */
48+
49+
Error: RESOURCE_LEAK (CWE-772):
50+
libgpg-error-1.41/tests/t-b64.c:100: alloc_fn: Storage is returned from allocation function "gpgrt_b64enc_start".
51+
libgpg-error-1.41/tests/t-b64.c:100: var_assign: Assigning: "state" = storage returned from "gpgrt_b64enc_start(fp, title)".
52+
libgpg-error-1.41/tests/t-b64.c:108: noescape: Resource "state" is not freed or pointed-to in "gpgrt_b64enc_write".
53+
libgpg-error-1.41/tests/t-b64.c:112: leaked_storage: Variable "state" going out of scope leaks the storage it points to.
54+
# 110| {
55+
# 111| fail ("gpgrt_b64enc_write failed: %s\n", gpg_strerror (err));
56+
# 112|-> return err;
57+
# 113| }
58+
# 114|
59+
60+
Error: RESOURCE_LEAK (CWE-772):
61+
libgpg-error-1.41/tests/t-b64.c:151: alloc_fn: Storage is returned from allocation function "malloc".
62+
libgpg-error-1.41/tests/t-b64.c:151: var_assign: Assigning: "buffer" = storage returned from "malloc(strlen(string) + 1UL)".
63+
libgpg-error-1.41/tests/t-b64.c:157: noescape: Resource "buffer" is not freed or pointed-to in "strcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
64+
libgpg-error-1.41/tests/t-b64.c:168: noescape: Resource "buffer" is not freed or pointed-to in "gpgrt_b64dec_proc".
65+
libgpg-error-1.41/tests/t-b64.c:194: leaked_storage: Variable "buffer" going out of scope leaks the storage it points to.
66+
# 192| strlen (expected));
67+
# 193| }
68+
# 194|-> return GPG_ERR_FALSE;
69+
# 195| }
70+
# 196|
71+
72+
Error: CPPCHECK_WARNING (CWE-404):
73+
libgpg-error-1.41/tests/t-syserror.c:53: error[resourceLeak]: Resource leak: fp
74+
# 51| {
75+
# 52| fprintf (stderr, "unable to run test\n");
76+
# 53|-> return 1;
77+
# 54| }
78+
# 55| save_errno = errno;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Error: SHELLCHECK_WARNING (CWE-398):
2+
/usr/bin/gpgrt-config:44:25: error[SC2066]: Since you double quoted this, it will not word split, and the loop will only run once.
3+
# 42| # variant of get_attr for list (separated by ',')
4+
# 43| get_attr_l () {
5+
# 44|-> (IFS=', '; for x in "$(get_attr $1)"; do echo $x; done)
6+
# 45| }
7+
# 46|
8+
9+
Error: SHELLCHECK_WARNING (CWE-563):
10+
/usr/bin/gpgrt-config:564:6: warning[SC2034]: delimiter appears unused. Verify use (or export if used externally).
11+
# 562| --modversion)
12+
# 563| want_attr=Version
13+
# 564|-> delimiter="
14+
# 565| "
15+
# 566| ;;
16+
17+
Error: CPPCHECK_WARNING (CWE-664):
18+
libgpg-error-1.41/src/logging.c:1277: error[va_list_usedBeforeStarted]: va_list 'dummy_argptr' used before va_start() was called.
19+
# 1275| static va_list dummy_argptr;
20+
# 1276|
21+
# 1277|-> _gpgrt_logv_printhex (buffer, length, NULL, dummy_argptr);
22+
# 1278| }
23+
# 1279| }
24+
25+
Error: RESOURCE_LEAK (CWE-772):
26+
libgpg-error-1.41/src/mkheader.c:196: alloc_fn: Storage is returned from allocation function "fopen".
27+
libgpg-error-1.41/src/mkheader.c:196: var_assign: Assigning: "fp" = storage returned from "fopen(fname, "r")".
28+
libgpg-error-1.41/src/mkheader.c:204: noescape: Resource "fp" is not freed or pointed-to in "fgets". [Note: The source code implementation of the function has been overridden by a builtin model.]
29+
libgpg-error-1.41/src/mkheader.c:243: noescape: Resource "fp" is not freed or pointed-to in "ferror".
30+
libgpg-error-1.41/src/mkheader.c:247: leaked_storage: Variable "fp" going out of scope leaks the storage it points to.
31+
# 245| fprintf (stderr, "%s:%d: error reading file: %s\n",
32+
# 246| fname, lnr, strerror (errno));
33+
# 247|-> return 1;
34+
# 248| }
35+
# 249|
36+
37+
Error: RESOURCE_LEAK (CWE-772):
38+
libgpg-error-1.41/src/spawn-posix.c:697: alloc_fn: Storage is returned from allocation function "_gpgrt_malloc".
39+
libgpg-error-1.41/src/spawn-posix.c:697: var_assign: Assigning: "r_exitcodes" = storage returned from "_gpgrt_malloc(4UL * count)".
40+
libgpg-error-1.41/src/spawn-posix.c:697: var_assign: Assigning: "dummy" = "r_exitcodes".
41+
libgpg-error-1.41/src/spawn-posix.c:707: leaked_storage: Variable "dummy" going out of scope leaks the storage it points to.
42+
libgpg-error-1.41/src/spawn-posix.c:707: leaked_storage: Returning without freeing "r_exitcodes" leaks the storage that it points to.
43+
# 705|
44+
# 706| if (pids[i] == (pid_t)(-1))
45+
# 707|-> return GPG_ERR_INV_VALUE;
46+
# 708|
47+
# 709| /* See if there was a previously stored result for this pid. */
48+
49+
Error: RESOURCE_LEAK (CWE-772):
50+
libgpg-error-1.41/tests/t-b64.c:100: alloc_fn: Storage is returned from allocation function "gpgrt_b64enc_start".
51+
libgpg-error-1.41/tests/t-b64.c:100: var_assign: Assigning: "state" = storage returned from "gpgrt_b64enc_start(fp, title)".
52+
libgpg-error-1.41/tests/t-b64.c:108: noescape: Resource "state" is not freed or pointed-to in "gpgrt_b64enc_write".
53+
libgpg-error-1.41/tests/t-b64.c:112: leaked_storage: Variable "state" going out of scope leaks the storage it points to.
54+
# 110| {
55+
# 111| fail ("gpgrt_b64enc_write failed: %s\n", gpg_strerror (err));
56+
# 112|-> return err;
57+
# 113| }
58+
# 114|
59+
60+
Error: RESOURCE_LEAK (CWE-772):
61+
libgpg-error-1.41/tests/t-b64.c:151: alloc_fn: Storage is returned from allocation function "malloc".
62+
libgpg-error-1.41/tests/t-b64.c:151: var_assign: Assigning: "buffer" = storage returned from "malloc(strlen(string) + 1UL)".
63+
libgpg-error-1.41/tests/t-b64.c:157: noescape: Resource "buffer" is not freed or pointed-to in "strcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
64+
libgpg-error-1.41/tests/t-b64.c:168: noescape: Resource "buffer" is not freed or pointed-to in "gpgrt_b64dec_proc".
65+
libgpg-error-1.41/tests/t-b64.c:194: leaked_storage: Variable "buffer" going out of scope leaks the storage it points to.
66+
# 192| strlen (expected));
67+
# 193| }
68+
# 194|-> return GPG_ERR_FALSE;
69+
# 195| }
70+
# 196|
71+
72+
Error: CPPCHECK_WARNING (CWE-404):
73+
libgpg-error-1.41/tests/t-syserror.c:53: error[resourceLeak]: Resource leak: fp
74+
# 51| {
75+
# 52| fprintf (stderr, "unable to run test\n");
76+
# 53|-> return 1;
77+
# 54| }
78+
# 55| save_errno = errno;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Error: SHELLCHECK_WARNING (CWE-569):
2+
/usr/bin/gpgrt-config:121:3: warning[SC2221]: This pattern always overrides a later one on line 132.
3+
# 119| if [ -n "$_reading_attrs" ]; then
4+
# 120| case "$_line" in
5+
# 121|-> *:\ *)
6+
# 122| _key="${_line%%:\ *}"
7+
# 123| _value="${_line#*:\ }"
8+
9+
Error: SHELLCHECK_WARNING (CWE-569):
10+
/usr/bin/gpgrt-config:132:6: warning[SC2222]: This pattern never matches because of a previous pattern on line 121.
11+
# 130| EOF2
12+
# 131| ;;
13+
# 132|-> *:|*:\ ) ;;
14+
# 133| *)
15+
# 134| echo "Error reading $_filename: $_line" 1>&2
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Error: SHELLCHECK_WARNING (CWE-398):
2+
/usr/bin/gpgrt-config:44:25: error[SC2066]: Since you double quoted this, it will not word split, and the loop will only run once.
3+
# 42| # variant of get_attr for list (separated by ',')
4+
# 43| get_attr_l () {
5+
# 44|-> (IFS=', '; for x in "$(get_attr $1)"; do echo $x; done)
6+
# 45| }
7+
# 46|
8+
9+
Error: SHELLCHECK_WARNING (CWE-569):
10+
/usr/bin/gpgrt-config:120:3: warning[SC2221]: This pattern always overrides a later one on line 131.
11+
# 118| if [ -n "$_reading_attrs" ]; then
12+
# 119| case "$_line" in
13+
# 120|-> *:\ *)
14+
# 121| _key="${_line%%:\ *}"
15+
# 122| _value="${_line#*:\ }"
16+
17+
Error: SHELLCHECK_WARNING (CWE-569):
18+
/usr/bin/gpgrt-config:131:6: warning[SC2222]: This pattern never matches because of a previous pattern on line 120.
19+
# 129| EOF2
20+
# 130| ;;
21+
# 131|-> *:|*:\ ) ;;
22+
# 132| *)
23+
# 133| echo "Error reading $_filename: $_line" 1>&2
24+
25+
Error: SHELLCHECK_WARNING (CWE-563):
26+
/usr/bin/gpgrt-config:564:6: warning[SC2034]: delimiter appears unused. Verify use (or export if used externally).
27+
# 562| --modversion)
28+
# 563| want_attr=Version
29+
# 564|-> delimiter="
30+
# 565| "
31+
# 566| ;;
32+
33+
Error: CPPCHECK_WARNING (CWE-664):
34+
libgpg-error-1.41/src/logging.c:1277: error[va_list_usedBeforeStarted]: va_list 'dummy_argptr' used before va_start() was called.
35+
# 1275| static va_list dummy_argptr;
36+
# 1276|
37+
# 1277|-> _gpgrt_logv_printhex (buffer, length, NULL, dummy_argptr);
38+
# 1278| }
39+
# 1279| }
40+
41+
Error: RESOURCE_LEAK (CWE-772):
42+
libgpg-error-1.41/src/mkheader.c:196: alloc_fn: Storage is returned from allocation function "fopen".
43+
libgpg-error-1.41/src/mkheader.c:196: var_assign: Assigning: "fp" = storage returned from "fopen(fname, "r")".
44+
libgpg-error-1.41/src/mkheader.c:204: noescape: Resource "fp" is not freed or pointed-to in "fgets". [Note: The source code implementation of the function has been overridden by a builtin model.]
45+
libgpg-error-1.41/src/mkheader.c:243: noescape: Resource "fp" is not freed or pointed-to in "ferror".
46+
libgpg-error-1.41/src/mkheader.c:247: leaked_storage: Variable "fp" going out of scope leaks the storage it points to.
47+
# 245| fprintf (stderr, "%s:%d: error reading file: %s\n",
48+
# 246| fname, lnr, strerror (errno));
49+
# 247|-> return 1;
50+
# 248| }
51+
# 249|
52+
53+
Error: RESOURCE_LEAK (CWE-772):
54+
libgpg-error-1.41/src/spawn-posix.c:697: alloc_fn: Storage is returned from allocation function "_gpgrt_malloc".
55+
libgpg-error-1.41/src/spawn-posix.c:697: var_assign: Assigning: "r_exitcodes" = storage returned from "_gpgrt_malloc(4UL * count)".
56+
libgpg-error-1.41/src/spawn-posix.c:697: var_assign: Assigning: "dummy" = "r_exitcodes".
57+
libgpg-error-1.41/src/spawn-posix.c:707: leaked_storage: Variable "dummy" going out of scope leaks the storage it points to.
58+
libgpg-error-1.41/src/spawn-posix.c:707: leaked_storage: Returning without freeing "r_exitcodes" leaks the storage that it points to.
59+
# 705|
60+
# 706| if (pids[i] == (pid_t)(-1))
61+
# 707|-> return GPG_ERR_INV_VALUE;
62+
# 708|
63+
# 709| /* See if there was a previously stored result for this pid. */
64+
65+
Error: RESOURCE_LEAK (CWE-772):
66+
libgpg-error-1.41/tests/t-b64.c:100: alloc_fn: Storage is returned from allocation function "gpgrt_b64enc_start".
67+
libgpg-error-1.41/tests/t-b64.c:100: var_assign: Assigning: "state" = storage returned from "gpgrt_b64enc_start(fp, title)".
68+
libgpg-error-1.41/tests/t-b64.c:108: noescape: Resource "state" is not freed or pointed-to in "gpgrt_b64enc_write".
69+
libgpg-error-1.41/tests/t-b64.c:112: leaked_storage: Variable "state" going out of scope leaks the storage it points to.
70+
# 110| {
71+
# 111| fail ("gpgrt_b64enc_write failed: %s\n", gpg_strerror (err));
72+
# 112|-> return err;
73+
# 113| }
74+
# 114|
75+
76+
Error: RESOURCE_LEAK (CWE-772):
77+
libgpg-error-1.41/tests/t-b64.c:151: alloc_fn: Storage is returned from allocation function "malloc".
78+
libgpg-error-1.41/tests/t-b64.c:151: var_assign: Assigning: "buffer" = storage returned from "malloc(strlen(string) + 1UL)".
79+
libgpg-error-1.41/tests/t-b64.c:157: noescape: Resource "buffer" is not freed or pointed-to in "strcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
80+
libgpg-error-1.41/tests/t-b64.c:168: noescape: Resource "buffer" is not freed or pointed-to in "gpgrt_b64dec_proc".
81+
libgpg-error-1.41/tests/t-b64.c:194: leaked_storage: Variable "buffer" going out of scope leaks the storage it points to.
82+
# 192| strlen (expected));
83+
# 193| }
84+
# 194|-> return GPG_ERR_FALSE;
85+
# 195| }
86+
# 196|
87+
88+
Error: CPPCHECK_WARNING (CWE-404):
89+
libgpg-error-1.41/tests/t-syserror.c:53: error[resourceLeak]: Resource leak: fp
90+
# 51| {
91+
# 52| fprintf (stderr, "unable to run test\n");
92+
# 53|-> return 1;
93+
# 54| }
94+
# 55| save_errno = errno;

tests/csdiff/diff-misc/sync.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/zsh
22
set -x
33

4-
csdiff=$(realpath ../../csdiff_build/csdiff)
4+
csdiff=$(realpath ../../../csdiff_build/src/csdiff)
55
test -x "$csdiff" || exit $?
66

77
for old in *-old.err; do

0 commit comments

Comments
 (0)