Skip to content

Commit ffb37e8

Browse files
committed
deflookup: look by line content without spaces if available
Related: #98
1 parent b34d811 commit ffb37e8

15 files changed

+20696
-117
lines changed

Diff for: src/lib/deflookup.cc

+24-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "deflookup.hh"
2121

22+
#include "finger-print.hh"
2223
#include "msg-filter.hh"
2324
#include "parser.hh"
2425

@@ -79,8 +80,29 @@ void DefLookup::hashDefect(const Defect &def)
7980
defList.push_back(def);
8081
}
8182

82-
static bool defLookupCore(TDefList &defList)
83+
static bool defLookupCore(TDefList &defList, const Defect &lookFor)
8384
{
85+
// look by line content without spaces if available
86+
const std::string lineCont = FingerPrinter(lookFor).getLineContent();
87+
if (!lineCont.empty()) {
88+
bool fullLineContCoverage = true;
89+
90+
for (auto it = defList.begin(); it != defList.end(); ++it) {
91+
const std::string lineContNow = FingerPrinter(*it).getLineContent();
92+
if (lineContNow.empty())
93+
fullLineContCoverage = false;
94+
else if (lineCont == lineContNow) {
95+
// matched by line content without spaces
96+
defList.erase(it);
97+
return true;
98+
}
99+
}
100+
101+
if (fullLineContCoverage)
102+
// we had line content for all lines but none of them matched
103+
return false;
104+
}
105+
84106
// just remove an arbitrary one
85107
// TODO: add some other criteria in order to make the match more precise
86108
defList.resize(defList.size() - 1U);
@@ -132,7 +154,7 @@ bool DefLookup::lookup(const Defect &def)
132154
// process the resulting list of defects sequentially
133155
TDefList &defList = itByMsg->second;
134156
assert(!defList.empty());
135-
if (!defLookupCore(defList))
157+
if (!defLookupCore(defList, def))
136158
return false;
137159

138160
// remove empty maps to speed up subsequent lookups

Diff for: src/lib/finger-print.cc

+5
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@ std::string FingerPrinter::getHash(const EFingerPrintVer fpv) const
132132
// return SHA1 hash from basicData AND lineContent
133133
return computeHexSHA1(d->basicData + sep + d->lineContent);
134134
}
135+
136+
std::string FingerPrinter::getLineContent() const
137+
{
138+
return d->lineContent;
139+
}

Diff for: src/lib/finger-print.hh

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class FingerPrinter {
3838
/// return fingerprint of the selected kind
3939
std::string getHash(EFingerPrintVer) const;
4040

41+
/// return line content without spaces (empty string if not available)
42+
std::string getLineContent() const;
43+
4144
private:
4245
struct Private;
4346
std::unique_ptr<Private> d;

Diff for: tests/csdiff/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ test_csdiff(diff-misc 16-cov-parser-key-event)
8484
test_csdiff(diff-misc 17-cov-parser-key-event)
8585
test_csdiff(diff-misc 18-cov-parser-key-event)
8686
test_csdiff(diff-misc 19-cov-parser-key-event)
87+
test_csdiff(diff-misc 20-shellcheck-line-content)
8788
test_csdiff(diff-misc 21-kernel-shell-code)
8889
test_csdiff(diff-misc 22-kernel-zstream-path)
8990
test_csdiff(diff-misc 23-cov-parser-key-event)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Error: SHELLCHECK_WARNING (CWE-475):
2+
/usr/lib/dracut/modules.d/01fips/fips.sh:81:5: warning[SC2039]: In POSIX sh, 'local' is undefined.
3+
# 79| fips_load_crypto() {
4+
# 80| local _k
5+
# 81|-> local _v
6+
# 82| local _module
7+
# 83| local _found
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Error: SHELLCHECK_WARNING (CWE-475):
2+
/usr/lib/dracut/modules.d/01fips/fips.sh:81:5: warning[SC2039]: In POSIX sh, 'local' is undefined.
3+
# 79| fips_load_crypto() {
4+
# 80| local _k
5+
# 81|-> local _v
6+
# 82| local _module
7+
# 83| local _found

Diff for: tests/csdiff/diff-misc/20-shellcheck-line-content-fix-z.err

Whitespace-only changes.

Diff for: tests/csdiff/diff-misc/20-shellcheck-line-content-fix.err

Whitespace-only changes.

0 commit comments

Comments
 (0)