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 1515
1616import cpp
1717import semmle.code.cpp.models.Models
18+ import semmle.code.cpp.commons.Buffer
1819
1920predicate baseType ( AllocationExpr alloc , Type base ) {
2021 exists ( PointerType pointer |
@@ -35,15 +36,6 @@ predicate decideOnSize(Type t, int size) {
3536 size = min ( t .getSize ( ) )
3637}
3738
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-
4739from AllocationExpr alloc , Type base , int basesize , int allocated
4840where
4941 baseType ( alloc , base ) and
5648 ( allocated / size ) * size = allocated
5749 ) and
5850 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
6052select alloc ,
6153 "Allocated memory (" + allocated .toString ( ) + " bytes) is not a multiple of the size of '" +
6254 base .getName ( ) + "' (" + basesize .toString ( ) + " bytes)."
You can’t perform that action at this time.
0 commit comments