Skip to content

Commit be1def4

Browse files
committed
csgrep --warning-rate-limit: drop location from key events
... to ease finding deduplication. If a checker is too noisy, a small change in the code could unexpectedly change the location (including the file path) of the `error[too-many]` key event, which would hamper the deduplication of findings. Related: https://issues.redhat.com/browse/OSH-496
1 parent 6517295 commit be1def4

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

src/lib/defect.hh

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ struct DefEvent {
6565
event(event)
6666
{
6767
}
68+
69+
void clearLoc()
70+
{
71+
this->fileName.clear();
72+
this->line = 0;
73+
this->column = 0;
74+
this->hSize = 0;
75+
this->vSize = 0;
76+
}
6877
};
6978

7079
///< return (end - beg) if it is positive and fits into target type, 0 otherwise

src/lib/filter.cc

+3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ void RateLimitter::flush()
281281
evtErr.event = "error[too-many]";
282282
evtErr.msg = err.str();
283283

284+
// drop location from the key event to ease finding deduplication
285+
evtErr.clearLoc();
286+
284287
// construct a note event
285288
note << (cnt - d->rateLimit) << " occurrences of "
286289
<< evtNote.event << " were discarded because of this";

tests/csgrep/0110-warning-rate-limit-stdout.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -1880,9 +1880,8 @@
18801880
"key_event_idx": 0,
18811881
"events": [
18821882
{
1883-
"file_name": "./doc/example/compiler-etc-dependencies/example-sessions/ompi-defaults.sh",
1884-
"line": 3,
1885-
"column": 8,
1883+
"file_name": "",
1884+
"line": 0,
18861885
"event": "error[too-many]",
18871886
"message": "115 occurrences of note[SC2086] exceeded the specified limit 16",
18881887
"verbosity_level": 0
@@ -1905,9 +1904,8 @@
19051904
"key_event_idx": 0,
19061905
"events": [
19071906
{
1908-
"file_name": "./init/bash_completion.in",
1909-
"line": 128,
1910-
"column": 37,
1907+
"file_name": "",
1908+
"line": 0,
19111909
"event": "error[too-many]",
19121910
"message": "29 occurrences of warning[SC2207] exceeded the specified limit 16",
19131911
"verbosity_level": 0

tests/csgrep/0116-csgrep-warning-rate-limit-stdout.txt

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"key_event_idx": 0,
2929
"events": [
3030
{
31-
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
32-
"line": 4988,
31+
"file_name": "",
32+
"line": 0,
3333
"event": "error[too-many]",
3434
"message": "1 occurrences of var_deref_model exceeded the specified limit 1",
3535
"verbosity_level": 0
@@ -52,8 +52,8 @@
5252
"key_event_idx": 0,
5353
"events": [
5454
{
55-
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
56-
"line": 5058,
55+
"file_name": "",
56+
"line": 0,
5757
"event": "error[too-many]",
5858
"message": "3 occurrences of var_deref_op exceeded the specified limit 1",
5959
"verbosity_level": 0
@@ -77,8 +77,8 @@
7777
"key_event_idx": 0,
7878
"events": [
7979
{
80-
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
81-
"line": 4600,
80+
"file_name": "",
81+
"line": 0,
8282
"event": "error[too-many]",
8383
"message": "2 occurrences of alloc_strlen exceeded the specified limit 1",
8484
"verbosity_level": 0
@@ -102,8 +102,8 @@
102102
"key_event_idx": 0,
103103
"events": [
104104
{
105-
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
106-
"line": 3811,
105+
"file_name": "",
106+
"line": 0,
107107
"event": "error[too-many]",
108108
"message": "1 occurrences of leaked_handle exceeded the specified limit 1",
109109
"verbosity_level": 0
@@ -127,8 +127,8 @@
127127
"key_event_idx": 0,
128128
"events": [
129129
{
130-
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
131-
"line": 4786,
130+
"file_name": "",
131+
"line": 0,
132132
"event": "error[too-many]",
133133
"message": "2 occurrences of leaked_storage exceeded the specified limit 1",
134134
"verbosity_level": 0
@@ -151,8 +151,8 @@
151151
"key_event_idx": 0,
152152
"events": [
153153
{
154-
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
155-
"line": 402,
154+
"file_name": "",
155+
"line": 0,
156156
"event": "error[too-many]",
157157
"message": "1 occurrences of fs_check_call exceeded the specified limit 1",
158158
"verbosity_level": 0
@@ -176,8 +176,8 @@
176176
"key_event_idx": 0,
177177
"events": [
178178
{
179-
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
180-
"line": 550,
179+
"file_name": "",
180+
"line": 0,
181181
"event": "error[too-many]",
182182
"message": "1 occurrences of uninit_use_in_call exceeded the specified limit 1",
183183
"verbosity_level": 0

0 commit comments

Comments
 (0)