Skip to content

Commit 1d8d45b

Browse files
authored
Static variables are initialized to zero or null by compiler
Static variables are initialized to zero or null by compiler, no need to get an initializer of them
1 parent bfc95c6 commit 1d8d45b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cpp/ql/src/Critical/NotInitialised.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ predicate undefinedLocalUse(VariableAccess va) {
5454
// it is hard to tell when a struct or array has been initialized, so we
5555
// ignore them
5656
not isAggregateType(lv.getUnderlyingType()) and
57+
not lv.isStatic() and // static variables are initialized to zero or null by default
5758
not lv.getType().hasName("va_list") and
5859
va = lv.getAnAccess() and
5960
noDefPath(lv, va) and
@@ -70,7 +71,8 @@ predicate uninitialisedGlobal(GlobalVariable gv) {
7071
va = gv.getAnAccess() and
7172
va.isRValue() and
7273
not gv.hasInitializer() and
73-
not gv.hasSpecifier("extern")
74+
not gv.hasSpecifier("extern") and
75+
not gv.isStatic() // static variables are initialized to zero or null by default
7476
)
7577
}
7678

0 commit comments

Comments
 (0)