C++: Make the two queries more alike.

This commit is contained in:
Geoffrey White
2020-10-20 17:46:47 +01:00
parent 4630c69950
commit 7db2b2ce37
2 changed files with 8 additions and 8 deletions

View File

@@ -44,16 +44,21 @@ predicate baseType(Allocation alloc, Type base) {
)
}
predicate decideOnSize(Type t, int size) {
// If the codebase has more than one type with the same name, it can have more than one size.
size = min(t.getSize())
}
from Allocation alloc, Type base, int basesize, int allocated
where
baseType(alloc, base) and
allocated = alloc.getSize() and
decideOnSize(base, basesize) and
// If the codebase has more than one type with the same name, check if any matches
not exists(int size | base.getSize() = size |
size = 0 or
(allocated / size) * size = allocated
) and
basesize = min(base.getSize())
)
select alloc,
"Allocated memory (" + allocated.toString() + " bytes) is not a multiple of the size of '" +
base.getName() + "' (" + basesize.toString() + " bytes)."