forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadStorageNotInitializedBeforeUse.ql
More file actions
44 lines (39 loc) · 1.62 KB
/
ThreadStorageNotInitializedBeforeUse.ql
File metadata and controls
44 lines (39 loc) · 1.62 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
36
37
38
39
40
41
42
43
44
/**
* @id c/misra/thread-storage-not-initialized-before-use
* @name RULE-22-20: Thread-specific storage pointers shall be created before being accessed
* @description Thread specific storage pointers shall be initialized with the standard library
* functions before using them.
* @kind problem
* @precision high
* @problem.severity error
* @tags external/misra/id/rule-22-20
* correctness
* concurrency
* external/misra/c/2012/amendment4
* external/misra/obligation/mandatory
*/
import cpp
import codingstandards.c.misra
import codingstandards.c.Objects
import codingstandards.cpp.ConcurrencyNew
import codingstandards.cpp.Type
import codingstandards.c.initialization.GlobalInitializationAnalysis
module ThreadStoreInitializationConfig implements GlobalInitializationAnalysisConfigSig {
ObjectIdentity getAnInitializedObject(Expr e) {
e.(TSSCreateFunctionCall).getKey() = result.getASubobjectAddressExpr()
}
ObjectIdentity getAUsedObject(Expr e) {
result.getASubobjectAddressExpr() = e and
exists(ThreadSpecificStorageFunctionCall use |
not use instanceof TSSCreateFunctionCall and e = use.getKey()
)
}
}
import GlobalInitalizationAnalysis<ThreadStoreInitializationConfig> as InitAnalysis
from Expr objUse, ObjectIdentity obj, Function callRoot
where
not isExcluded(objUse, Concurrency9Package::threadStorageNotInitializedBeforeUseQuery()) and
InitAnalysis::uninitializedFrom(objUse, obj, callRoot)
select objUse,
"Thread specific storage pointer '$@' used before initialization from entry point function '$@'.",
obj, obj.toString(), callRoot, callRoot.getName()