Skip to content

Commit fb15a4e

Browse files
authored
Reduce the false alarms of GlobalUseBeforeInit.ql
1 parent e08790d commit fb15a4e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cpp/ql/src/Critical/GlobalUseBeforeInit.ql

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,25 @@ predicate callReaches(Call call, ControlFlowNode successor) {
9898
)
9999
}
100100

101+
// To avoid many false alarms like `static int a = 1;`
102+
predicate initialisedAtDeclaration(GlobalVariable v) {
103+
exists(VariableDeclarationEntry vde |
104+
vde = v.getDefinition()
105+
and vde.isDefinition()
106+
)
107+
}
108+
109+
// No need to initialize those variables
110+
predicate isStdlibVariable(GlobalVariable v) {
111+
v.getName() = ["stdin", "stdout", "stderr"]
112+
}
113+
101114
from GlobalVariable v, Function f
102115
where
103116
uninitialisedBefore(v, f) and
104-
useFunc(v, f)
117+
useFunc(v, f) and
118+
not initialisedAtDeclaration(v) and
119+
not isStdlibVariable(v)
105120
select f,
106121
"The variable '" + v.getName() +
107122
" is used in this function but may not be initialized when it is called."

0 commit comments

Comments
 (0)