File tree Expand file tree Collapse file tree 1 file changed +2
-10
lines changed Expand file tree Collapse file tree 1 file changed +2
-10
lines changed Original file line number Diff line number Diff line change 15
15
16
16
import cpp
17
17
import semmle.code.cpp.models.Models
18
+ import semmle.code.cpp.commons.Buffer
18
19
19
20
predicate baseType ( AllocationExpr alloc , Type base ) {
20
21
exists ( PointerType pointer |
@@ -35,15 +36,6 @@ predicate decideOnSize(Type t, int size) {
35
36
size = min ( t .getSize ( ) )
36
37
}
37
38
38
- predicate mayHaveVarSize ( Type t ) {
39
- // a member (normally at the end of the type) that looks like it may be intended have variable size.
40
- exists ( MemberVariable mv , ArrayType at |
41
- mv .getDeclaringType ( ) = t and
42
- mv .getUnspecifiedType ( ) = at and
43
- not at .getArraySize ( ) > 1
44
- )
45
- }
46
-
47
39
from AllocationExpr alloc , Type base , int basesize , int allocated
48
40
where
49
41
baseType ( alloc , base ) and
56
48
( allocated / size ) * size = allocated
57
49
) and
58
50
not basesize > allocated and // covered by SizeCheck.ql
59
- not mayHaveVarSize ( base .getUnspecifiedType ( ) ) // exclude variable size types
51
+ not memberMayBeVarSize ( base .getUnspecifiedType ( ) , _ ) // exclude variable size types
60
52
select alloc ,
61
53
"Allocated memory (" + allocated .toString ( ) + " bytes) is not a multiple of the size of '" +
62
54
base .getName ( ) + "' (" + basesize .toString ( ) + " bytes)."
You can’t perform that action at this time.
0 commit comments