Skip to content

Commit cf21997

Browse files
authored
Reduce false alarms raised by static variables
Static variables are initialized to zero or null by compiler, no need to get an initializer of them. See https://stackoverflow.com/questions/13251083/the-initialization-of-static-variables-in-c See 6.7.8/10 in the C99 Standard. A relevant PR: github#16527
1 parent 89dcad4 commit cf21997

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cpp/ql/src/Critical/InitialisationNotRun.ql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@ predicate called(Function f) {
3232
exists(FunctionAccess fa | fa.getTarget() = f)
3333
}
3434

35+
predicate staticWithoutDereference(GlobalVariable v) {
36+
v.isStatic() and
37+
not exists(VariableAccess va |
38+
va = v.getAnAccess() and
39+
dereferenced(va)
40+
)
41+
}
42+
3543
from GlobalVariable v
3644
where
3745
global(v) and
46+
not staticWithoutDereference(v) and
3847
not exists(VariableAccess lval |
3948
v.getAnAccess() = lval and
4049
lval.isUsedAsLValue() and

0 commit comments

Comments
 (0)