Skip to content

Commit b03054b

Browse files
committed
C++: Make sure some instruction also gives back the 'ParenthesisExpr's.
1 parent 71fe6f5 commit b03054b

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,13 @@ private module GetConvertedResultExpression {
11131113
result = tas.getExtent().getExpr() and
11141114
instr = tas.getInstruction(any(AllocationExtentConvertTag tag))
11151115
)
1116+
or
1117+
// There's no instruction that returns `ParenthesisExpr`, but some queries
1118+
// expect this
1119+
exists(TranslatedTransparentConversion ttc |
1120+
result = ttc.getExpr().(ParenthesisExpr) and
1121+
instr = ttc.getResult()
1122+
)
11161123
}
11171124

11181125
private Expr getConvertedResultExpressionImpl(Instruction instr) {

cpp/ql/test/query-tests/Critical/MemoryFreed/DoubleFree.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edges
66
| test_free.cpp:44:27:44:27 | a | test_free.cpp:46:10:46:10 | a |
77
| test_free.cpp:50:27:50:27 | a | test_free.cpp:51:10:51:10 | a |
88
| test_free.cpp:69:10:69:10 | a | test_free.cpp:72:14:72:14 | a |
9+
| test_free.cpp:83:12:83:12 | a | test_free.cpp:85:12:85:12 | a |
910
| test_free.cpp:101:10:101:10 | a | test_free.cpp:103:10:103:10 | a |
1011
| test_free.cpp:128:10:128:11 | * ... | test_free.cpp:129:10:129:11 | * ... |
1112
| test_free.cpp:152:27:152:27 | a | test_free.cpp:154:10:154:10 | a |
@@ -25,6 +26,8 @@ nodes
2526
| test_free.cpp:51:10:51:10 | a | semmle.label | a |
2627
| test_free.cpp:69:10:69:10 | a | semmle.label | a |
2728
| test_free.cpp:72:14:72:14 | a | semmle.label | a |
29+
| test_free.cpp:83:12:83:12 | a | semmle.label | a |
30+
| test_free.cpp:85:12:85:12 | a | semmle.label | a |
2831
| test_free.cpp:101:10:101:10 | a | semmle.label | a |
2932
| test_free.cpp:103:10:103:10 | a | semmle.label | a |
3033
| test_free.cpp:128:10:128:11 | * ... | semmle.label | * ... |
@@ -42,6 +45,7 @@ subpaths
4245
| test_free.cpp:46:10:46:10 | a | test_free.cpp:44:27:44:27 | a | test_free.cpp:46:10:46:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:44:22:44:25 | call to free | call to free |
4346
| test_free.cpp:51:10:51:10 | a | test_free.cpp:50:27:50:27 | a | test_free.cpp:51:10:51:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:50:22:50:25 | call to free | call to free |
4447
| test_free.cpp:72:14:72:14 | a | test_free.cpp:69:10:69:10 | a | test_free.cpp:72:14:72:14 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:69:5:69:8 | call to free | call to free |
48+
| test_free.cpp:85:12:85:12 | a | test_free.cpp:83:12:83:12 | a | test_free.cpp:85:12:85:12 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:83:5:83:13 | delete | delete |
4549
| test_free.cpp:103:10:103:10 | a | test_free.cpp:101:10:101:10 | a | test_free.cpp:103:10:103:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:101:5:101:8 | call to free | call to free |
4650
| test_free.cpp:129:10:129:11 | * ... | test_free.cpp:128:10:128:11 | * ... | test_free.cpp:129:10:129:11 | * ... | Memory pointed to by '* ...' may already have been freed by $@. | test_free.cpp:128:5:128:8 | call to free | call to free |
4751
| test_free.cpp:154:10:154:10 | a | test_free.cpp:152:27:152:27 | a | test_free.cpp:154:10:154:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:152:22:152:25 | call to free | call to free |

cpp/ql/test/query-tests/Critical/MemoryFreed/UseAfterFree.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ edges
44
| test_free.cpp:42:27:42:27 | a | test_free.cpp:45:5:45:5 | a |
55
| test_free.cpp:44:27:44:27 | a | test_free.cpp:45:5:45:5 | a |
66
| test_free.cpp:69:10:69:10 | a | test_free.cpp:71:9:71:9 | a |
7+
| test_free.cpp:83:12:83:12 | a | test_free.cpp:84:5:84:5 | a |
78
| test_free.cpp:90:10:90:10 | a | test_free.cpp:91:5:91:5 | a |
89
| test_free.cpp:95:10:95:10 | a | test_free.cpp:96:9:96:9 | a |
910
| test_free.cpp:101:10:101:10 | a | test_free.cpp:102:23:102:23 | a |
@@ -21,6 +22,8 @@ nodes
2122
| test_free.cpp:45:5:45:5 | a | semmle.label | a |
2223
| test_free.cpp:69:10:69:10 | a | semmle.label | a |
2324
| test_free.cpp:71:9:71:9 | a | semmle.label | a |
25+
| test_free.cpp:83:12:83:12 | a | semmle.label | a |
26+
| test_free.cpp:84:5:84:5 | a | semmle.label | a |
2427
| test_free.cpp:90:10:90:10 | a | semmle.label | a |
2528
| test_free.cpp:91:5:91:5 | a | semmle.label | a |
2629
| test_free.cpp:95:10:95:10 | a | semmle.label | a |
@@ -42,6 +45,7 @@ subpaths
4245
| test_free.cpp:45:5:45:5 | a | test_free.cpp:42:27:42:27 | a | test_free.cpp:45:5:45:5 | a | Memory may have been previously freed by $@. | test_free.cpp:42:22:42:25 | call to free | call to free |
4346
| test_free.cpp:45:5:45:5 | a | test_free.cpp:44:27:44:27 | a | test_free.cpp:45:5:45:5 | a | Memory may have been previously freed by $@. | test_free.cpp:44:22:44:25 | call to free | call to free |
4447
| test_free.cpp:71:9:71:9 | a | test_free.cpp:69:10:69:10 | a | test_free.cpp:71:9:71:9 | a | Memory may have been previously freed by $@. | test_free.cpp:69:5:69:8 | call to free | call to free |
48+
| test_free.cpp:84:5:84:5 | a | test_free.cpp:83:12:83:12 | a | test_free.cpp:84:5:84:5 | a | Memory may have been previously freed by $@. | test_free.cpp:83:5:83:13 | delete | delete |
4549
| test_free.cpp:91:5:91:5 | a | test_free.cpp:90:10:90:10 | a | test_free.cpp:91:5:91:5 | a | Memory may have been previously freed by $@. | test_free.cpp:90:5:90:8 | call to free | call to free |
4650
| test_free.cpp:96:9:96:9 | a | test_free.cpp:95:10:95:10 | a | test_free.cpp:96:9:96:9 | a | Memory may have been previously freed by $@. | test_free.cpp:95:5:95:8 | call to free | call to free |
4751
| test_free.cpp:102:23:102:23 | a | test_free.cpp:101:10:101:10 | a | test_free.cpp:102:23:102:23 | a | Memory may have been previously freed by $@. | test_free.cpp:101:5:101:8 | call to free | call to free |

cpp/ql/test/query-tests/Critical/MemoryFreed/test_free.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class A {
8181
void test_new1() {
8282
A *a = new A();
8383
delete(a);
84-
a->f(); // BAD [NOT DETECTED]
85-
delete(a); // BAD [NOT DETECTED]
84+
a->f(); // BAD
85+
delete(a); // BAD
8686
}
8787

8888
void test_dereference1(A *a) {
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
| test.cpp:173:29:173:51 | ... & ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... |
2-
| test.cpp:173:29:173:51 | ... & ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:170:16:170:47 | ... * ... | ... * ... |
3-
| test.cpp:174:30:174:45 | ... >> ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... |
4-
| test.cpp:174:30:174:45 | ... >> ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:170:16:170:47 | ... * ... | ... * ... |
51
| test.cpp:193:15:193:24 | ... / ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:193:15:193:24 | ... / ... | ... / ... |
6-
| test.cpp:217:29:217:51 | ... & ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:214:2:214:47 | ... += ... | ... += ... |
7-
| test.cpp:217:29:217:51 | ... & ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:214:16:214:47 | ... * ... | ... * ... |
8-
| test.cpp:218:30:218:45 | ... >> ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:214:2:214:47 | ... += ... | ... += ... |
9-
| test.cpp:218:30:218:45 | ... >> ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:214:16:214:47 | ... * ... | ... * ... |

0 commit comments

Comments
 (0)