Skip to content

Commit d935e9f

Browse files
committed
C++: Also resolve typedefs nested inside arrays.
1 parent fdc3052 commit d935e9f

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,21 @@ private string getTypeName(Type t, boolean needsSpace) {
529529
needsSpace = false and
530530
(if needsSpace0 = true then result = s + " *" else result = s + "*")
531531
or
532+
// We don't need to check for `needsSpace0` here because the type of
533+
// `x` in `int x[1024]` is formatted without a space between the bracket
534+
// and the `int` by `Type.getName`. That is, calling `Type.getName` on
535+
// the type of `x` gives `int[1024]` and not `int [1024]`.
536+
needsSpace = false and
537+
exists(ArrayType array | array = dt |
538+
result = s + "[" + array.getArraySize() + "]"
539+
or
540+
not array.hasArraySize() and
541+
result = s + "[]"
542+
)
543+
or
532544
not dt instanceof ReferenceType and
533545
not dt instanceof PointerType and
546+
not dt instanceof ArrayType and
534547
result = s and
535548
needsSpace = needsSpace0
536549
)

cpp/ql/test/library-tests/dataflow/models-as-data/FlowSummaryNode.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@
7676
| tests.cpp:437:5:437:36 | [summary] to write: ReturnValue in madCallReturnValueIgnoreFunction | ReturnNode | madCallReturnValueIgnoreFunction | madCallReturnValueIgnoreFunction |
7777
| tests.cpp:459:5:459:31 | [summary param] *0 in parameter_ref_to_return_ref | ParameterNode | parameter_ref_to_return_ref | parameter_ref_to_return_ref |
7878
| tests.cpp:459:5:459:31 | [summary] to write: ReturnValue[*] in parameter_ref_to_return_ref | ReturnNode | parameter_ref_to_return_ref | parameter_ref_to_return_ref |
79+
| tests.cpp:471:5:471:17 | [summary param] *0 in receive_array | ParameterNode | receive_array | receive_array |
80+
| tests.cpp:471:5:471:17 | [summary] to write: ReturnValue in receive_array | ReturnNode | receive_array | receive_array |

cpp/ql/test/library-tests/dataflow/models-as-data/SummaryCall.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ summarizedCallables
3030
| tests.cpp:436:6:436:25 | madCallArg0WithValue |
3131
| tests.cpp:437:5:437:36 | madCallReturnValueIgnoreFunction |
3232
| tests.cpp:459:5:459:31 | parameter_ref_to_return_ref |
33+
| tests.cpp:471:5:471:17 | receive_array |
3334
sourceCallables
3435
| tests.cpp:3:5:3:10 | source |
3536
| tests.cpp:4:6:4:14 | sourcePtr |
@@ -231,7 +232,6 @@ sourceCallables
231232
| tests.cpp:464:36:464:36 | s |
232233
| tests.cpp:465:6:465:6 | y |
233234
| tests.cpp:469:7:469:9 | INT |
234-
| tests.cpp:471:5:471:17 | receive_array |
235235
| tests.cpp:471:23:471:23 | a |
236236
| tests.cpp:473:6:473:23 | test_receive_array |
237237
| tests.cpp:474:6:474:6 | x |

cpp/ql/test/library-tests/dataflow/models-as-data/tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,11 @@ void test_parameter_ref_to_return_ref() {
468468

469469
using INT = int;
470470

471-
int receive_array(INT a[20]); // $ MISSING: interpretElement
471+
int receive_array(INT a[20]); // $ interpretElement
472472

473473
void test_receive_array() {
474474
int x = source();
475475
int array[10] = {x};
476476
int y = receive_array(array);
477-
sink(y); // $ MISSING: ir
477+
sink(y); // $ ir
478478
}

0 commit comments

Comments
 (0)