Skip to content

Commit

Permalink
csgrep --warning-rate-limit: drop location from key events
Browse files Browse the repository at this point in the history
... 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
  • Loading branch information
kdudka committed May 28, 2024
1 parent 13e6f04 commit d237079
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
9 changes: 9 additions & 0 deletions src/lib/defect.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ struct DefEvent {
event(event)
{
}

void clearLoc()
{
this->fileName.clear();
this->line = 0;
this->column = 0;
this->hSize = 0;
this->vSize = 0;
}
};

///< return (end - beg) if it is positive and fits into target type, 0 otherwise
Expand Down
3 changes: 3 additions & 0 deletions src/lib/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ void RateLimitter::flush()
evtErr.event = "error[too-many]";
evtErr.msg = err.str();

// drop location from the key event to ease finding deduplication
evtErr.clearLoc();

// construct a note event
note << (cnt - d->rateLimit) << " occurrences of "
<< evtNote.event << " were discarded because of this";
Expand Down
10 changes: 4 additions & 6 deletions tests/csgrep/0110-warning-rate-limit-stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1880,9 +1880,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "./doc/example/compiler-etc-dependencies/example-sessions/ompi-defaults.sh",
"line": 3,
"column": 8,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "115 occurrences of note[SC2086] exceeded the specified limit 16",
"verbosity_level": 0
Expand All @@ -1905,9 +1904,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "./init/bash_completion.in",
"line": 128,
"column": 37,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "29 occurrences of warning[SC2207] exceeded the specified limit 16",
"verbosity_level": 0
Expand Down
28 changes: 14 additions & 14 deletions tests/csgrep/0116-csgrep-warning-rate-limit-stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 4988,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of var_deref_model exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -52,8 +52,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 5058,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "3 occurrences of var_deref_op exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -77,8 +77,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 4600,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "2 occurrences of alloc_strlen exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -102,8 +102,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 3811,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of leaked_handle exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -127,8 +127,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 4786,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "2 occurrences of leaked_storage exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -151,8 +151,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 402,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of fs_check_call exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -176,8 +176,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 550,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of uninit_use_in_call exceeded the specified limit 1",
"verbosity_level": 0
Expand Down

0 comments on commit d237079

Please sign in to comment.