Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpp/ql/lib/change-notes/2026-11-26-uninitialized-arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The `UninitializedNode` class from `semmle.code.cpp.dataflow.new.DataFlow` no longer includes stack-allocated arrays.
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ module Public {
* flow graph.
*/
class UninitializedNode extends AbstractUninitializedNode {
UninitializedNode() { indirectionIndex = 0 }
UninitializedNode() { indirectionIndex = 0 and not v.getUnspecifiedType() instanceof ArrayType }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void following_pointers( // $ ast-def=sourceStruct1_ptr ir-def=*cleanArray1 ir-d

int stackArray[2] = { source(), source() };
stackArray[0] = source();
sink(stackArray); // $ ast,ir
sink(stackArray); // $ ast
indirect_sink(stackArray); // $ ast ir=50:25 ir=50:35 ir=51:19
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ astFlow
| test.cpp:1312:7:1312:12 | call to source | test.cpp:1314:8:1314:8 | x |
| test.cpp:1329:11:1329:16 | call to source | test.cpp:1330:10:1330:10 | i |
| test.cpp:1335:10:1335:15 | buffer | test.cpp:1336:10:1336:18 | access to array |
| test.cpp:1342:8:1342:10 | buf | test.cpp:1344:8:1344:8 | p |
| test.cpp:1348:7:1348:7 | x | test.cpp:1350:8:1350:8 | p |
| true_upon_entry.cpp:17:11:17:16 | call to source | true_upon_entry.cpp:21:8:21:8 | x |
| true_upon_entry.cpp:27:9:27:14 | call to source | true_upon_entry.cpp:29:8:29:8 | x |
| true_upon_entry.cpp:33:11:33:16 | call to source | true_upon_entry.cpp:39:8:39:8 | x |
Expand Down Expand Up @@ -201,7 +203,6 @@ irFlow
| clang.cpp:35:32:35:37 | call to source | clang.cpp:38:10:38:11 | m2 |
| clang.cpp:40:42:40:47 | call to source | clang.cpp:42:18:42:19 | m2 |
| clang.cpp:44:35:44:40 | call to source | clang.cpp:46:17:46:18 | m2 |
| clang.cpp:50:7:50:16 | definition of stackArray | clang.cpp:52:8:52:17 | stackArray |
| clang.cpp:50:25:50:30 | call to source | clang.cpp:53:17:53:26 | *stackArray |
| clang.cpp:50:35:50:40 | call to source | clang.cpp:53:17:53:26 | *stackArray |
| clang.cpp:51:19:51:24 | call to source | clang.cpp:53:17:53:26 | *stackArray |
Expand Down Expand Up @@ -291,11 +292,9 @@ irFlow
| test.cpp:417:16:417:20 | intRefSource output argument | test.cpp:418:8:418:12 | local |
| test.cpp:422:7:422:11 | definition of local | test.cpp:424:8:424:12 | local |
| test.cpp:423:20:423:25 | intPointerSource output argument | test.cpp:424:8:424:12 | local |
| test.cpp:433:7:433:11 | definition of local | test.cpp:435:8:435:12 | local |
| test.cpp:434:20:434:24 | intPointerSource output argument | test.cpp:436:8:436:13 | * ... |
| test.cpp:440:7:440:11 | definition of local | test.cpp:442:8:442:12 | local |
| test.cpp:441:18:441:23 | intArraySource output argument | test.cpp:442:8:442:12 | local |
| test.cpp:448:7:448:11 | definition of local | test.cpp:450:8:450:12 | local |
| test.cpp:449:18:449:22 | intArraySource output argument | test.cpp:451:8:451:13 | * ... |
| test.cpp:456:26:456:32 | source1 | test.cpp:457:9:457:22 | (statement expression) |
| test.cpp:456:26:456:32 | source1 | test.cpp:468:8:468:12 | local |
Expand Down
16 changes: 14 additions & 2 deletions cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void intPointerSourceCaller() {
void intPointerSourceCaller2() {
int local[1];
intPointerSource(local);
sink(local); // $ ast=434:20 ir SPURIOUS: ast=433:7
sink(local); // $ ast=434:20 SPURIOUS: ast=433:7
sink(*local); // $ ast=434:20 ir SPURIOUS: ast=433:7
}

Expand All @@ -447,7 +447,7 @@ void intArraySourceCaller() {
void intArraySourceCaller2() {
int local[2];
intArraySource(local, 2);
sink(local); // $ ast=449:18 ir SPURIOUS: ast=448:7
sink(local); // $ ast=449:18 SPURIOUS: ast=448:7
sink(*local); // $ ast=449:18 ir SPURIOUS: ast=448:7
}

Expand Down Expand Up @@ -1336,4 +1336,16 @@ void certain_def_uninitialized_instruction_test() {
sink(buffer[0]); // $ SPURIOUS: ast
buffer[0] = source();
}
}

void uninitialized_array_address() {
char buf[10];
char *p = buf;
sink(p); // $ SPURIOUS: ast
}

void uninitialized_scalar_address() {
int x;
int *p = &x;
sink(p); // $ SPURIOUS: ast
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@
| test.cpp:1137:7:1137:10 | data | test.cpp:1140:10:1140:13 | data |
| test.cpp:1335:10:1335:15 | buffer | test.cpp:1336:10:1336:15 | buffer |
| test.cpp:1335:10:1335:15 | buffer | test.cpp:1337:5:1337:10 | buffer |
| test.cpp:1342:8:1342:10 | buf | test.cpp:1343:13:1343:15 | buf |
| test.cpp:1348:7:1348:7 | x | test.cpp:1349:13:1349:13 | x |
Loading