Skip to content

Commit 823c767

Browse files
committed
C++: Undo changes to SizeCheck.ql, SizeCheck2.ql.
1 parent 2023abd commit 823c767

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

cpp/ql/src/Critical/SizeCheck.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import cpp
1717
import semmle.code.cpp.models.Models
1818

19-
predicate baseType(HeuristicAllocationExpr alloc, Type base) {
19+
predicate baseType(AllocationExpr alloc, Type base) {
2020
exists(PointerType pointer |
2121
pointer.getBaseType() = base and
2222
(
@@ -34,12 +34,12 @@ predicate decideOnSize(Type t, int size) {
3434
size = min(t.getSize())
3535
}
3636

37-
from HeuristicAllocationExpr alloc, Type base, int basesize, int allocated
37+
from AllocationExpr alloc, Type base, int basesize, int allocated
3838
where
3939
baseType(alloc, base) and
4040
allocated = alloc.getSizeBytes() and
4141
decideOnSize(base, basesize) and
42-
alloc.(FunctionCall).getTarget() instanceof HeuristicAllocationFunction and // exclude `new` and similar
42+
alloc.(FunctionCall).getTarget() instanceof AllocationFunction and // exclude `new` and similar
4343
basesize > allocated
4444
select alloc,
4545
"Type '" + base.getName() + "' is " + basesize.toString() + " bytes, but only " +

cpp/ql/src/Critical/SizeCheck2.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import cpp
1717
import semmle.code.cpp.models.Models
1818

19-
predicate baseType(HeuristicAllocationExpr alloc, Type base) {
19+
predicate baseType(AllocationExpr alloc, Type base) {
2020
exists(PointerType pointer |
2121
pointer.getBaseType() = base and
2222
(
@@ -34,12 +34,12 @@ predicate decideOnSize(Type t, int size) {
3434
size = min(t.getSize())
3535
}
3636

37-
from HeuristicAllocationExpr alloc, Type base, int basesize, int allocated
37+
from AllocationExpr alloc, Type base, int basesize, int allocated
3838
where
3939
baseType(alloc, base) and
4040
allocated = alloc.getSizeBytes() and
4141
decideOnSize(base, basesize) and
42-
alloc.(FunctionCall).getTarget() instanceof HeuristicAllocationFunction and // exclude `new` and similar
42+
alloc.(FunctionCall).getTarget() instanceof AllocationFunction and // exclude `new` and similar
4343
// If the codebase has more than one type with the same name, check if any matches
4444
not exists(int size | base.getSize() = size |
4545
size = 0 or

cpp/ql/test/query-tests/Critical/SizeCheck/SizeCheck.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
| test.c:32:19:32:24 | call to malloc | Type 'float' is 4 bytes, but only 2 bytes are allocated. |
44
| test.c:33:20:33:25 | call to malloc | Type 'double' is 8 bytes, but only 4 bytes are allocated. |
55
| test.c:59:15:59:20 | call to malloc | Type 'MyUnion' is 128 bytes, but only 8 bytes are allocated. |
6-
| test.c:69:20:69:28 | call to MyMalloc1 | Type 'float' is 4 bytes, but only 3 bytes are allocated. |
7-
| test.c:70:20:70:28 | call to MyMalloc2 | Type 'float' is 4 bytes, but only 3 bytes are allocated. |

cpp/ql/test/query-tests/Critical/SizeCheck/SizeCheck2.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
| test2.c:17:20:17:25 | call to malloc | Allocated memory (33 bytes) is not a multiple of the size of 'double' (8 bytes). |
33
| test2.c:32:23:32:28 | call to malloc | Allocated memory (28 bytes) is not a multiple of the size of 'long long' (8 bytes). |
44
| test2.c:33:20:33:25 | call to malloc | Allocated memory (20 bytes) is not a multiple of the size of 'double' (8 bytes). |
5-
| test2.c:53:21:53:29 | call to MyMalloc1 | Allocated memory (33 bytes) is not a multiple of the size of 'double' (8 bytes). |
6-
| test2.c:54:21:54:29 | call to MyMalloc2 | Allocated memory (33 bytes) is not a multiple of the size of 'double' (8 bytes). |

cpp/ql/test/query-tests/Critical/SizeCheck/test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ void *MyMalloc2(size_t size);
6666

6767
void customAllocatorTests()
6868
{
69-
float *fptr1 = MyMalloc1(3); // BAD (too small)
70-
float *fptr2 = MyMalloc2(3); // BAD (too small)
69+
float *fptr1 = MyMalloc1(3); // BAD (too small) [NOT DETECTED]
70+
float *fptr2 = MyMalloc2(3); // BAD (too small) [NOT DETECTED]
7171
}

cpp/ql/test/query-tests/Critical/SizeCheck/test2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ void *MyMalloc2(size_t size);
5050

5151
void customAllocatorTests()
5252
{
53-
double *dptr1 = MyMalloc1(33); // BAD -- Not a multiple of sizeof(double)
54-
double *dptr2 = MyMalloc2(33); // BAD -- Not a multiple of sizeof(double)
53+
double *dptr1 = MyMalloc1(33); // BAD -- Not a multiple of sizeof(double) [NOT DETECTED]
54+
double *dptr2 = MyMalloc2(33); // BAD -- Not a multiple of sizeof(double) [NOT DETECTED]
5555
}

0 commit comments

Comments
 (0)