Skip to content

Commit aa1d5c5

Browse files
authored
Merge pull request #15960 from MathiasVP/unitialized-local-as-path
C++: Convert `cpp/uninitialized-local` to a `path-problem` query
2 parents a3da6c8 + b66b878 commit aa1d5c5

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

cpp/ql/src/Likely Bugs/Memory Management/UninitializedLocal.ql

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Potentially uninitialized local variable
33
* @description Reading from a local variable that has not been assigned to
44
* will typically yield garbage.
5-
* @kind problem
5+
* @kind path-problem
66
* @id cpp/uninitialized-local
77
* @problem.severity warning
88
* @security-severity 7.8
@@ -15,6 +15,7 @@
1515
import cpp
1616
import semmle.code.cpp.ir.IR
1717
import semmle.code.cpp.ir.dataflow.MustFlow
18+
import PathGraph
1819

1920
/**
2021
* Auxiliary predicate: Types that don't require initialization
@@ -89,4 +90,4 @@ where
8990
conf.hasFlowPath(source, sink) and
9091
isSinkImpl(sink.getInstruction(), va) and
9192
v = va.getTarget()
92-
select va, "The variable $@ may not be initialized at this access.", v, v.getName()
93+
select va, source, sink, "The variable $@ may not be initialized at this access.", v, v.getName()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Potentially uninitialized local variable" query (`cpp/uninitialized-local`) has been converted to a `path-problem` query.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
| test.cpp:12:6:12:8 | foo | The variable $@ may not be initialized at this access. | test.cpp:11:6:11:8 | foo | foo |
2-
| test.cpp:113:6:113:8 | foo | The variable $@ may not be initialized at this access. | test.cpp:111:6:111:8 | foo | foo |
3-
| test.cpp:219:3:219:3 | x | The variable $@ may not be initialized at this access. | test.cpp:218:7:218:7 | x | x |
4-
| test.cpp:243:13:243:13 | i | The variable $@ may not be initialized at this access. | test.cpp:241:6:241:6 | i | i |
5-
| test.cpp:336:10:336:10 | a | The variable $@ may not be initialized at this access. | test.cpp:333:7:333:7 | a | a |
6-
| test.cpp:369:10:369:10 | a | The variable $@ may not be initialized at this access. | test.cpp:358:7:358:7 | a | a |
7-
| test.cpp:378:9:378:11 | val | The variable $@ may not be initialized at this access. | test.cpp:359:6:359:8 | val | val |
8-
| test.cpp:417:10:417:10 | j | The variable $@ may not be initialized at this access. | test.cpp:414:9:414:9 | j | j |
9-
| test.cpp:436:9:436:9 | j | The variable $@ may not be initialized at this access. | test.cpp:431:9:431:9 | j | j |
10-
| test.cpp:454:2:454:2 | x | The variable $@ may not be initialized at this access. | test.cpp:452:6:452:6 | x | x |
11-
| test.cpp:460:7:460:7 | x | The variable $@ may not be initialized at this access. | test.cpp:458:6:458:6 | x | x |
12-
| test.cpp:467:2:467:2 | x | The variable $@ may not be initialized at this access. | test.cpp:464:6:464:6 | x | x |
13-
| test.cpp:474:7:474:7 | x | The variable $@ may not be initialized at this access. | test.cpp:471:6:471:6 | x | x |
1+
edges
2+
nodes
3+
| test.cpp:11:6:11:8 | definition of foo | semmle.label | definition of foo |
4+
| test.cpp:111:6:111:8 | definition of foo | semmle.label | definition of foo |
5+
| test.cpp:218:7:218:7 | definition of x | semmle.label | definition of x |
6+
| test.cpp:241:6:241:6 | definition of i | semmle.label | definition of i |
7+
| test.cpp:333:7:333:7 | definition of a | semmle.label | definition of a |
8+
| test.cpp:358:7:358:7 | definition of a | semmle.label | definition of a |
9+
| test.cpp:359:6:359:8 | definition of val | semmle.label | definition of val |
10+
| test.cpp:414:9:414:9 | definition of j | semmle.label | definition of j |
11+
| test.cpp:431:9:431:9 | definition of j | semmle.label | definition of j |
12+
| test.cpp:452:6:452:6 | definition of x | semmle.label | definition of x |
13+
| test.cpp:458:6:458:6 | definition of x | semmle.label | definition of x |
14+
| test.cpp:464:6:464:6 | definition of x | semmle.label | definition of x |
15+
| test.cpp:471:6:471:6 | definition of x | semmle.label | definition of x |
16+
#select
17+
| test.cpp:12:6:12:8 | foo | test.cpp:11:6:11:8 | definition of foo | test.cpp:11:6:11:8 | definition of foo | The variable $@ may not be initialized at this access. | test.cpp:11:6:11:8 | foo | foo |
18+
| test.cpp:113:6:113:8 | foo | test.cpp:111:6:111:8 | definition of foo | test.cpp:111:6:111:8 | definition of foo | The variable $@ may not be initialized at this access. | test.cpp:111:6:111:8 | foo | foo |
19+
| test.cpp:219:3:219:3 | x | test.cpp:218:7:218:7 | definition of x | test.cpp:218:7:218:7 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:218:7:218:7 | x | x |
20+
| test.cpp:243:13:243:13 | i | test.cpp:241:6:241:6 | definition of i | test.cpp:241:6:241:6 | definition of i | The variable $@ may not be initialized at this access. | test.cpp:241:6:241:6 | i | i |
21+
| test.cpp:336:10:336:10 | a | test.cpp:333:7:333:7 | definition of a | test.cpp:333:7:333:7 | definition of a | The variable $@ may not be initialized at this access. | test.cpp:333:7:333:7 | a | a |
22+
| test.cpp:369:10:369:10 | a | test.cpp:358:7:358:7 | definition of a | test.cpp:358:7:358:7 | definition of a | The variable $@ may not be initialized at this access. | test.cpp:358:7:358:7 | a | a |
23+
| test.cpp:378:9:378:11 | val | test.cpp:359:6:359:8 | definition of val | test.cpp:359:6:359:8 | definition of val | The variable $@ may not be initialized at this access. | test.cpp:359:6:359:8 | val | val |
24+
| test.cpp:417:10:417:10 | j | test.cpp:414:9:414:9 | definition of j | test.cpp:414:9:414:9 | definition of j | The variable $@ may not be initialized at this access. | test.cpp:414:9:414:9 | j | j |
25+
| test.cpp:436:9:436:9 | j | test.cpp:431:9:431:9 | definition of j | test.cpp:431:9:431:9 | definition of j | The variable $@ may not be initialized at this access. | test.cpp:431:9:431:9 | j | j |
26+
| test.cpp:454:2:454:2 | x | test.cpp:452:6:452:6 | definition of x | test.cpp:452:6:452:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:452:6:452:6 | x | x |
27+
| test.cpp:460:7:460:7 | x | test.cpp:458:6:458:6 | definition of x | test.cpp:458:6:458:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:458:6:458:6 | x | x |
28+
| test.cpp:467:2:467:2 | x | test.cpp:464:6:464:6 | definition of x | test.cpp:464:6:464:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:464:6:464:6 | x | x |
29+
| test.cpp:474:7:474:7 | x | test.cpp:471:6:471:6 | definition of x | test.cpp:471:6:471:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:471:6:471:6 | x | x |

0 commit comments

Comments
 (0)