Skip to content

Commit 9a3a622

Browse files
committed
parser-cov: search key event backwards
... only for RESOURCE_LEAK, UNINIT, and UNINIT_CTOR. Coverity is inconsistent in this and the plain-text parser in csdiff needs to follow it. Resolves: https://issues.redhat.com/browse/OSH-552 Closes: #165
1 parent ef2b40f commit 9a3a622

17 files changed

+53
-11326
lines changed

Diff for: src/lib/parser-cov.cc

+13-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct KeyEventDigger::Private {
206206
typedef std::set<std::string> TSet;
207207
typedef std::map<std::string, TSet> TMap;
208208
TMap hMap;
209-
TSet denyList, traceEvts;
209+
TSet denyList, traceEvts, searchBackwards;
210210
const RE reEvtSuffix = RE("^(.*)\\[[^ \\]]+\\]$");
211211
const std::string stripEvtName(const std::string &) const;
212212
};
@@ -331,6 +331,10 @@ KeyEventDigger::KeyEventDigger():
331331
// OWASP ZAP uses "alert" as the key event
332332
d->hMap["OWASP_ZAP_WARNING"] .insert("alert");
333333

334+
d->searchBackwards.insert("RESOURCE_LEAK");
335+
d->searchBackwards.insert("UNINIT");
336+
d->searchBackwards.insert("UNINIT_CTOR");
337+
334338
// events that should never be used as key events (excluding trace events)
335339
d->denyList.insert("another_instance");
336340
d->denyList.insert("comparison_remediation");
@@ -402,6 +406,7 @@ bool KeyEventDigger::guessKeyEvent(Defect *def)
402406
pKeyEvents = &it->second;
403407

404408
// look for an explicitly defined key event
409+
bool found = false;
405410
for (unsigned idx = 0U; idx < evtCount; ++idx) {
406411
const DefEvent &evt = evtList[idx];
407412
const std::string evtName = d->stripEvtName(evt.event);
@@ -410,9 +415,15 @@ bool KeyEventDigger::guessKeyEvent(Defect *def)
410415

411416
// matched
412417
def->keyEventIdx = idx;
413-
return true;
418+
found = true;
419+
if (!d->searchBackwards.count(def->checker))
420+
// checker not listed in d->searchBackwards --> take the first match
421+
break;
414422
}
415423

