File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 11import semmle.code.cpp.pointsto.PointsTo
22
3+ /** Holds if there exists a call to a function that might close the file specified by `e`. */
34predicate closed ( Expr e ) {
45 fcloseCall ( _, e ) or
56 exists ( ExprCall c |
@@ -8,10 +9,19 @@ predicate closed(Expr e) {
89 )
910}
1011
12+ /** An expression for which there exists a function call that might close it. */
1113class ClosedExpr extends PointsToExpr {
1214 ClosedExpr ( ) { closed ( this ) }
1315
1416 override predicate interesting ( ) { closed ( this ) }
1517}
1618
19+ /**
20+ * Holds if `fc` is a call to a function that opens a file that might be closed. For example:
21+ * ```
22+ * FILE* f = fopen("file.txt", "r");
23+ * ...
24+ * fclose(f);
25+ * ```
26+ */
1727predicate fopenCallMayBeClosed ( FunctionCall fc ) { fopenCall ( fc ) and anythingPointsTo ( fc ) }
Original file line number Diff line number Diff line change 22
33import cpp
44
5+ /**
6+ * An assignment to a variable with the value `0`. For example:
7+ * ```
8+ * int x;
9+ * x = 0;
10+ * ```
11+ * but not:
12+ * ```
13+ * int x = 0;
14+ * ```
15+ */
516class ZeroAssignment extends AssignExpr {
617 ZeroAssignment ( ) {
718 this .getAnOperand ( ) instanceof VariableAccess and
819 this .getAnOperand ( ) instanceof Zero
920 }
1021
22+ /** Gets a variable that is assigned the value `0`. */
1123 Variable assignedVariable ( ) { result .getAnAccess ( ) = this .getAnOperand ( ) }
1224}
1325
Original file line number Diff line number Diff line change @@ -9,10 +9,19 @@ private predicate freed(Expr e) {
99 )
1010}
1111
12+ /** An expression that might be deallocated. */
1213class FreedExpr extends PointsToExpr {
1314 FreedExpr ( ) { freed ( this ) }
1415
1516 override predicate interesting ( ) { freed ( this ) }
1617}
1718
19+ /**
20+ * An allocation expression that might be deallocated. For example:
21+ * ```
22+ * int* p = new int;
23+ * ...
24+ * delete p;
25+ * ```
26+ */
1827predicate allocMayBeFreed ( AllocationExpr alloc ) { anythingPointsTo ( alloc ) }
You can’t perform that action at this time.
0 commit comments