Skip to content

Commit 12bbb07

Browse files
committed
CPP: Additional test cases.
1 parent 41d5d5a commit 12bbb07

File tree

2 files changed

+162
-1
lines changed

2 files changed

+162
-1
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/UninitializedLocal.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@
88
| test.cpp:132:9:132:9 | j | The variable $@ may not be initialized here. | test.cpp:126:6:126:6 | j | j |
99
| test.cpp:219:3:219:3 | x | The variable $@ may not be initialized here. | test.cpp:218:7:218:7 | x | x |
1010
| test.cpp:243:13:243:13 | i | The variable $@ may not be initialized here. | test.cpp:241:6:241:6 | i | i |
11+
| test.cpp:268:9:268:11 | val | The variable $@ may not be initialized here. | test.cpp:261:6:261:8 | val | val |
12+
| test.cpp:292:9:292:11 | val | The variable $@ may not be initialized here. | test.cpp:285:6:285:8 | val | val |
13+
| test.cpp:304:9:304:11 | val | The variable $@ may not be initialized here. | test.cpp:297:6:297:8 | val | val |
14+
| test.cpp:316:9:316:11 | val | The variable $@ may not be initialized here. | test.cpp:309:6:309:8 | val | val |
15+
| test.cpp:329:9:329:11 | val | The variable $@ may not be initialized here. | test.cpp:321:6:321:8 | val | val |
16+
| test.cpp:336:10:336:10 | a | The variable $@ may not be initialized here. | test.cpp:333:7:333:7 | a | a |
17+
| test.cpp:342:9:342:11 | val | The variable $@ may not be initialized here. | test.cpp:334:6:334:8 | val | val |
18+
| test.cpp:369:10:369:10 | a | The variable $@ may not be initialized here. | test.cpp:358:7:358:7 | a | a |
19+
| test.cpp:378:9:378:11 | val | The variable $@ may not be initialized here. | test.cpp:359:6:359:8 | val | val |

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/test.cpp

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,156 @@ void test21()
242242

243243
v3 = v1 >> i; // BAD: i is not initialized
244244
v3 = v2 >> 1; // BAD: v2 is not initialized [NOT DETECTED]
245-
}
245+
}
246+
247+
int test22() {
248+
bool loop = true;
249+
int val;
250+
251+
while (loop)
252+
{
253+
val = 1;
254+
loop = false;
255+
}
256+
return val; // GOOD
257+
}
258+
259+
int test23() {
260+
bool loop = true, stop = false;
261+
int val;
262+
263+
while (loop && true)
264+
{
265+
val = 1;
266+
loop = false;
267+
}
268+
return val; // GOOD [FALSE POSITIVE]
269+
}
270+
271+
int test24() {
272+
bool stop = false;
273+
int val;
274+
275+
while (!stop)
276+
{
277+
val = 1;
278+
stop = true;
279+
}
280+
return val; // GOOD
281+
}
282+
283+
int test25() {
284+
bool loop = true, stop = false;
285+
int val;
286+
287+
while (true && loop)
288+
{
289+
val = 1;
290+
loop = false;
291+
}
292+
return val; // GOOD [FALSE POSITIVE]
293+
}
294+
295+
int test26() {
296+
bool loop = true, stop = false;
297+
int val;
298+
299+
while (loop && loop)
300+
{
301+
val = 1;
302+
loop = false;
303+
}
304+
return val; // GOOD [FALSE POSITIVE]
305+
}
306+
307+
int test27() {
308+
bool loop = true, stop = false;
309+
int val;
310+
311+
while (loop || false)
312+
{
313+
val = 1;
314+
loop = false;
315+
}
316+
return val; // GOOD [FALSE POSITIVE]
317+
}
318+
319+
int test28() {
320+
bool a = true, b = true, c = true;
321+
int val;
322+
323+
while (a ? b : c)
324+
{
325+
val = 1;
326+
a = false;
327+
c = false;
328+
}
329+
return val; // GOOD [FALSE POSITIVE]
330+
}
331+
332+
int test29() {
333+
bool a, b = true, c = true;
334+
int val;
335+
336+
while ((a && b) || c) // BAD (a is uninitialized)
337+
{
338+
val = 1;
339+
b = false;
340+
c = false;
341+
}
342+
return val; // GOOD [FALSE POSITIVE]
343+
}
344+
345+
int test30() {
346+
int val;
347+
348+
do
349+
{
350+
val = 1;
351+
} while (false);
352+
return val; // GOOD
353+
}
354+
355+
int test31() {
356+
bool loop = true;
357+
bool stop = false;
358+
bool a, b = true, c = true;
359+
int val;
360+
361+
while (loop || false)
362+
{
363+
loop = false;
364+
}
365+
while (!stop)
366+
{
367+
stop = true;
368+
}
369+
while ((a && b) || c) // BAD (a is uninitialized)
370+
{
371+
b = false;
372+
c = false;
373+
}
374+
do
375+
{
376+
} while (false);
377+
378+
return val; // BAD
379+
}
380+
381+
int test32() {
382+
int val;
383+
384+
while (true)
385+
{
386+
}
387+
388+
return val; // GOOD (never reached)
389+
}
390+
391+
int test33() {
392+
int val;
393+
394+
while (val = 1, true) {
395+
return val; // GOOD
396+
}
397+
}

0 commit comments

Comments
 (0)