424+
if (found)
425+
return true;
426+
416427
// take the first eligible key event
417428
bool valid = false;
418429
for (unsigned idx = 0; idx < evtCount; ++idx) {

Diff for: tests/csdiff/diff-misc/17-cov-parser-key-event-add-z.err

-2,779
Large diffs are not rendered by default.

Diff for: tests/csdiff/diff-misc/17-cov-parser-key-event-add.err

-2,779
Large diffs are not rendered by default.

Diff for: tests/csdiff/diff-misc/17-cov-parser-key-event-fix-z.err

-2,779
Large diffs are not rendered by default.

Diff for: tests/csdiff/diff-misc/17-cov-parser-key-event-fix.err

-2,779
Large diffs are not rendered by default.

Diff for: tests/csdiff/diff7.0-icu/00-add-z.err

-32
Original file line numberDiff line numberDiff line change
@@ -660,26 +660,6 @@ Error: RESOURCE_LEAK:
660660
/builddir/build/BUILD/icu/source/i18n/decimfmt.cpp:3322: var_assign: Assigning: "fmt" = storage returned from "new icu_48::ChoiceFormat(struct icu_48::UnicodeString(s), ec)".
661661
/builddir/build/BUILD/icu/source/i18n/decimfmt.cpp:3333: leaked_storage: Variable "fmt" going out of scope leaks the storage it points to.
662662

663-
Error: RESOURCE_LEAK:
664-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: alloc_fn: Calling allocation function "uprv_malloc_48".
665-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
666-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: return_alloc_fn: Directly returning storage allocated by "malloc".
667-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: var_assign: Assigning: "strbuffer" = storage returned from "uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))".
668-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3542: var_assign: Assigning: "UCharOffset" = "strbuffer".
669-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3543: noescape: Variable "UCharOffset" is not freed or pointed-to in function "memcpy".
670-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: overwrite_var: Overwriting "strbuffer" in call "strbuffer = (UChar *)uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))" leaks the storage that "strbuffer" points to.
671-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3542: overwrite_var: Overwriting "UCharOffset" in call "UCharOffset = strbuffer + newsize" leaks the storage that "UCharOffset" points to.
672-
673-
Error: RESOURCE_LEAK:
674-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: alloc_fn: Calling allocation function "uprv_malloc_48".
675-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
676-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: return_alloc_fn: Directly returning storage allocated by "malloc".
677-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: var_assign: Assigning: "strbuffer" = storage returned from "uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))".
678-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3542: var_assign: Assigning: "UCharOffset" = "strbuffer".
679-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3543: noescape: Variable "UCharOffset" is not freed or pointed-to in function "memcpy".
680-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: overwrite_var: Overwriting "strbuffer" in call "strbuffer = (UChar *)uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))" leaks the storage that "strbuffer" points to.
681-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3540: leaked_storage: Variable "UCharOffset" going out of scope leaks the storage it points to.
682-
683663
Error: RESOURCE_LEAK:
684664
/builddir/build/BUILD/icu/source/i18n/ucurr.cpp:1864: alloc_fn: Calling allocation function "uprv_malloc_48".
685665
/builddir/build/BUILD/icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
@@ -1216,22 +1196,10 @@ Error: UNINIT_CTOR:
12161196
/builddir/build/BUILD/icu/source/i18n/tznames_impl.cpp:365: member_decl: Class member declaration for fStrings.
12171197
/builddir/build/BUILD/icu/source/i18n/tznames_impl.cpp:372: uninit_member: Non-static class member fStrings is not initialized in this constructor nor in any functions that it calls.
12181198

1219-
Error: UNINIT_CTOR:
1220-
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.h:108: member_decl: Class member declaration for fChecks.
1221-
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.cpp:62: uninit_member: Non-static class member fChecks is not initialized in this constructor nor in any functions that it calls.
1222-
12231199
Error: UNINIT_CTOR:
12241200
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.h:108: member_decl: Class member declaration for fChecks.
12251201
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.cpp:32: uninit_member: Non-static class member fChecks is not initialized in this constructor nor in any functions that it calls.
12261202

1227-
Error: UNINIT_CTOR:
1228-
/builddir/build/BUILD/icu/source/tools/toolutil/package.cpp:418: uninit_member: Non-static class member inStrings is not initialized in this constructor nor in any functions that it calls.
1229-
/builddir/build/BUILD/icu/source/tools/toolutil/package.cpp:418: uninit_member: Non-static class member isMissingItems is not initialized in this constructor nor in any functions that it calls.
1230-
/builddir/build/BUILD/icu/source/tools/toolutil/package.cpp:418: uninit_member: Non-static class member outStrings is not initialized in this constructor nor in any functions that it calls.
1231-
/builddir/build/BUILD/icu/source/tools/toolutil/package.h:156: member_decl: Class member declaration for inStrings.
1232-
/builddir/build/BUILD/icu/source/tools/toolutil/package.h:156: member_decl: Class member declaration for outStrings.
1233-
/builddir/build/BUILD/icu/source/tools/toolutil/package.h:167: member_decl: Class member declaration for isMissingItems.
1234-
12351203
Error: UNINIT_CTOR:
12361204
/builddir/build/BUILD/icu/source/tools/toolutil/denseranges.cpp:28: uninit_member: Non-static class member gapLengths is not initialized in this constructor nor in any functions that it calls.
12371205
/builddir/build/BUILD/icu/source/tools/toolutil/denseranges.cpp:28: uninit_member: Non-static class member gapStarts is not initialized in this constructor nor in any functions that it calls.

Diff for: tests/csdiff/diff7.0-icu/00-add.err

-32
Original file line numberDiff line numberDiff line change
@@ -660,26 +660,6 @@ Error: RESOURCE_LEAK:
660660
/builddir/build/BUILD/icu/source/i18n/decimfmt.cpp:3322: var_assign: Assigning: "fmt" = storage returned from "new icu_48::ChoiceFormat(struct icu_48::UnicodeString(s), ec)".
661661
/builddir/build/BUILD/icu/source/i18n/decimfmt.cpp:3333: leaked_storage: Variable "fmt" going out of scope leaks the storage it points to.
662662

663-
Error: RESOURCE_LEAK:
664-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: alloc_fn: Calling allocation function "uprv_malloc_48".
665-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
666-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: return_alloc_fn: Directly returning storage allocated by "malloc".
667-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: var_assign: Assigning: "strbuffer" = storage returned from "uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))".
668-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3542: var_assign: Assigning: "UCharOffset" = "strbuffer".
669-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3543: noescape: Variable "UCharOffset" is not freed or pointed-to in function "memcpy".
670-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: overwrite_var: Overwriting "strbuffer" in call "strbuffer = (UChar *)uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))" leaks the storage that "strbuffer" points to.
671-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3542: overwrite_var: Overwriting "UCharOffset" in call "UCharOffset = strbuffer + newsize" leaks the storage that "UCharOffset" points to.
672-
673-
Error: RESOURCE_LEAK:
674-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: alloc_fn: Calling allocation function "uprv_malloc_48".
675-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
676-
/builddir/build/BUILD/icu/source/common/cmemory.c:45: return_alloc_fn: Directly returning storage allocated by "malloc".
677-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: var_assign: Assigning: "strbuffer" = storage returned from "uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))".
678-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3542: var_assign: Assigning: "UCharOffset" = "strbuffer".
679-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3543: noescape: Variable "UCharOffset" is not freed or pointed-to in function "memcpy".
680-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3535: overwrite_var: Overwriting "strbuffer" in call "strbuffer = (UChar *)uprv_malloc_48(sizeof (UChar) /*2*/ * (newsize + 128))" leaks the storage that "strbuffer" points to.
681-
/builddir/build/BUILD/icu/source/i18n/ucol.cpp:3540: leaked_storage: Variable "UCharOffset" going out of scope leaks the storage it points to.
682-
683663
Error: RESOURCE_LEAK:
684664
/builddir/build/BUILD/icu/source/i18n/ucurr.cpp:1864: alloc_fn: Calling allocation function "uprv_malloc_48".
685665
/builddir/build/BUILD/icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
@@ -1216,22 +1196,10 @@ Error: UNINIT_CTOR:
12161196
/builddir/build/BUILD/icu/source/i18n/tznames_impl.cpp:365: member_decl: Class member declaration for fStrings.
12171197
/builddir/build/BUILD/icu/source/i18n/tznames_impl.cpp:372: uninit_member: Non-static class member fStrings is not initialized in this constructor nor in any functions that it calls.
12181198

1219-
Error: UNINIT_CTOR:
1220-
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.h:108: member_decl: Class member declaration for fChecks.
1221-
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.cpp:62: uninit_member: Non-static class member fChecks is not initialized in this constructor nor in any functions that it calls.
1222-
12231199
Error: UNINIT_CTOR:
12241200
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.h:108: member_decl: Class member declaration for fChecks.
12251201
/builddir/build/BUILD/icu/source/i18n/uspoof_impl.cpp:32: uninit_member: Non-static class member fChecks is not initialized in this constructor nor in any functions that it calls.
12261202

1227-
Error: UNINIT_CTOR:
1228-
/builddir/build/BUILD/icu/source/tools/toolutil/package.cpp:418: uninit_member: Non-static class member inStrings is not initialized in this constructor nor in any functions that it calls.
1229-
/builddir/build/BUILD/icu/source/tools/toolutil/package.cpp:418: uninit_member: Non-static class member isMissingItems is not initialized in this constructor nor in any functions that it calls.
1230-
/builddir/build/BUILD/icu/source/tools/toolutil/package.cpp:418: uninit_member: Non-static class member outStrings is not initialized in this constructor nor in any functions that it calls.
1231-
/builddir/build/BUILD/icu/source/tools/toolutil/package.h:156: member_decl: Class member declaration for inStrings.
1232-
/builddir/build/BUILD/icu/source/tools/toolutil/package.h:156: member_decl: Class member declaration for outStrings.
1233-
/builddir/build/BUILD/icu/source/tools/toolutil/package.h:167: member_decl: Class member declaration for isMissingItems.
1234-
12351203
Error: UNINIT_CTOR:
12361204
/builddir/build/BUILD/icu/source/tools/toolutil/denseranges.cpp:28: uninit_member: Non-static class member gapLengths is not initialized in this constructor nor in any functions that it calls.
12371205
/builddir/build/BUILD/icu/source/tools/toolutil/denseranges.cpp:28: uninit_member: Non-static class member gapStarts is not initialized in this constructor nor in any functions that it calls.

Diff for: tests/csdiff/diff7.0-icu/00-fix-z.err

-40
Original file line numberDiff line numberDiff line change
@@ -578,26 +578,6 @@ icu/source/i18n/basictz.cpp:353: noescape: Variable "res_initial" is not freed o
578578
icu/source/i18n/tzrule.cpp:78:15: noescape: "icu_44::TimeZoneRule::getDSTSavings() const" does not free or save its pointer parameter "this".
579579
icu/source/i18n/basictz.cpp:520: leaked_storage: Variable "res_initial" going out of scope leaks the storage it points to.
580580

581-
Error: RESOURCE_LEAK:
582-
icu/source/i18n/ucol.cpp:3400: alloc_fn: Calling allocation function "uprv_malloc_44".
583-
icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
584-
icu/source/common/cmemory.c:45: return_alloc_fn: Directly returning storage allocated by "malloc".
585-
icu/source/i18n/ucol.cpp:3400: var_assign: Assigning: "strbuffer" = storage returned from "uprv_malloc_44(sizeof (UChar) /*2*/ * (newsize + 128))".
586-
icu/source/i18n/ucol.cpp:3407: var_assign: Assigning: "UCharOffset" = "strbuffer".
587-
icu/source/i18n/ucol.cpp:3408: noescape: Variable "UCharOffset" is not freed or pointed-to in function "memcpy".
588-
icu/source/i18n/ucol.cpp:3400: overwrite_var: Overwriting "strbuffer" in call "strbuffer = (UChar *)uprv_malloc_44(sizeof (UChar) /*2*/ * (newsize + 128))" leaks the storage that "strbuffer" points to.
589-
icu/source/i18n/ucol.cpp:3407: overwrite_var: Overwriting "UCharOffset" in call "UCharOffset = strbuffer + newsize" leaks the storage that "UCharOffset" points to.
590-
591-
Error: RESOURCE_LEAK:
592-
icu/source/i18n/ucol.cpp:3400: alloc_fn: Calling allocation function "uprv_malloc_44".
593-
icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
594-
icu/source/common/cmemory.c:45: return_alloc_fn: Directly returning storage allocated by "malloc".
595-
icu/source/i18n/ucol.cpp:3400: var_assign: Assigning: "strbuffer" = storage returned from "uprv_malloc_44(sizeof (UChar) /*2*/ * (newsize + 128))".
596-
icu/source/i18n/ucol.cpp:3407: var_assign: Assigning: "UCharOffset" = "strbuffer".
597-
icu/source/i18n/ucol.cpp:3408: noescape: Variable "UCharOffset" is not freed or pointed-to in function "memcpy".
598-
icu/source/i18n/ucol.cpp:3400: overwrite_var: Overwriting "strbuffer" in call "strbuffer = (UChar *)uprv_malloc_44(sizeof (UChar) /*2*/ * (newsize + 128))" leaks the storage that "strbuffer" points to.
599-
icu/source/i18n/ucol.cpp:3405: leaked_storage: Variable "UCharOffset" going out of scope leaks the storage it points to.
600-
601581
Error: RESOURCE_LEAK:
602582
icu/source/i18n/ucol_elm.cpp:1249: alloc_fn: Calling allocation function "uprv_malloc_44".
603583
icu/source/common/cmemory.c:45: alloc_fn: Storage is returned from allocation function "malloc".
@@ -762,12 +742,6 @@ icu/source/i18n/plurfmt.cpp:70: uninit_member: Non-static class member numberFor
762742
icu/source/i18n/plurfmt.cpp:70: uninit_member: Non-static class member pluralRules is not initialized in this constructor nor in any functions that it calls.
763743
icu/source/i18n/plurfmt.cpp:70: uninit_member: Non-static class member replacedNumberFormat is not initialized in this constructor nor in any functions that it calls.
764744

765-
Error: UNINIT_CTOR:
766-
icu/source/i18n/uspoof_impl.h:111: member_decl: Class member declaration for fChecks.
767-
icu/source/i18n/uspoof_impl.h:115: member_decl: Class member declaration for fCheckMask.
768-
icu/source/i18n/uspoof_impl.cpp:62: uninit_member: Non-static class member fCheckMask is not initialized in this constructor nor in any functions that it calls.
769-
icu/source/i18n/uspoof_impl.cpp:62: uninit_member: Non-static class member fChecks is not initialized in this constructor nor in any functions that it calls.
770-
771745
Error: UNINIT_CTOR:
772746
icu/source/i18n/uspoof_impl.h:111: member_decl: Class member declaration for fChecks.
773747
icu/source/i18n/uspoof_impl.h:115: member_decl: Class member declaration for fCheckMask.
@@ -837,20 +811,6 @@ icu/source/tools/toolutil/package.cpp:411: uninit_member: Non-static class membe
837811
icu/source/tools/toolutil/package.h:37: member_decl: Class member declaration for name.
838812
icu/source/tools/toolutil/package.h:38: member_decl: Class member declaration for data.
839813

840-
Error: UNINIT_CTOR:
841-
icu/source/tools/toolutil/package.cpp:411: uninit_member: Non-static class member field items.isDataOwned is not initialized in this constructor nor in any functions that it calls.
842-
icu/source/tools/toolutil/package.cpp:411: uninit_member: Non-static class member field items.length is not initialized in this constructor nor in any functions that it calls.
843-
icu/source/tools/toolutil/package.cpp:411: uninit_member: Non-static class member field items.type is not initialized in this constructor nor in any functions that it calls.
844-
icu/source/tools/toolutil/package.cpp:411: uninit_member: Non-static class member inStrings is not initialized in this constructor nor in any functions that it calls.
845-
icu/source/tools/toolutil/package.cpp:411: uninit_member: Non-static class member isMissingItems is not initialized in this constructor nor in any functions that it calls.
846-
icu/source/tools/toolutil/package.cpp:411: uninit_member: Non-static class member outStrings is not initialized in this constructor nor in any functions that it calls.
847-
icu/source/tools/toolutil/package.h:39: member_decl: Class member declaration for length.
848-
icu/source/tools/toolutil/package.h:40: member_decl: Class member declaration for isDataOwned.
849-
icu/source/tools/toolutil/package.h:41: member_decl: Class member declaration for type.
850-
icu/source/tools/toolutil/package.h:151: member_decl: Class member declaration for inStrings.
851-
icu/source/tools/toolutil/package.h:151: member_decl: Class member declaration for outStrings.
852-
icu/source/tools/toolutil/package.h:162: member_decl: Class member declaration for isMissingItems.
853-
854814
Error: UNUSED_VALUE:
855815
icu/source/i18n/ucurr.cpp:1875: returned_pointer: Pointer "s" returned by "ures_getStringByKey_44(currencyRes, "id", &resLen, &localStatus)" is never used.
856816

0 commit comments

Comments
 (0)