Skip to content

Commit 7becf39

Browse files
committed
csparser: pick last event as key event
... even if all the events are deny-listed for key event
1 parent d2b7828 commit 7becf39

File tree

5 files changed

+308
-11
lines changed

5 files changed

+308
-11
lines changed

src/csparser.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,20 +361,26 @@ bool KeyEventDigger::guessKeyEvent(Defect *def)
361361
}
362362

363363
// use the last event as key event by default (unless deny-listed)
364-
for (int idx = evtCount - 1U; idx >= 0; --idx) {
365-
const DefEvent &evt = evtList[idx];
366-
if (evt.event == "#")
367-
// never use comment as the key event
368-
continue;
364+
for (int pass = 0; pass < 2; ++pass) {
365+
for (int idx = evtCount - 1U; idx >= 0; --idx) {
366+
const DefEvent &evt = evtList[idx];
367+
if (evt.event == "#")
368+
// never use comment as the key event
369+
continue;
370+
369371

370-
const std::string &evtName = evt.event;
371-
if (d->traceEvts.count(evtName) || d->denyList.count(evtName))
372372
// never use trace or deny-listed event as the key event
373-
continue;
373+
// (but pick the last one of there are no other events)
374+
if (!pass) {
375+
const std::string &evtName = evt.event;
376+
if (d->traceEvts.count(evtName) || d->denyList.count(evtName))
377+
continue;
378+
}
374379

375-
// matched
376-
def->keyEventIdx = idx;
377-
return true;
380+
// matched
381+
def->keyEventIdx = idx;
382+
return true;
383+
}
378384
}
379385

380386
// no valid key event
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--mode=json
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Error: COMPILER_WARNING (CWE-758):
2+
boost_1_75_0/boost/smart_ptr/detail/sp_thread_sleep.hpp:22: included_from: Included from here.
3+
boost_1_75_0/boost/smart_ptr/detail/yield_k.hpp:23: included_from: Included from here.
4+
boost_1_75_0/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14: included_from: Included from here.
5+
boost_1_75_0/boost/smart_ptr/detail/spinlock.hpp:42: included_from: Included from here.
6+
boost_1_75_0/boost/smart_ptr/detail/spinlock_pool.hpp:25: included_from: Included from here.
7+
boost_1_75_0/boost/smart_ptr/shared_ptr.hpp:29: included_from: Included from here.
8+
boost_1_75_0/boost/shared_ptr.hpp:17: included_from: Included from here.
9+
boost_1_75_0/boost/program_options/options_description.hpp:16: included_from: Included from here.
10+
boost_1_75_0/boost/program_options/detail/cmdline.hpp:14: included_from: Included from here.
11+
boost_1_75_0/libs/program_options/src/cmdline.cpp:11: included_from: Included from here.
12+
boost_1_75_0/boost/config/pragma_message.hpp:24:34: note: '#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.'
13+
# 22| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ "(" BOOST_STRINGIZE(__LINE__) "): note: " x))
14+
# 23| #elif defined(__GNUC__)
15+
# 24|-> # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
16+
# 25| #elif defined(_MSC_VER)
17+
# 26| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ "(" BOOST_STRINGIZE(__LINE__) "): note: " x))
18+
19+
Error: COMPILER_WARNING (CWE-758):
20+
boost_1_75_0/boost/smart_ptr/detail/sp_thread_sleep.hpp:22: included_from: Included from here.
21+
boost_1_75_0/boost/smart_ptr/detail/yield_k.hpp:23: included_from: Included from here.
22+
boost_1_75_0/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14: included_from: Included from here.
23+
boost_1_75_0/boost/smart_ptr/detail/spinlock.hpp:42: included_from: Included from here.
24+
boost_1_75_0/boost/smart_ptr/detail/spinlock_pool.hpp:25: included_from: Included from here.
25+
boost_1_75_0/boost/smart_ptr/shared_ptr.hpp:29: included_from: Included from here.
26+
boost_1_75_0/boost/property_map/vector_property_map.hpp:14: included_from: Included from here.
27+
boost_1_75_0/boost/property_map/property_map.hpp:602: included_from: Included from here.
28+
boost_1_75_0/boost/graph/graphviz.hpp:19: included_from: Included from here.
29+
boost_1_75_0/boost/graph/graphml.hpp:20: included_from: Included from here.
30+
boost_1_75_0/libs/graph/src/graphml.cpp:17: included_from: Included from here.
31+
boost_1_75_0/boost/config/pragma_message.hpp:24:34: note: '#pragma message: This header is deprecated. Use <iterator> instead.'
32+
# 22| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ "(" BOOST_STRINGIZE(__LINE__) "): note: " x))
33+
# 23| #elif defined(__GNUC__)
34+
# 24|-> # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
35+
# 25| #elif defined(_MSC_VER)
36+
# 26| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ "(" BOOST_STRINGIZE(__LINE__) "): note: " x))
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
{
2+
"defects": [
3+
{
4+
"checker": "COMPILER_WARNING",
5+
"cwe": 758,
6+
"language": "c/c++",
7+
"key_event_idx": 10,
8+
"events": [
9+
{
10+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/sp_thread_sleep.hpp",
11+
"line": 22,
12+
"event": "included_from",
13+
"message": "Included from here.",
14+
"verbosity_level": "1"
15+
},
16+
{
17+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/yield_k.hpp",
18+
"line": 23,
19+
"event": "included_from",
20+
"message": "Included from here.",
21+
"verbosity_level": "1"
22+
},
23+
{
24+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp",
25+
"line": 14,
26+
"event": "included_from",
27+
"message": "Included from here.",
28+
"verbosity_level": "1"
29+
},
30+
{
31+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/spinlock.hpp",
32+
"line": 42,
33+
"event": "included_from",
34+
"message": "Included from here.",
35+
"verbosity_level": "1"
36+
},
37+
{
38+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/spinlock_pool.hpp",
39+
"line": 25,
40+
"event": "included_from",
41+
"message": "Included from here.",
42+
"verbosity_level": "1"
43+
},
44+
{
45+
"file_name": "boost_1_75_0/boost/smart_ptr/shared_ptr.hpp",
46+
"line": 29,
47+
"event": "included_from",
48+
"message": "Included from here.",
49+
"verbosity_level": "1"
50+
},
51+
{
52+
"file_name": "boost_1_75_0/boost/shared_ptr.hpp",
53+
"line": 17,
54+
"event": "included_from",
55+
"message": "Included from here.",
56+
"verbosity_level": "1"
57+
},
58+
{
59+
"file_name": "boost_1_75_0/boost/program_options/options_description.hpp",
60+
"line": 16,
61+
"event": "included_from",
62+
"message": "Included from here.",
63+
"verbosity_level": "1"
64+
},
65+
{
66+
"file_name": "boost_1_75_0/boost/program_options/detail/cmdline.hpp",
67+
"line": 14,
68+
"event": "included_from",
69+
"message": "Included from here.",
70+
"verbosity_level": "1"
71+
},
72+
{
73+
"file_name": "boost_1_75_0/libs/program_options/src/cmdline.cpp",
74+
"line": 11,
75+
"event": "included_from",
76+
"message": "Included from here.",
77+
"verbosity_level": "1"
78+
},
79+
{
80+
"file_name": "boost_1_75_0/boost/config/pragma_message.hpp",
81+
"line": 24,
82+
"column": 34,
83+
"event": "note",
84+
"message": "'#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.'",
85+
"verbosity_level": "0"
86+
},
87+
{
88+
"file_name": "",
89+
"line": 0,
90+
"event": "#",
91+
"message": " 22| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ \"(\" BOOST_STRINGIZE(__LINE__) \"): note: \" x))",
92+
"verbosity_level": "1"
93+
},
94+
{
95+
"file_name": "",
96+
"line": 0,
97+
"event": "#",
98+
"message": " 23| #elif defined(__GNUC__)",
99+
"verbosity_level": "1"
100+
},
101+
{
102+
"file_name": "",
103+
"line": 0,
104+
"event": "#",
105+
"message": " 24|-> # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))",
106+
"verbosity_level": "1"
107+
},
108+
{
109+
"file_name": "",
110+
"line": 0,
111+
"event": "#",
112+
"message": " 25| #elif defined(_MSC_VER)",
113+
"verbosity_level": "1"
114+
},
115+
{
116+
"file_name": "",
117+
"line": 0,
118+
"event": "#",
119+
"message": " 26| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ \"(\" BOOST_STRINGIZE(__LINE__) \"): note: \" x))",
120+
"verbosity_level": "1"
121+
}
122+
]
123+
},
124+
{
125+
"checker": "COMPILER_WARNING",
126+
"cwe": 758,
127+
"language": "c/c++",
128+
"key_event_idx": 11,
129+
"events": [
130+
{
131+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/sp_thread_sleep.hpp",
132+
"line": 22,
133+
"event": "included_from",
134+
"message": "Included from here.",
135+
"verbosity_level": "1"
136+
},
137+
{
138+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/yield_k.hpp",
139+
"line": 23,
140+
"event": "included_from",
141+
"message": "Included from here.",
142+
"verbosity_level": "1"
143+
},
144+
{
145+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp",
146+
"line": 14,
147+
"event": "included_from",
148+
"message": "Included from here.",
149+
"verbosity_level": "1"
150+
},
151+
{
152+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/spinlock.hpp",
153+
"line": 42,
154+
"event": "included_from",
155+
"message": "Included from here.",
156+
"verbosity_level": "1"
157+
},
158+
{
159+
"file_name": "boost_1_75_0/boost/smart_ptr/detail/spinlock_pool.hpp",
160+
"line": 25,
161+
"event": "included_from",
162+
"message": "Included from here.",
163+
"verbosity_level": "1"
164+
},
165+
{
166+
"file_name": "boost_1_75_0/boost/smart_ptr/shared_ptr.hpp",
167+
"line": 29,
168+
"event": "included_from",
169+
"message": "Included from here.",
170+
"verbosity_level": "1"
171+
},
172+
{
173+
"file_name": "boost_1_75_0/boost/property_map/vector_property_map.hpp",
174+
"line": 14,
175+
"event": "included_from",
176+
"message": "Included from here.",
177+
"verbosity_level": "1"
178+
},
179+
{
180+
"file_name": "boost_1_75_0/boost/property_map/property_map.hpp",
181+
"line": 602,
182+
"event": "included_from",
183+
"message": "Included from here.",
184+
"verbosity_level": "1"
185+
},
186+
{
187+
"file_name": "boost_1_75_0/boost/graph/graphviz.hpp",
188+
"line": 19,
189+
"event": "included_from",
190+
"message": "Included from here.",
191+
"verbosity_level": "1"
192+
},
193+
{
194+
"file_name": "boost_1_75_0/boost/graph/graphml.hpp",
195+
"line": 20,
196+
"event": "included_from",
197+
"message": "Included from here.",
198+
"verbosity_level": "1"
199+
},
200+
{
201+
"file_name": "boost_1_75_0/libs/graph/src/graphml.cpp",
202+
"line": 17,
203+
"event": "included_from",
204+
"message": "Included from here.",
205+
"verbosity_level": "1"
206+
},
207+
{
208+
"file_name": "boost_1_75_0/boost/config/pragma_message.hpp",
209+
"line": 24,
210+
"column": 34,
211+
"event": "note",
212+
"message": "'#pragma message: This header is deprecated. Use <iterator> instead.'",
213+
"verbosity_level": "0"
214+
},
215+
{
216+
"file_name": "",
217+
"line": 0,
218+
"event": "#",
219+
"message": " 22| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ \"(\" BOOST_STRINGIZE(__LINE__) \"): note: \" x))",
220+
"verbosity_level": "1"
221+
},
222+
{
223+
"file_name": "",
224+
"line": 0,
225+
"event": "#",
226+
"message": " 23| #elif defined(__GNUC__)",
227+
"verbosity_level": "1"
228+
},
229+
{
230+
"file_name": "",
231+
"line": 0,
232+
"event": "#",
233+
"message": " 24|-> # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))",
234+
"verbosity_level": "1"
235+
},
236+
{
237+
"file_name": "",
238+
"line": 0,
239+
"event": "#",
240+
"message": " 25| #elif defined(_MSC_VER)",
241+
"verbosity_level": "1"
242+
},
243+
{
244+
"file_name": "",
245+
"line": 0,
246+
"event": "#",
247+
"message": " 26| # define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ \"(\" BOOST_STRINGIZE(__LINE__) \"): note: \" x))",
248+
"verbosity_level": "1"
249+
}
250+
]
251+
}
252+
]
253+
}

tests/csgrep/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ test_csgrep("66-json-parser-valgrind-dedup" )
113113
test_csgrep("67-json-parser-valgrind-dedup" )
114114
test_csgrep("68-gcc-parser-cppcheck-iterator1" )
115115
test_csgrep("69-csfilter-python-build-path" )
116+
test_csgrep("70-csparser-included-from-note" )

0 commit comments

Comments
 (0)