From be1def43618608bbd4b662beb0053824d41042e1 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Tue, 28 May 2024 15:30:22 +0200 Subject: [PATCH] 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 --- src/lib/defect.hh | 9 ++++++ src/lib/filter.cc | 3 ++ .../csgrep/0110-warning-rate-limit-stdout.txt | 10 +++---- .../0116-csgrep-warning-rate-limit-stdout.txt | 28 +++++++++---------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/lib/defect.hh b/src/lib/defect.hh index 809b864c..554b7ee6 100644 --- a/src/lib/defect.hh +++ b/src/lib/defect.hh @@ -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 diff --git a/src/lib/filter.cc b/src/lib/filter.cc index 1f4d794c..8659772f 100644 --- a/src/lib/filter.cc +++ b/src/lib/filter.cc @@ -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"; diff --git a/tests/csgrep/0110-warning-rate-limit-stdout.txt b/tests/csgrep/0110-warning-rate-limit-stdout.txt index 16b6feaf..7ddf38b8 100644 --- a/tests/csgrep/0110-warning-rate-limit-stdout.txt +++ b/tests/csgrep/0110-warning-rate-limit-stdout.txt @@ -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 @@ -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 diff --git a/tests/csgrep/0116-csgrep-warning-rate-limit-stdout.txt b/tests/csgrep/0116-csgrep-warning-rate-limit-stdout.txt index b393fb4e..dd543109 100644 --- a/tests/csgrep/0116-csgrep-warning-rate-limit-stdout.txt +++ b/tests/csgrep/0116-csgrep-warning-rate-limit-stdout.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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