Skip to content

Commit 11d7a0b

Browse files
committed
C++: Exclude results where the address of the variable is taken.
1 parent d41e517 commit 11d7a0b

File tree

3 files changed

+2
-2
lines changed

3 files changed

+2
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ImproperNullTerminationReachability extends StackVariableReachabilityWithR
5353
override predicate isBarrier(ControlFlowNode node, StackVariable v) {
5454
exprDefinition(v, node, _) or
5555
mayAddNullTerminator(node, v.getAnAccess()) or
56+
node.(AddressOfExpr).getOperand() = v.getAnAccess() or // address taken
5657
isSinkActual(node, v) // only report first use
5758
}
5859
}

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ImproperNullTermination/ImproperNullTermination.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@
2626
| test.cpp:421:19:421:25 | buffer2 | Variable $@ may not be null terminated. | test.cpp:419:8:419:14 | buffer2 | buffer2 |
2727
| test.cpp:448:17:448:22 | buffer | Variable $@ may not be null terminated. | test.cpp:446:8:446:13 | buffer | buffer |
2828
| test.cpp:454:18:454:23 | buffer | Variable $@ may not be null terminated. | test.cpp:452:8:452:13 | buffer | buffer |
29-
| test.cpp:502:10:502:18 | after_ptr | Variable $@ may not be null terminated. | test.cpp:497:9:497:17 | after_ptr | after_ptr |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ImproperNullTermination/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,6 @@ void test_strtol()
499499

500500
strcpy(buffer, "123abc");
501501
num = strtol("123abc", &after_ptr, 10);
502-
strlen(after_ptr); // GOOD [FALSE POSITIVE]
502+
strlen(after_ptr); // GOOD
503503
}
504504
}

0 commit comments

Comments
 (0)