forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStdLibDynamicMemoryAllocationUsed.ql
More file actions
35 lines (33 loc) · 1.2 KB
/
StdLibDynamicMemoryAllocationUsed.ql
File metadata and controls
35 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @id c/misra/std-lib-dynamic-memory-allocation-used
* @name RULE-4-12: Dynamic memory allocation shall not be used
* @description Using dynamic memory allocation and deallocation can result to undefined behavior.
* This query is for the Standard Library Implementation. Any implementation outside it
* will require a separate query under the same directive.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-4-12
* security
* correctness
* maintainability
* external/misra/obligation/required
*/
import cpp
import codingstandards.c.misra
import cpp
import codingstandards.c.misra
import semmle.code.cpp.models.interfaces.Allocation
import semmle.code.cpp.models.interfaces.Deallocation
from Expr e, string type
where
not isExcluded(e, BannedPackage::memoryAllocDeallocFunctionsOfStdlibhUsedQuery()) and
(
e.(FunctionCall).getTarget().(AllocationFunction).requiresDealloc() and
type = "allocation"
or
e instanceof DeallocationExpr and
not e.(FunctionCall).getTarget() instanceof AllocationFunction and
type = "deallocation"
)
select e, "Use of banned dynamic memory " + type + "."